2018-12-17 07:22:46 +00:00
|
|
|
# [cert-info.js](https://git.coolaj86.com/coolaj86/cert-info.js)
|
2016-08-11 15:43:11 +00:00
|
|
|
|
2016-08-11 15:15:10 +00:00
|
|
|
Read basic info from a cert.pem / x509 certificate.
|
2016-08-11 15:43:11 +00:00
|
|
|
|
2018-08-17 01:47:37 +00:00
|
|
|
Used for [Greenlock.js](https://git.coolaj86.com/coolaj86/greenlock-express.js)
|
|
|
|
|
2018-12-17 07:22:46 +00:00
|
|
|
# Features
|
|
|
|
|
|
|
|
| <175 lines of code | 1.7k gzipped | 4.4k minified | 8.8k with comments |
|
|
|
|
|
|
|
|
* [x] Parses x.509 certificate schemas
|
|
|
|
* [x] DER/ASN.1
|
|
|
|
* [x] PEM (base64-encoded DER)
|
|
|
|
* [x] Subject
|
|
|
|
* [x] SAN extension (altNames)
|
|
|
|
* [x] Issuance Date (notBefore)
|
|
|
|
* [x] Expiry Date (notAfter)
|
|
|
|
* [x] VanillaJS, **Zero Dependencies**
|
|
|
|
* [x] Node.js
|
|
|
|
* [ ] Browsers (built, publishing soon)
|
|
|
|
|
|
|
|
# Install
|
2016-08-11 15:43:11 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# bin
|
2018-12-17 07:22:46 +00:00
|
|
|
npm install --global cert-info
|
2016-08-11 15:43:11 +00:00
|
|
|
|
|
|
|
# node.js library
|
2018-12-17 07:22:46 +00:00
|
|
|
npm install --save cert-info
|
2016-08-11 15:43:11 +00:00
|
|
|
```
|
|
|
|
|
2018-12-17 07:22:46 +00:00
|
|
|
# Usage
|
2016-08-11 15:43:11 +00:00
|
|
|
|
2018-12-17 07:22:46 +00:00
|
|
|
## CLI
|
2016-08-11 16:06:11 +00:00
|
|
|
|
2016-08-11 15:43:11 +00:00
|
|
|
For basic info (subject, altnames, issuedAt, expiresAt):
|
|
|
|
|
|
|
|
```bash
|
2018-12-17 07:22:46 +00:00
|
|
|
cert-info /path/to/cert.pem
|
2016-08-11 15:43:11 +00:00
|
|
|
```
|
|
|
|
|
2018-12-17 07:22:46 +00:00
|
|
|
## node.js
|
2016-08-11 16:06:11 +00:00
|
|
|
|
2016-08-11 15:43:11 +00:00
|
|
|
```javascript
|
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 07:22:46 +00:00
|
|
|
var certinfo = require('cert-info');
|
2016-08-11 15:43:11 +00:00
|
|
|
var cert = fs.readFile('cert.pem', 'ascii', function (err, certstr) {
|
|
|
|
|
2016-08-11 16:01:24 +00:00
|
|
|
// basic info
|
2018-12-17 07:22:46 +00:00
|
|
|
console.info(certinfo.info(certstr));
|
2016-08-11 16:01:24 +00:00
|
|
|
|
2018-12-17 07:22:46 +00:00
|
|
|
// if you need to submit a bug report
|
|
|
|
console.info(certinfo.debug(certstr));
|
2016-08-11 15:43:11 +00:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2016-08-11 16:06:55 +00:00
|
|
|
Example output:
|
|
|
|
|
2016-08-11 15:43:11 +00:00
|
|
|
```javascript
|
|
|
|
{
|
2018-12-17 07:22:46 +00:00
|
|
|
"subject": "localhost.example.com",
|
2016-08-11 15:43:11 +00:00
|
|
|
"altnames": [
|
2018-12-17 07:22:46 +00:00
|
|
|
"localhost.example.com"
|
2016-08-11 15:43:11 +00:00
|
|
|
],
|
|
|
|
"issuedAt": 1465516800000,
|
|
|
|
"expiresAt": 1499731199000
|
|
|
|
}
|
|
|
|
```
|
2016-08-11 16:06:11 +00:00
|
|
|
|
2018-12-17 07:22:46 +00:00
|
|
|
With a few small changes this could also work in the browser
|
|
|
|
(it has no dependencies and all of the non-browser things are on the Enc object).
|
|
|
|
|
|
|
|
# Legal
|
|
|
|
|
|
|
|
[cert-info.js](https://git.coolaj86.com/coolaj86/cert-info.js) |
|
|
|
|
MPL-2.0 |
|
|
|
|
[Terms of Use](https://therootcompany.com/legal/#terms) |
|
|
|
|
[Privacy Policy](https://therootcompany.com/legal/#privacy)
|