# self-cert

> A simple library to generate self signed x509 certs

Latest version **2.0.1** (published 2024-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install self-cert
pnpm add self-cert
yarn add self-cert
bun add self-cert
```

Provides the command `self-cert`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2024-08-16 |
| First published | 2017-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | James Sumners |
| Maintainers | jsumners |
| Keywords | x509, certificates, self-signed |

## Links

- npm: https://www.npmjs.com/package/self-cert
- Repository: https://github.com/jsumners/self-cert
- Homepage: https://github.com/jsumners/self-cert#readme
- Issues: https://github.com/jsumners/self-cert/issues
- npm.io page: https://npm.io/package/self-cert

## Dependencies (5)

- [edtf](https://npm.io/package/edtf.md) ^4.1.0
- [pino](https://npm.io/package/pino.md) ^9.3.2
- [sade](https://npm.io/package/sade.md) ^1.8.1
- [node-forge](https://npm.io/package/node-forge.md) ^1.2.1
- [abstract-logging](https://npm.io/package/abstract-logging.md) ^2.0.1

## Recent versions

- 2.0.1 (latest) — 2024-08-16
- 2.0.0 — 2022-02-18
- 1.2.0 — 2020-06-28
- 1.1.1 — 2018-04-18
- 1.1.0 — 2018-01-23
- 1.0.1 — 2017-09-07
- 1.0.0 — 2017-09-07

## README

# self-cert

This is a simple library for generating a self-signed x509 keypair and certificate.
I looked at [selfsigned](https://npm.im/selfsigned) before writing this
library, but it didn't seem to be well maintained and had a hard dependency
on an outdated version of [node-forge](https://npm.im/node-forge). This library
also depends on `node-forge`, but it does so with semver qualifiers such that
newer versions can be specified by the library user.

The keys and certs generated by this library are configured for usage in any
scenario. Also, the certificate Subject Alternate Names (SANs) are populated
with the IP addresses of the present network interfaces as returned by
`os.networkInterfaces()`.

## Example

```js
const selfCert = require('self-cert')
const certDetails = selfCert({
  attrs: {
    stateName: 'Georgia',
    locality: 'Atlanta',
    orgName: 'Acme Widgets',
    shortName: 'widget42'
  },
  expires: new Date('2030-12-31')
})

/* certDetails = {
  privateKey: 'pem formatted string',
  publicKey: 'pem formatted string',
  certificate: 'pem formatted string'
} */
```

## Options

```js
{
  attrs: {
    commonName: '', // Default: os.hostname()
    countryName: '', // Default: 'US'
    stateName: '', // Default: 'Georgia'
    locality: '', // Default: 'Atlanta'
    orgName: '', // Default: 'None'
    shortName: '' // Default: 'example'
  },
  bits: 4096, // Default: 4096
  expires: new Date(), // Default: 5 years
  logger: {}
}
```

Notes:

+ `commonName` is used for the first SAN.
+ `stateName` maps to `stateOrProvinceName`.
+ `logger` should be a Log4j compliant logger; [Pino](http://getpino.io/) is
recommended. This library logs some progress messages at the `debug` level.
The default is a null logger.

## CLI

This module may also be installed globally as a CLI tool:

```sh
$ npm install -g self-cert
$ self-cert generate --help
```

## License

[MIT License](http://jsumners.mit-license.org/)

---
_Source: https://npm.io/package/self-cert · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
