UNPKG

wsfed

Version:
67 lines (58 loc) 2.4 kB
var xmlCrypto = require('xml-crypto'), xmldom = require('xmldom'); exports.verifySignature = function(assertion, cert) { var doc = new xmldom.DOMParser().parseFromString(assertion); var signature = xmlCrypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; var sig = new xmlCrypto.SignedXml(null, { idAttribute: 'AssertionID' }); sig.keyInfoProvider = { getKeyInfo: function (key) { return "<X509Data></X509Data>"; }, getKey: function (keyInfo) { return cert; } }; sig.loadSignature(signature.toString()); return sig.checkSignature(assertion); }; exports.getIssuer = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement.getAttribute('Issuer'); }; exports.getSignatureMethodAlgorithm = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement .getElementsByTagName('SignatureMethod')[0] .getAttribute('Algorithm'); }; exports.getDigestMethodAlgorithm = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement .getElementsByTagName('DigestMethod')[0] .getAttribute('Algorithm'); }; exports.getIssueInstant = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement.getAttribute('IssueInstant'); }; exports.getConditions = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement.getElementsByTagName('saml:Conditions'); }; exports.getAudiences = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement .getElementsByTagName('saml:Conditions')[0] .getElementsByTagName('saml:AudienceRestrictionCondition')[0] .getElementsByTagName('saml:Audience'); }; exports.getAttributes = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement .getElementsByTagName('saml:Attribute'); }; exports.getNameIdentifier = function(assertion) { var doc = new xmldom.DOMParser().parseFromString(assertion); return doc.documentElement .getElementsByTagName('saml:NameIdentifier')[0]; };