# [@fidm/x509](https://github.com/fidm/x509) Pure JavaScript X509 certificate tools for Node.js. [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Downloads][downloads-image]][downloads-url] Inspired by https://github.com/digitalbazaar/forge ## Install ``` npm i --save @fidm/x509 ``` ## Documentation https://fidm.github.io/x509/ ## Example ### Support ed25519 certificate ```js const fs = require('fs') const { Certificate, PrivateKey } = require('@fidm/x509') const ed25519Cert = Certificate.fromPEM(fs.readFileSync('./test/cert/ed25519-server-cert.pem')) const privateKey = PrivateKey.fromPEM(fs.readFileSync('./test/cert/ed25519-server-key.pem')) const data = Buffer.allocUnsafe(100) const signature = privateKey.sign(data, 'sha256') console.log(ed25519Cert.publicKey.verify(data, signature, 'sha256')) // true ``` ### Parse githu.com' certificate ```js const fs = require('fs') const { Certificate } = require('@fidm/x509') const issuer = Certificate.fromPEM(fs.readFileSync('./test/cert/github-issuer.crt')) const cert = Certificate.fromPEM(fs.readFileSync('./test/cert/github.crt')) console.log(cert.isIssuer(issuer)) // true console.log(issuer.verifySubjectKeyIdentifier()) // true console.log(cert.verifySubjectKeyIdentifier()) // true console.log(issuer.checkSignature(cert)) // null console.log(issuer) // , // version: 3, // serialNumber: '0c79a944b08c11952092615fe26b1d83', // signatureOID: '1.2.840.113549.1.1.11', // signatureAlgorithm: 'sha256WithRsaEncryption', // infoSignatureOID: '1.2.840.113549.1.1.11', // signature: // , // validFrom: '2013-10-22T12:00:00.000Z', // validTo: '2028-10-22T12:00:00.000Z', // issuer: // { C: 'US', // O: 'DigiCert Inc', // OU: 'www.digicert.com', // CN: 'DigiCert High Assurance EV Root CA', // uniqueId: null, // attributes: // [ { oid: '2.5.4.6', // value: 'US', // valueTag: 19, // name: 'countryName', // shortName: 'C' }, // { oid: '2.5.4.10', // value: 'DigiCert Inc', // valueTag: 19, // name: 'organizationName', // shortName: 'O' }, // { oid: '2.5.4.11', // value: 'www.digicert.com', // valueTag: 19, // name: 'organizationalUnitName', // shortName: 'OU' }, // { oid: '2.5.4.3', // value: 'DigiCert High Assurance EV Root CA', // valueTag: 19, // name: 'commonName', // shortName: 'CN' } ] }, // subject: // { C: 'US', // O: 'DigiCert Inc', // OU: 'www.digicert.com', // CN: 'DigiCert SHA2 Extended Validation Server CA', // uniqueId: null, // attributes: // [ { oid: '2.5.4.6', // value: 'US', // valueTag: 19, // name: 'countryName', // shortName: 'C' }, // { oid: '2.5.4.10', // value: 'DigiCert Inc', // valueTag: 19, // name: 'organizationName', // shortName: 'O' }, // { oid: '2.5.4.11', // value: 'www.digicert.com', // valueTag: 19, // name: 'organizationalUnitName', // shortName: 'OU' }, // { oid: '2.5.4.3', // value: 'DigiCert SHA2 Extended Validation Server CA', // valueTag: 19, // name: 'commonName', // shortName: 'CN' } ] }, // extensions: // [ { oid: '2.5.29.19', // critical: true, // value: , // name: 'basicConstraints', // isCA: true, // maxPathLen: 0, // basicConstraintsValid: true }, // { oid: '2.5.29.15', // critical: true, // value: , // name: 'keyUsage', // keyUsage: 97, // digitalSignature: true, // nonRepudiation: false, // keyEncipherment: false, // dataEncipherment: false, // keyAgreement: false, // keyCertSign: true, // cRLSign: true, // encipherOnly: false, // decipherOnly: false }, // { oid: '2.5.29.37', // critical: false, // value: // , // name: 'extKeyUsage', // serverAuth: true, // clientAuth: true }, // { oid: '1.3.6.1.5.5.7.1.1', // critical: false, // value: // , // name: 'authorityInfoAccess', // authorityInfoAccessOcsp: 'http://ocsp.digicert.com' }, // { oid: '2.5.29.31', // critical: false, // value: // , // name: 'cRLDistributionPoints' }, // { oid: '2.5.29.32', // critical: false, // value: // , // name: 'certificatePolicies' }, // { oid: '2.5.29.14', // critical: false, // value: // , // name: 'subjectKeyIdentifier', // subjectKeyIdentifier: '3dd350a5d6a0adeef34a600a65d321d4f8f8d60f' }, // { oid: '2.5.29.35', // critical: false, // value: // , // name: 'authorityKeyIdentifier', // authorityKeyIdentifier: 'b13ec36903f8bf4701d498261a0802ef63642bc3' } ], // subjectKeyIdentifier: '3dd350a5d6a0adeef34a600a65d321d4f8f8d60f', // authorityKeyIdentifier: 'b13ec36903f8bf4701d498261a0802ef63642bc3', // ocspServer: 'http://ocsp.digicert.com', // issuingCertificateURL: '', // isCA: true, // maxPathLen: 0, // basicConstraintsValid: true, // keyUsage: 97, // dnsNames: [], // emailAddresses: [], // ipAddresses: [], // uris: [], // publicKey: // { oid: '1.2.840.113549.1.1.1', // algo: 'rsaEncryption', // publicKey: // }, // publicKeyRaw: // }> // , // version: 3, // serialNumber: '0a0630427f5bbced6957396593b6451f', // signatureOID: '1.2.840.113549.1.1.11', // signatureAlgorithm: 'sha256WithRsaEncryption', // infoSignatureOID: '1.2.840.113549.1.1.11', // signature: // , // validFrom: '2018-05-08T00:00:00.000Z', // validTo: '2020-06-03T12:00:00.000Z', // issuer: // { C: 'US', // O: 'DigiCert Inc', // OU: 'www.digicert.com', // CN: 'DigiCert SHA2 Extended Validation Server CA', // uniqueId: null, // attributes: // [ { oid: '2.5.4.6', // value: 'US', // valueTag: 19, // name: 'countryName', // shortName: 'C' }, // { oid: '2.5.4.10', // value: 'DigiCert Inc', // valueTag: 19, // name: 'organizationName', // shortName: 'O' }, // { oid: '2.5.4.11', // value: 'www.digicert.com', // valueTag: 19, // name: 'organizationalUnitName', // shortName: 'OU' }, // { oid: '2.5.4.3', // value: 'DigiCert SHA2 Extended Validation Server CA', // valueTag: 19, // name: 'commonName', // shortName: 'CN' } ] }, // subject: // { C: 'US', // ST: 'California', // L: 'San Francisco', // O: 'GitHub, Inc.', // CN: 'github.com', // uniqueId: null, // attributes: // [ { oid: '2.5.4.15', // value: 'Private Organization', // valueTag: 12, // name: 'businessCategory', // shortName: '' }, // { oid: '1.3.6.1.4.1.311.60.2.1.3', // value: 'US', // valueTag: 19, // name: 'jurisdictionC', // shortName: '' }, // { oid: '1.3.6.1.4.1.311.60.2.1.2', // value: 'Delaware', // valueTag: 19, // name: 'jurisdictionST', // shortName: '' }, // { oid: '2.5.4.5', // value: '5157550', // valueTag: 19, // name: 'serialName', // shortName: '' }, // { oid: '2.5.4.6', // value: 'US', // valueTag: 19, // name: 'countryName', // shortName: 'C' }, // { oid: '2.5.4.8', // value: 'California', // valueTag: 19, // name: 'stateOrProvinceName', // shortName: 'ST' }, // { oid: '2.5.4.7', // value: 'San Francisco', // valueTag: 19, // name: 'localityName', // shortName: 'L' }, // { oid: '2.5.4.10', // value: 'GitHub, Inc.', // valueTag: 19, // name: 'organizationName', // shortName: 'O' }, // { oid: '2.5.4.3', // value: 'github.com', // valueTag: 19, // name: 'commonName', // shortName: 'CN' } ] }, // extensions: // [ { oid: '2.5.29.35', // critical: false, // value: // , // name: 'authorityKeyIdentifier', // authorityKeyIdentifier: '3dd350a5d6a0adeef34a600a65d321d4f8f8d60f' }, // { oid: '2.5.29.14', // critical: false, // value: // , // name: 'subjectKeyIdentifier', // subjectKeyIdentifier: 'c9c25361669d5fab25f426cd0f389aa849ea48a9' }, // { oid: '2.5.29.17', // critical: false, // value: // , // name: 'subjectAltName', // altNames: // [ { tag: 2, // value: , // dnsName: 'github.com' }, // { tag: 2, // value: , // dnsName: 'www.github.com' } ] }, // { oid: '2.5.29.15', // critical: true, // value: , // name: 'keyUsage', // keyUsage: 5, // digitalSignature: true, // nonRepudiation: false, // keyEncipherment: true, // dataEncipherment: false, // keyAgreement: false, // keyCertSign: false, // cRLSign: false, // encipherOnly: false, // decipherOnly: false }, // { oid: '2.5.29.37', // critical: false, // value: // , // name: 'extKeyUsage', // serverAuth: true, // clientAuth: true }, // { oid: '2.5.29.31', // critical: false, // value: // , // name: 'cRLDistributionPoints' }, // { oid: '2.5.29.32', // critical: false, // value: // , // name: 'certificatePolicies' }, // { oid: '1.3.6.1.5.5.7.1.1', // critical: false, // value: // , // name: 'authorityInfoAccess', // authorityInfoAccessOcsp: 'http://ocsp.digicert.com', // authorityInfoAccessIssuers: // 'http://cacerts.digicert.com/DigiCertSHA2ExtendedValidationServerCA.crt' }, // { oid: '2.5.29.19', // critical: true, // value: , // name: 'basicConstraints', // isCA: false, // maxPathLen: -1, // basicConstraintsValid: true }, // { oid: '1.3.6.1.4.1.11129.2.4.2', // critical: false, // value: // , // name: 'timestampList' } ], // subjectKeyIdentifier: 'c9c25361669d5fab25f426cd0f389aa849ea48a9', // authorityKeyIdentifier: '3dd350a5d6a0adeef34a600a65d321d4f8f8d60f', // ocspServer: 'http://ocsp.digicert.com', // issuingCertificateURL: // 'http://cacerts.digicert.com/DigiCertSHA2ExtendedValidationServerCA.crt', // isCA: false, // maxPathLen: -1, // basicConstraintsValid: true, // keyUsage: 5, // dnsNames: [ 'github.com', 'www.github.com' ], // emailAddresses: [], // ipAddresses: [], // uris: [], // publicKey: // { oid: '1.2.840.113549.1.1.1', // algo: 'rsaEncryption', // publicKey: // }, // publicKeyRaw: // }> ``` ### License @fidm/x509 is licensed under the [MIT](https://github.com/fidm/x509/blob/master/LICENSE) license. Copyright © 2018-2019 FIdM. [npm-url]: https://www.npmjs.com/package/@fidm/x509 [npm-image]: https://img.shields.io/npm/v/@fidm/x509.svg [travis-url]: https://travis-ci.org/fidm/x509 [travis-image]: http://img.shields.io/travis/fidm/x509.svg [downloads-url]: https://npmjs.org/package/@fidm/x509 [downloads-image]: https://img.shields.io/npm/dm/@fidm/x509.svg?style=flat-square