npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

auto.self.sign

v1.0.1

Published

Auto Self Sign is a NodeJS package that creates, installs and serve self-signed certificates for Windows. It allows to you develop on HTTPS easily.

Downloads

2

Readme

Auto Self Sign

Author: Philip Schoeman

License: MIT

Please note that this package contains the binaries of MKCert and OpenSSL. The OpenSSL binary requires the Visual Studio Runtime in order to run.


Auto Self Sign is a NodeJS package that creates, installs and serve self-signed certificates for Windows. It allows to you develop on HTTPS easily.

Features:

  • Does everything for you with a single API call.
    • Creates a PKCS12 certificate.
    • Installs the certificate into Windows as a "Trusted Root Certification Authority".
    • Extract the X.509 certificate and private key from the PKCS12 certificate.

Installing

Install via NPM :

npm install auto.self.sign

Using

Important: Since Auto Self Sign installs the certificate into Windows, you need to run as administrator. For example, if Visual Studio Code is used, you need to run VSCode as administrator, or else the certificate won't be able to be installed into windows.

Importing Auto Self Sign :

const autoSelfSign = require("auto.self.sign");

Configuring :

The package exports a configuration object that should be used to configure the certificate generation

const autoSelfSign = require("auto.self.sign");
const path = require("path");

//Get the config object from the package
let config = autoSelfSign.config;

//Setting the directory where the certificates should be saved in 
config.certificateFolder = path.join(__dirname, "certificates");
Configuration Options :

Property | Type | Description ------------ | ------------- | ------------- certificateFolder | String (required) | An absolute path to an existing directory where the self-signed certificates will be saved in. installCertWindows | Boolean (optional, default : true) | Sets if the certificate should be installed in Windows after it is created. pkcs12CertFileName | String (Optional, default : "certP12") | Sets the name of the PKCS12 certificate, please note that this excludes the extension. certFileName | String (Optional, default : "cert") | Sets the name of the X.509 certificate, please note that this excludes the extension. pkcs12CertFileName | String (Optional, default : "key") | Sets the name of the X.509 key file, please note that this excludes the extension.

Installing and getting the certificate and private key :

Method | Parameter | Result ------------ | ------------- | ------------- autoSelfSign(config) | object | object : certGenerationResult { key : String, cert : string, certStatsPKCS12 }

Certificate generation result fields :

Property | Type | Description ------------ | ------------- | ------------- cert | String | The X.509 certificate. key | String | The X.509 private key. pkcs12GenerationResult | Array< String > | The output result and errors of the MKCert utility's PKCS12 certificate generation. certInstallationResult | Array< String > | The out put and errors of CERTUTIL certificate generation.

The certificate can be generated, installed and by calling the autoSelfSign method.

const autoSelfSign = require("auto.self.sign");
const path = require("path");

(async () => {
    //Get the config object from the package
    let config = autoSelfSign.config;

    //Setting the directory where the certificates should be saved in 
    config.certificateFolder = path.join(__dirname, "certificates");

    //Generates and returns the generated certificate.
    let generationResult = await autoSelfSign.autoSelfSign(config);
})();

Creating an HTTPS server

This example creates a HTTPS server and opens chrome to view the result:

const autoSelfSign = require("auto.self.sign");
const path = require("path");
const https = require("https");
const exec = require('child_process').exec

(async () => {
    //Get the config object from the package
    let config = autoSelfSign.config;

    //Setting the directory where the certificates should be saved in. Directory should exist
    config.certificateFolder = path.join(__dirname, "certificates");

    //Generate certificate
    let generationResult = await autoSelfSign.autoSelfSign(config);
        
    //create HTTPS server
    let serverRequest = function (request, response) {
        response.writeHead("200");
        response.end("Test SSL response");
    }
    const options = {
        key: generationResult.key,
        cert: generationResult.cert
    };
    let server = https.createServer(options, serverRequest).listen(8580);

    //open chrome
    exec('start chrome https://localhost:8580', function (err) { });
})();

When running the example, you will be greeted with a secure https site. If it does not work, you can inspect the certificate generation result for errors.

Trouble shooting

No certificates were generated in the provided certificate folder?

Make sure to run your application and IDE as administrator. Also check the pkcs12GenerationResult property and certInstallationResult property on the certification generation result.

Error: More than one possible pks12 cert file found in directory

Make sure your certificate folder does not already contain a p12 certificate and the provided name is unique. Else leave on default naming.