How to use the node-forge.pki.certificateFromPem function in node-forge

To help you get started, we’ve selected a few node-forge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mgcrea / node-easyrsa / test / spec / ssl.spec.js View on Github external
it('should have correct basicConstraints and keyUsage', () => {
      const {cert} = res.cert;
      const certPem = pki.certificateToPem(cert);
      const resultCert = pki.certificateFromPem(certPem);
      const expectedCert = fixtures.cert;
      // d(getCertificateShortSubject(expectedCert));
      const extensions = groupBy(resultCert.extensions, 'name');
      const expectedExtensions = groupBy(expectedCert.extensions, 'name');
      expect(extensions.basicConstraints).toEqual(expectedExtensions.basicConstraints);
      expect(extensions.keyUsage).toEqual(expectedExtensions.keyUsage);
      // expect(extensions.extKeyUsage).toEqual(expectedExtensions.extKeyUsage);
    });
  });
github mgcrea / node-easyrsa / test / spec / mdm.spec.js View on Github external
it('should have correct extensions', () => {
      const {cert} = res.cert;
      const certPem = pki.certificateToPem(cert);
      const resultCert = pki.certificateFromPem(certPem);
      const expectedCert = fixtures.cert;
      expect(getCertificateIssuer(resultCert)).toEqual(getCertificateSubject(res.ca.cert));
      // expect(getCertificateIssuer(resultCert)).toEqual(getCertificateIssuer(expectedCert)); // @TODO chain
      expect(getCertificateSubject(resultCert)).toEqual(getCertificateSubject(expectedCert));
      expect(parseInt(resultCert.serialNumber, 16).length).toEqual(parseInt(expectedCert.serialNumber, 16).length);
      expect(map(resultCert.extensions, 'name').sort()).toEqual(map(expectedCert.extensions, 'name').sort());
      expect(map(resultCert.extensions, 'id').sort()).toEqual(map(expectedCert.extensions, 'id').sort());
    });
    it('should have correct basicConstraints and keyUsage', () => {
github mreinstein / alexa-verifier / validate-cert.js View on Github external
module.exports = function validate (pem_cert) {
  try {
    var cert = pki.certificateFromPem(pem_cert)

    // check that cert has a Subject Alternative Names (SANs) section
    var altNameExt = cert.getExtension("subjectAltName")
    if (!altNameExt)
      return 'invalid certificate validity (subjectAltName extension not present)'

    // check that the domain echo-api.amazon.com is present in SANs section
    var domainExists = altNameExt.altNames.some(function(name) {
      return name.value === VALID_CERT_SAN
    })
    if(!domainExists)
      return 'invalid certificate validity (correct domain not found in subject alternative names)'

    var currTime = new Date().getTime()
    var notAfterTime = new Date(cert.validity.notAfter).getTime()
    if (notAfterTime <= currTime)
github kalmhq / kalm / frontend / src / permission / utils.ts View on Github external
export const extractDomainsFromCertificateContent = (certificateContent: string) => {
  try {
    // 1. wildcard multiple domains
    // 2. alt name multiple domains
    // https://medium.com/@pubudu538/how-to-create-a-self-signed-ssl-certificate-for-multiple-domains-25284c91142b
    // https://www.rpkamp.com/2014/08/25/setting-up-a-multi-domain-self-signed-ssl-certificate/
    const cert = pki.certificateFromPem(certificateContent);

    let domains = Immutable.List([]);

    // multiple domains
    if (cert.extensions.length > 0) {
      cert.extensions.map((attribute) => {
        if (attribute.altNames && attribute.altNames.length > 0) {
          attribute.altNames.map((altName: any) => {
            domains = domains.push(altName.value);
            return altName;
          });
        }
        return attribute;
      });
    }
github mgcrea / node-easyrsa / test / spec / vpn.spec.js View on Github external
it('should have correct extensions', () => {
      const {cert} = res.ca;
      const certPem = pki.certificateToPem(cert);
      const resultCert = pki.certificateFromPem(certPem);
      const expectedCert = fixtures.ca;
      expect(getCertificateSubject(resultCert)).toEqual(getCertificateSubject(expectedCert));
      expect(resultCert.serialNumber.length).toEqual(expectedCert.serialNumber.length);
      expect(map(resultCert.extensions, 'name').sort()).toEqual(map(expectedCert.extensions, 'name').sort());
      expect(map(resultCert.extensions, 'id').sort()).toEqual(map(expectedCert.extensions, 'id').sort());
    });
    it('should have correct basicConstraints and keyUsage', () => {
github mgcrea / node-easyrsa / test / spec / vpn.spec.js View on Github external
it('should have correct extensions', () => {
        const {cert} = res.cert;
        const certPem = pki.certificateToPem(cert);
        const resultCert = pki.certificateFromPem(certPem);
        const expectedCert = fixtures.clientCert;
        expect(getCertificateIssuer(resultCert)).toEqual(getCertificateSubject(res.ca.cert));
        expect(getCertificateIssuer(resultCert)).toEqual(getCertificateIssuer(expectedCert));
        expect(getCertificateSubject(resultCert)).toEqual(getCertificateSubject(expectedCert));
        expect(parseInt(resultCert.serialNumber, 16).length).toEqual(parseInt(expectedCert.serialNumber, 16).length);
        expect(map(resultCert.extensions, 'name').sort()).toEqual(map(expectedCert.extensions, 'name').sort());
        expect(map(resultCert.extensions, 'id').sort()).toEqual(map(expectedCert.extensions, 'id').sort());
      });
      it('should have correct basicConstraints and keyUsage', () => {
github mgcrea / node-easyrsa / test / spec / ssl.spec.js View on Github external
it('should have correct extensions', () => {
      const {cert} = res.ca;
      const certPem = pki.certificateToPem(cert);
      const resultCert = pki.certificateFromPem(certPem);
      const expectedCert = fixtures.ca;
      expect(getCertificateSubject(resultCert)).toEqual(getCertificateSubject(expectedCert));
      expect(resultCert.serialNumber.length).toEqual(expectedCert.serialNumber.length);
      expect(map(resultCert.extensions, 'name').sort()).toEqual(map(expectedCert.extensions, 'name').sort());
      expect(map(resultCert.extensions, 'id').sort()).toEqual(map(expectedCert.extensions, 'id').sort());
    });
    it('should have correct basicConstraints and keyUsage', () => {
github mgcrea / node-easyrsa / test / spec / vpn.spec.js View on Github external
it('should have correct basicConstraints and keyUsage', () => {
        const {cert} = res.cert;
        const certPem = pki.certificateToPem(cert);
        const resultCert = pki.certificateFromPem(certPem);
        const expectedCert = fixtures.clientCert;
        const extensions = groupBy(resultCert.extensions, 'name');
        const expectedExtensions = groupBy(expectedCert.extensions, 'name');
        expect(extensions.basicConstraints).toEqual(expectedExtensions.basicConstraints);
        expect(extensions.keyUsage).toEqual(expectedExtensions.keyUsage);
        expect(extensions.extKeyUsage).toEqual(expectedExtensions.extKeyUsage);
      });
      it('should properly verify', () => {
github rolodato / gitlab-letsencrypt / lib.js View on Github external
).then(cert => xtend(cert, {
                domains: options.domain,
                repository: options.repository,
                pagesUrl: `${gitlabBaseUrl}/${options.repository}/pages`,
                notAfter: pki.certificateFromPem(cert.cert).validity.notAfter
            }));
        });
github matianfu / telsa / src / telsa.js View on Github external
constructor (opts = {}) {
    super(opts)

    /** options */
    this.opts = opts

    if (!this.opts.ca) {
      throw new Error('ca not provided')
    }

    /** root ca certificate in forge format */
    this.ca = pki.certificateFromPem(this.opts.ca)

    /** ca store in forge format*/
    this.caStore = pki.createCaStore([this.ca])

    if (!this.opts.cert) {
      throw new Error('client certificate not provided')
    }

    /** 
     * client cert in PEM format 
     * @type {string}
     */
    this.certPem = this.opts.cert

    /** 
     * client cert in forge format