Skip to content

Support parsing x509 certificate with ECC public key #791

@martinraie

Description

@martinraie

Parsing x509 certificate with ECC public key fails with error Cannot read public key. Unknown OID. In our case we only need subject and validity data from certificate which is the same for both RSA and ECC cases. If Forge parses x509 with unsupported keys, it could just leave the key information blank instead of throwing and exception.

I'm not too familiar with Forge source code but I tested the following simple change which worked for our case:
Remove following lines from certificateFromAsn1 function (rows 1288:1290 in x509.js):

  if(oid !== pki.oids.rsaEncryption) {
    throw new Error('Cannot read public key. OID is not RSA.');
  }

Wrap last lines of the same function inside if-block:

  if(oid === pki.oids.rsaEncryption) {
    // convert RSA public key from ASN.1
    cert.publicKey = pki.publicKeyFromAsn1(capture.subjectPublicKeyInfo);
  }

Would this change be acceptable or is there any specific reason why certificateFromAsn1 function should throw exception instead of leaving publicKey field blank?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions