Skip to content

Instantly share code, notes, and snippets.

@mikesmullin
Created July 18, 2018 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesmullin/783369117629fb3e9ca5e9776259e488 to your computer and use it in GitHub Desktop.
Save mikesmullin/783369117629fb3e9ca5e9776259e488 to your computer and use it in GitHub Desktop.
Parsing SAML x.509 Certificate in pure-Javascript
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