• Stars
    star
    230
  • Rank 174,053 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate self-signed certificates from node.js

Generate a self signed x509 certificate from node.js.

Install

  npm install selfsigned

Usage

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

Async

selfsigned.generate(attrs, { days: 365 }, function (err, pems) {
  console.log(pems)
});

Will return the following like this:

{
  private: '-----BEGIN RSA PRIVATE KEY-----\r\nMIICXAIBAAKBgQCBFMXMYS/+RZz6+qzv+xeqXPdjw4YKZC4y3dPhSwgEwkecrCTX\r\nsR6boue+1MjIqPqWggXZnotIGldfEN0kn0Jbh2vMTrTx6YwqQ8tceBPoyuuqcYBO\r\nOONAcKOB3MLnZbyOgVtbyT3j68JE5V/lx6LhpIKAgY0m5WIuaKrW6mvLXQIDAQAB\r\nAoGAU6ODGxAqSecPdayyG/ml9vSwNAuAMgGB0eHcpZG5i2PbhRAh+0TAIXaoFQXJ\r\naAPeA2ISqlTJyRmQXYAO2uj61FzeyDzYCf0z3+yZEVz3cO7jB5Pl6iBvzbxWuuuA\r\ncbJtWLhWtW5/jioc8F0EAzZ+lkC/XuVJdwKHDmwt2qvJO+ECQQD+dvo1g3Sz9xGw\r\n21n+fDG5i4128+Qh+JPgh5AeLuXSofc1HMHaOXcC6Wu/Cloh7QAD934b7W0A7VoD\r\ndLd/JLyFAkEAgdwjryyvdhy69e516IrPB3b+m4rggtntBlZREMrk9tOzeIucVO3W\r\ntKI3FHm6JebN2gVcG+rZ+FaDPo+ifJkW+QJBAPojrMwEACmUevB2f9246gxx0UsY\r\nbq6yM3No71OsWEEY8/Bi53CEQqg7Gq5+F6H33qcHmBEN8LQTngN9rY+vZh0CQBg0\r\nqJImii5B/LeK03+dICoMDDmCEYdSh9P+ku3GZBd+Lp3xqBp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upr\r\ny10CAwEAAaNFMEMwDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAvQwJgYDVR0RBB8w\r\nHYYbaHR0cDovL2V4YW1wbGUub3JnL3dlYmlkI21lMA0GCSqGSIb3DQEBBQUAA4GB\r\nAC9hGQlDh8anNo1YDJdG2mYqOQ5uybJV++kixblGaOkoDROPsWepUpL6kMDUtbAM\r\n4uXTyFkvlUQSaQkhNgOY5w/BRIAkCIu6u4D4XcjlCdwFq6vcKMEuWTHMAlBWFla3\r\nXJZAPO10PHuDen7JeMOUf1Re7lRFtwfRGAvVYmrvYFKv\r\n-----END CERTIFICATE-----\r\n'
}

Attributes

for attributes, please refer to: https://github.com/digitalbazaar/forge/blob/master/lib/x509.js

Options

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')
});

You can avoid key pair generation specifying your own keys ({ keyPair: { publicKey: '-----BEGIN PUBLIC KEY-----...', privateKey: '-----BEGIN RSA PRIVATE KEY-----...' })

Generate Client Certificates

If you are in an environment where servers require client certificates, you can generate client keys signed by the original (server) key.

var pems = selfsigned.generate(null, { clientCertificate: true });
console.log(pems)

Will return the following like this:

{ private: '-----BEGIN RSA PRIVATE KEY-----\r\nMIICXQIBAAKBgQDLg/kS4dCPVu96sbK6MQuUPmhqnF8SeBXVHH18h+0BTj7HqnrA\r\nA75hNVIiSLTChvpzQ0qi2Ju7O2ESUOdx7cvGiftGuZLiI8uL2HVlYuX+wQTIoRHx\r\n9nxv56TIiqnPg5d05vSTLXoiJg5uac3a6+4vnhhTo0XRRXVVboZsfNpuGQIDAQAB\r\nAoGAf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CAbSgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBpMRQwEgYDVQQDEwtleGFt\r\ncGxlLm9yZzELMAkGA1UEBhMCVVMxETAPBgNVBAgTCFZpcmdpbmlhMRMwEQYDVQQH\r\nEwpCbGFja3NidXJnMQ0wCwYDVQQKEwRUZXN0MQ0wCwYDVQQLEwRUZXN0MB4XDTE1\r\nMTAyOTEzMDYwNVoXDTE2MTAyOTEzMDYwNVowbjEZMBcGA1UEAxMQSm9obiBEb2Ug\r\namRvZTEyMzELMAkGA1UEBhMCVVMxETAPBgNVBAgTCFZpcmdpbmlhMRMwEQYDVQQH\r\nEwpCbGFja3NidXJnMQ0wCwYDVQQKEwRUZXN0MQ0wCwYDVQQLEwRUZXN0MIGfMA0G\r\nCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDjR5FrrdZ1jirqkx3KMPnGjrcObj/vmztW\r\nTEZ1kX6gTskQugJUoxktzwDZza4jYODC6Ud2jouFLWeAi5BDSAeLwAQb951qVD9z\r\nVsmQ+63V/mvSJUojigwj7YjcxyReJ17F0YgjceqrkZaPM8YRo8h1fj1JdPc4ZOUg\r\nA5ASZ0h2ewIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACOUglBxJ80jzR3DSSMrgRav\r\n7deKUPShEPC3tbVrc3LHPGpCEJUC309aK2mbMwz2jX78tr/ezePELKbyRggUvVgN\r\nB0XdIQkpR9X4mPdtFYkMiWKNVYKd79r0kolprgFPryhT3jsICIOnwE1Ur23Q+Fk2\r\nnizRS0HY4Q25JLCmsWWy\r\n-----END CERTIFICATE-----\r\n' }

To override the default client CN of john doe jdoe123, add another option for clientCertificateCN:

var pems = selfsigned.generate(null, { clientCertificate: true, clientCertificateCN: 'FooBar' });

License

MIT

More Repositories

1

passport.socketio

access passport.js authenticated user information from socket.io connection
JavaScript
655
star
2

url-join

Join all arguments together and normalize the resulting url.
JavaScript
350
star
3

winser

Run a node.js application as a window service using nssm.
JavaScript
270
star
4

express-unless

Conditionally add a middleware to express with some common patterns
TypeScript
177
star
5

pswatch

Powershell cmdlet to monitor file changes in a directory tree.
79
star
6

node-gpstracker

server library for a GPS / GPRS tracker
JavaScript
51
star
7

node-windows-eventlog

Native node.js module to log messages to the Windows EventLog
C++
47
star
8

li

JavaScript utility to parse and generate the Link header according to RFC 5988.
JavaScript
41
star
9

Grandson-of-Obsidian

Textmate theme inspired in Obsidian
39
star
10

sublime-node-require

helper to add require clauses to node.js modules in Sublime Text 2
Python
38
star
11

zero-downtime-node

JavaScript
36
star
12

lru-memoizer

Memoize functions results using an lru-cache.
JavaScript
28
star
13

sublime-html-to-jade

Sublime Text 2 plugin to convert html file, selection or clipboard to jade.
Python
27
star
14

Sublime-Package-Decontrol

Like Sublime Package Control but without a central repository.
Python
26
star
15

sublime-mocha-snippets

sublime 2 snippets for the mocha testing framework
23
star
16

mac-ca

Get Mac OS Root certificates in node.js
TypeScript
23
star
17

passport-hawk

Passport strategy for the Hawk authentication schema.
JavaScript
22
star
18

npm-install-retry

Command line utility that retries `npm install` when NPM fails with `npm ERR! cb() never called`
JavaScript
21
star
19

node-windows-certs

Get certificates from the windows cert store from node.js
JavaScript
19
star
20

refresh-token

Helper to get a valid oauth 2 token given a refresh token.
JavaScript
16
star
21

parse-links

Parse a Links header into a JavaScript object.
JavaScript
15
star
22

mongo-getdb

A very opinionated way to connect with the mongodb driver.
JavaScript
13
star
23

RazorCandle

Render a razor template and save it to a file from command line.
C#
11
star
24

mockuire

require a module with mocked dependencies in node.js
JavaScript
11
star
25

winston-winlog

Windows Event Log logger for the node.js Winston module.
JavaScript
9
star
26

slido

A web application to generate HTML5 slideshow from markdown.
JavaScript
9
star
27

passport-sharejs

Use passport.js user profile from session to authorize operations on Share.js documents.
JavaScript
9
star
28

teamcity-badges

Teamcity Badges
JavaScript
8
star
29

nestin

Visual Studio extension to "nest" files in the Solution Explorer.
XSLT
8
star
30

fstream-s3

Advanced FS streaming to amazon s3 for Node
JavaScript
8
star
31

sns-subscribe-internal

Subscribe an SNS Topic to an internal webhook.
JavaScript
8
star
32

master-process

reload node.js apps with no downtime
JavaScript
7
star
33

npm-preserve

Shell
6
star
34

strider-hipchat

Strider plugin for hipchat
JavaScript
6
star
35

ejs-amd

standalone and express/connect middleware to serve EJS template as AMD .js files to the browser
JavaScript
5
star
36

LongPollingChat

C#
4
star
37

socket-io.sessions

access express.js session from socket.io
JavaScript
4
star
38

rendirect

Express middleware to render a message and redirect the browser
JavaScript
4
star
39

dynamodb-subscriber

Subscribe to DynamoDB streams easily.
JavaScript
4
star
40

very-fast-args

JavaScript
3
star
41

fix-github-tabs

JavaScript
3
star
42

ss-to-db

Send screenshot to dropbox (Mac only)
JavaScript
3
star
43

tortu

AJLogo command line interpreter
JavaScript
3
star
44

sublime-goto-node-module

Open the homepage of any node module installed (or native)
Python
3
star
45

envcredstash

JavaScript
3
star
46

uqbar

JavaScript
3
star
47

extract

JavaScript
3
star
48

jmail

An example of single page web application driven by unit tests
JavaScript
3
star
49

xtail

Restart, stop or start service while watching its log file.
JavaScript
3
star
50

cose-kit

TypeScript
3
star
51

visa-analyzer

JavaScript
2
star
52

xenv

JavaScript
2
star
53

alerta-cookbook

Chef cookbook for alerta
Ruby
2
star
54

iSqlCmd

Enhanced Sql Server Command Line interface
C#
2
star
55

funstream

Functional programming operations with node.js streams (nothing here yet)
CoffeeScript
2
star
56

hashi

an AMD polyfill for hashchange
JavaScript
2
star
57

put-blob

send file to blob storage from command line
JavaScript
2
star
58

sublime-unity-recents

Sublime Text 2 plugin to automatically keep a list of the ten last folders opened in the Ubuntu Unity launcher.
Python
2
star
59

jam-jade-runtime

Amd jade runtime for the JAM package system.
JavaScript
2
star
60

zq

An AMD module to manipulate the DOM, combining three small libraries that works for me and might work for you
JavaScript
1
star
61

chato

pet project chat with websockets
JavaScript
1
star
62

pb-stream

Protobuf.js stream encoder / decoder for varint32 length-delimited messages.
JavaScript
1
star
63

chinooktest

1
star
64

tvpublica-roku

Roku channel for TV Publica - Canal 7 - Argentina.
Brightscript
1
star
65

pshare

stream something to a public url
JavaScript
1
star
66

ts-env-parser

TypeScript
1
star
67

css-import

merge css files with @import clause
JavaScript
1
star
68

s2s3

Take a snapshot and send it to s3. (OSx only)
JavaScript
1
star
69

json-docker

the json command line utility built into a docker image
Shell
1
star
70

recurse-delete-property

Delete property recursively
JavaScript
1
star
71

gdrivesdk

this is the example of the google drive sdk, nothing to see here
JavaScript
1
star
72

tedemo

a demo application to show how to share jade templates to the browser
JavaScript
1
star
73

yams

Yet Another MongoDb Session Store
JavaScript
1
star
74

gapps-provisioning

(Unofficial) Google Apps Provisioning Api client library for node.js
JavaScript
1
star
75

slice-of-life

Helper functions to create paginated REST APIs in node.js.
JavaScript
1
star
76

prismcontrib

Prism Contrib fork for Prism v3
C#
1
star
77

my-console2

my console2 configuration
1
star
78

fizzbuzz-js

Ejemplo FizzBuzz en Js - CodeCampBA
JavaScript
1
star
79

har-sanitizer

HAR archive sanitizer
TypeScript
1
star