Created
July 18, 2018 04:38
-
-
Save mikesmullin/783369117629fb3e9ca5e9776259e488 to your computer and use it in GitHub Desktop.
Parsing SAML x.509 Certificate in pure-Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _idpX509Cert = _.get(resp, ['samlp:Response', 'Assertion', 0, | |
'ds:Signature', 0, 'KeyInfo', 0, 'ds:X509Data', 0, 'ds:X509Certificate', 0]); | |
const asn1js = require('asn1js'); | |
const pkijs = require("pkijs"); | |
const Certificate = pkijs.Certificate; | |
const buf = new Buffer(_idpX509Cert, 'base64').buffer; | |
console.log('_idpX509Cert', _idpX509Cert); | |
const asn1 = asn1js.fromBER(buf); | |
if (asn1.offset === (-1)) | |
throw Error("Can not parse x.509 binary data"); | |
const idpX509Cert = new Certificate({ schema: asn1.result }); | |
res.end(JSON.stringify({ | |
idpX509Cert: idpX509Cert.toJSON(), | |
}, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment