Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

selfsigned

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selfsigned - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

10

index.js

@@ -16,6 +16,6 @@ var forge = require('node-forge')

options = options || {};
var keys = forge.pki.rsa.generateKeyPair(1024);
var keys = forge.pki.rsa.generateKeyPair(options.keySize || 1024);
var cert = forge.pki.createCertificate();
cert.serialNumber = '01';
cert.serialNumber = forge.util.bytesToHex(forge.random.getBytesSync(9)); // the serial number can be decimal or hex (if preceded by 0x)
cert.validity.notBefore = new Date();

@@ -48,3 +48,5 @@ cert.validity.notAfter = new Date();

cert.setExtensions([{
cert.publicKey = keys.publicKey
cert.setExtensions(options.extensions || [{
name: 'basicConstraints',

@@ -67,4 +69,2 @@ cA: true

cert.publicKey = keys.publicKey
cert.sign(keys.privateKey, getAlgorithm(options && options.algorithm))

@@ -71,0 +71,0 @@

{
"name": "selfsigned",
"version": "1.4.1",
"version": "1.5.0",
"description": "Generate self signed certificates private and public keys",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,3 +15,4 @@ Generate a self signed x509 certificate from node.js.

var selfsigned = require('selfsigned');
var pems = selfsigned.generate({ subj: '/CN=contoso.com', days: 365 });
var attrs = [{ name: 'commonName', value: 'contoso.com' }];
var pems = selfsigned.generate(attrs, { days: 365 });
console.log(pems)

@@ -30,8 +31,14 @@ ```

## Configuration
## Options
You can optionally specify a different algorithm:
```js
var pems = selfsigned.generate({ subj: '/CN=contoso.com', days: 365 }, { algorithm: 'sha256' });
var pems = selfsigned.generate(null, {
keySize: 2048, // the size for the private key in bits (default: 1024)
days: 30, // how long till expiry of the signed certificate (default: 365)
algorithm: 'sha256', // sign the certificate with specified algorithm (default: 'sha1')
extensions: [{ name: 'basicConstraints', cA: true }], // certificate extensions array
pkcs7: true, // include PKCS#7 as part of the output (default: false)
clientCertificate: true, // generate client cert signed by the original key (default: false)
clientCertificateCN: 'jdoe' // client certificate's common name (default: 'John Doe jdoe123')
});
```

@@ -44,24 +51,20 @@

```js
var selfsigned = require('selfsigned');
var pems = selfsigned.generate(null, { clientCertificate: true });
console.log(pems)
```
You can optionally specify a different algorithm:
Which will generate the following:
Will return the following like this:
```js
{ private: '-----BEGIN RSA PRIVATE KEY-----\r\nMIICXQIBAAKBgQCgd/lGfk+0Yfgprcm0pJUiP6Hl3i4GDsGmstW3JBRsUNgE+RpT\r\nhLrDoxr0hvovXvdKLTUfRMkqLNVevv0EP6QP+2yG97FJ9IZb+DX3wHrTvMj3ngcf\r\nE5LpN632c8jK2TF9syozAuBnDiBmU27ys5mP4mf1OPmmZGfNADib85vWYQIDAQAB\r\nAoGASeESnlb3IUhdteqyS/3eP4dmZWuWaumOVM5PQONWl8vcuOVrLnqUdg/5EA24\r\nz+h8F+WaaIwFxeogTl/GI5edU5RrcMsX7yAJahGcV7NG8A1ajCCdlUXUJKKiahAI\r\nU3S9ej+8VCj93NwBtTgcTWDr24lyhZF7MCFpQ6qIoTFP58UCQQD0vx4etezlC5ba\r\nOWK7fLux8JhRsqOhhU7pMtnSc7kStCcXnkMMFgnCQOui5jh6CA9g1VeMGFppQ+00\r\ndh8NTEYrAkEAp9jUuOeXzobgV+f84V6eQ2FU+tB1EfsNSgSHIZRMsMUkVe+HOKed\r\nEyQzduuo8t/RUUmXKvGFtC6DU3t1cT37owJBAJnIOIm9b/NfO9M0uZfqwRkGfv7e\r\nizhjRfj7TaiRtBlPfzy04ZYHhuw61JSPqa7rv5Xtl0vcxXpdBv+utMYrRe8CQCnr\r\njbVgohmCtiU+W3ouF3jcpky+I38KJJeH6fgJAd5kXl7YI/2SXziYogHheaCvJagX\r\nqRmgmLQXqdT/0KUnxeECQQDR4c1sq8imgm82OpGElAZHxaSHQMwOWzo4E8E+XZCo\r\nV4tLzLjGKPwwdNTwGK+oxD3P7Qy1klnAow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QUAA4GBACOUglBxJ80jzR3DSSMrgRav\r\n7deKUPShEPC3tbVrc3LHPGpCEJUC309aK2mbMwz2jX78tr/ezePELKbyRggUvVgN\r\nB0XdIQkpR9X4mPdtFYkMiWKNVYKd79r0kolprgFPryhT3jsICIOnwE1Ur23Q+Fk2\r\nnizRS0HY4Q25JLCmsWWy\r\n-----END CERTIFICATE-----\r\n' }
```
var pems = selfsigned.generate({ subj: '/CN=contoso.com', days: 365 }, { algorithm: 'sha256' });
To override the default client CN of `john doe jdoe123`, add another option for clientCertificateCN:
To override the default client CN of `john doe jdoe123`, add another option for `clientCertificateCN`:
```js
var selfsigned = require('selfsigned');
var pems = selfsigned.generate(null, { clientCertificate: true, clientCertificateCN: "FooBar" });
console.log(pems)
var pems = selfsigned.generate(null, { clientCertificate: true, clientCertificateCN: 'FooBar' });
```

@@ -68,0 +71,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc