How to use the asn1.js-rfc5280.SubjectPublicKeyInfo function in asn1

To help you get started, we’ve selected a few asn1 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 indutny / ocsp / lib / ocsp / verify.js View on Github external
function findResponder(issuer, certs, raws) {
  var issuerKey = issuer.tbsCertificate.subjectPublicKeyInfo;
  issuerKey = ocsp.utils.toPEM(
      rfc5280.SubjectPublicKeyInfo.encode(issuerKey, 'der'), 'PUBLIC KEY');

  for (var i = 0; i < certs.length; i++) {
    var cert = certs[i];
    var signAlg = ocsp.utils.sign[cert.signatureAlgorithm.algorithm.join('.')];
    if (!signAlg) {
      throw new Error('Unknown signature algorithm ' +
                      cert.signatureAlgorithm.algorithm);
    }

    var verify = crypto.createVerify(signAlg);

    verify.update(raws[i]);
    if (!verify.verify(issuerKey, cert.signature.data))
      throw new Error('Invalid signature');

    var certKey = cert.tbsCertificate.subjectPublicKeyInfo;
github indutny / ocsp / lib / ocsp / verify.js View on Github external
var cert = certs[i];
    var signAlg = ocsp.utils.sign[cert.signatureAlgorithm.algorithm.join('.')];
    if (!signAlg) {
      throw new Error('Unknown signature algorithm ' +
                      cert.signatureAlgorithm.algorithm);
    }

    var verify = crypto.createVerify(signAlg);

    verify.update(raws[i]);
    if (!verify.verify(issuerKey, cert.signature.data))
      throw new Error('Invalid signature');

    var certKey = cert.tbsCertificate.subjectPublicKeyInfo;
    certKey = ocsp.utils.toPEM(
        rfc5280.SubjectPublicKeyInfo.encode(certKey, 'der'), 'PUBLIC KEY');
    return certKey;
  }

  return issuerKey;
}
github snowflakedb / snowflake-connector-nodejs / lib / agent / verify.js View on Github external
function findResponder(issuer, certs, raws)
{
  var issuerKey = issuer.tbsCertificate.subjectPublicKeyInfo;
  issuerKey = ocsp.utils.toPEM(
    rfc5280.SubjectPublicKeyInfo.encode(issuerKey, 'der'), 'PUBLIC KEY');

  for (var i = 0; i < certs.length; i++)
  {
    var cert = certs[i];
    var signAlg = ocsp.utils.sign[cert.signatureAlgorithm.algorithm.join('.')];
    if (!signAlg)
    {
      throw new Error('Unknown signature algorithm ' +
        cert.signatureAlgorithm.algorithm);
    }

    var verify = crypto.createVerify(signAlg);

    verify.update(raws[i]);
    if (!verify.verify(issuerKey, cert.signature.data))
    {
github snowflakedb / snowflake-connector-nodejs / lib / agent / cert_util.js View on Github external
const findResponder = function (issuer, certs, raws)
{
  var issuerKey = issuer.tbsCertificate.subjectPublicKeyInfo;
  issuerKey = ocsp.utils.toPEM(
    rfc5280.SubjectPublicKeyInfo.encode(issuerKey, 'der'), 'PUBLIC KEY');
  if (certs.length > 0)
  {
    const currentTime = Date.now();
    const cert = certs[0];
    const certValidity = cert.tbsCertificate.validity;
    if (certValidity.notAfter.value < currentTime || certValidity.notBefore.value > currentTime)
    {
      return {
        err: Errors.createOCSPError(
          ErrorCodes.ERR_OCSP_INVALID_CERTIFICATE_VALIDITY,
          "Valid from:", toUTCString(certValidity.notBefore.value),
          ", Valid to:", toUTCString(certValidity.notAfter.value)),
        responderKey: null
      }
    }
    const signAlg = ocsp.utils.sign[cert.signatureAlgorithm.algorithm.join('.')];
github snowflakedb / snowflake-connector-nodejs / lib / agent / cert_util.js View on Github external
}

    const verify = crypto.createVerify(signAlg);

    verify.update(raws[0]);
    if (!verify.verify(issuerKey, cert.signature.data))
    {
      return {
        err: Errors.createOCSPError(ErrorCodes.ERR_OCSP_INVALID_SIGNATURE),
        responderKey: null
      }
    }

    let certKey = cert.tbsCertificate.subjectPublicKeyInfo;
    certKey = ocsp.utils.toPEM(
      rfc5280.SubjectPublicKeyInfo.encode(certKey, 'der'), 'PUBLIC KEY');
    return {err: null, responderKey: certKey};
  }

  return {err: null, responderKey: issuerKey};
};
github snowflakedb / snowflake-connector-nodejs / lib / agent / verify.js View on Github external
{
      throw new Error('Unknown signature algorithm ' +
        cert.signatureAlgorithm.algorithm);
    }

    var verify = crypto.createVerify(signAlg);

    verify.update(raws[i]);
    if (!verify.verify(issuerKey, cert.signature.data))
    {
      throw new Error('Invalid signature');
    }

    var certKey = cert.tbsCertificate.subjectPublicKeyInfo;
    certKey = ocsp.utils.toPEM(
      rfc5280.SubjectPublicKeyInfo.encode(certKey, 'der'), 'PUBLIC KEY');
    return certKey;
  }

  return issuerKey;
}