Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about parsing x509 extensions within a parsed Certificate #41

Closed
MasterKale opened this issue Mar 31, 2021 · 1 comment
Closed
Assignees

Comments

@MasterKale
Copy link

I'm trying to migrate more of my code over to asn1-schema but I'm stumped about how to take an extension out of an x.509 Certificate instance and then parse it through an extension schema.

After running my leaf cert through AsnParser.parse(leafCertBuffer, Certificate), I'm able to view the expected extensions:

Extensions(2) [
  Extension {
    extnID: '1.3.6.1.4.1.45724.2.1.1',
    critical: false,
    extnValue: OctetString {
      buffer: ArrayBuffer { [Uint8Contents]: <03 02 05 20>, byteLength: 4 }
    }
  },
  Extension {
    extnID: '2.5.29.19',
    critical: true,
    extnValue: OctetString {
      buffer: ArrayBuffer { [Uint8Contents]: <30 03 01 01 00>, byteLength: 5 }
    }
  }
]

What I want to do is then take that '2.5.29.19' (BasicConstraints) extension and parse it so I can more easily access its cA attribute. I tried this but of course the types didn't match:

if (ext.extnID === id_ce_basicConstraints) {
  console.log(AsnParser.fromASN(ext, BasicConstraints)); // No good, ext isn't a Buffer
}

Is there a clean way to further parse something that's within a parsed asn.1 schema? Thank you in advance for shining a light on this more advanced use case 😄

@MasterKale
Copy link
Author

I figured it out, turns out I could just parse ext.extnValue:

if (ext.extnID === id_ce_basicConstraints) {
  console.log(AsnParser.parse(ext.extnValue, BasicConstraints));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants