How to use the xml-crypto.xpath function in xml-crypto

To help you get started, we’ve selected a few xml-crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RocketChat / Rocket.Chat / app / meteor-accounts-saml / server / saml_utils.js View on Github external
SAML.prototype.validateSignature = function(xml, cert) {
	const self = this;

	const doc = new xmldom.DOMParser().parseFromString(xml);
	const signature = xmlCrypto.xpath(doc, '//*[local-name(.)=\'Signature\' and namespace-uri(.)=\'http://www.w3.org/2000/09/xmldsig#\']')[0];

	const sig = new xmlCrypto.SignedXml();

	sig.keyInfoProvider = {
		getKeyInfo(/* key*/) {
			return '';
		},
		getKey(/* keyInfo*/) {
			return self.certToPEM(cert);
		},
	};

	sig.loadSignature(signature);

	return sig.checkSignature(xml);
};
github auth0 / node-samlp / lib / signers.js View on Github external
module.exports.validateXmlEmbeddedSignature = function (xml, options) {
  var calculatedThumbprint = '';
  var signature = xmlCrypto.xpath(xml, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0];
  if (!signature){
    return ['Signature is missing'];
  }

  if (options.thumprints){
    // Make sure thumprints is an array for the validation 
    options.thumbprints = options.thumbprints instanceof Array ? options.thumbprints : [options.thumbprints];
  }

  var sig = new SignedXml();

  sig.keyInfoProvider = {
    getKeyInfo: function () {
      return "";
    },
    getKey: function (keyInfo) {
github tngan / samlify / test / issues.ts View on Github external
test('#98 undefined AssertionConsumerServiceURL with redirect request', t => {
    const { id, context } = sp98.createLoginRequest(idp, 'redirect');
    const originalURL = url.parse(context, true);
    const request = originalURL.query.SAMLRequest as string;
    const rawRequest = utility.inflateString(decodeURIComponent(request));
    const xml = new dom().parseFromString(rawRequest);
    const authnRequest = select(xml, "/*[local-name(.)='AuthnRequest']")[0];
    const index = Object.keys(authnRequest.attributes).find((i: string) => authnRequest.attributes[i].nodeName === 'AssertionConsumerServiceURL') as any;
    t.is(authnRequest.attributes[index].nodeValue, 'https://example.org/response');
  });
})();
github tngan / samlify / test / index.js View on Github external
describe('2. SamlLib.js', function() {
    var _originRequest = fs.readFileSync('./test/metadata/SAMLRequest.xml').toString();
    var _originResponse = fs.readFileSync('./test/metadata/SAMLResponse.xml').toString();

    var _decodedResponse = fs.readFileSync('./test/metadata/SignSAMLResponse.xml').toString();
    var _decodedResponseDoc = new dom().parseFromString(_decodedResponse);
    var _decodedResponseSignature = select(_decodedResponseDoc, "/*/*[local-name(.)='Signature']")[0];

    var _decodedRequestSHA256 = fs.readFileSync('./test/metadata/SignSAMLRequestSHA256.xml').toString();
    var _decodedRequestDocSHA256 = new dom().parseFromString(_decodedRequestSHA256);
    var _decodedRequestSignatureSHA256 = select(_decodedRequestDocSHA256, "/*/*[local-name(.)='Signature']")[0];

    var _decodedRequestSHA512 = fs.readFileSync('./test/metadata/SignSAMLRequestSHA512.xml').toString();
    var _decodedRequestDocSHA512 = new dom().parseFromString(_decodedRequestSHA512);
    var _decodedRequestSignatureSHA512 = select(_decodedRequestDocSHA512, "/*/*[local-name(.)='Signature']")[0];

    var octetString = 'SAMLRequest=fVNdj9MwEHxH4j9Yfm%2Fi5PpBrLaotEJUOrioKTzwgoy9oZZiO9ibu%2FLvcXLtKUhHnyzZM7Mzu+tlEKZp+abDkz3A7w4CkrNpbODDw4p23nIngg7cCgOBo+TV5vM9zxPGW+%2FQSdfQEeU2Q4QAHrWzlOx3K%2FrjHSsWbFEzdsfETDE2z5ksVKHqYlHP84WooVBS5lNKvoEPkbeiUYaS0rtHrcB%2FiRVWtCoJRuNRM4QO9jagsBiRLJtO2GKSzY%2F5HZ%2FlfDr7TskuIrUVOIidEFueplq1CZyFaRtIpDNpVT1U4B+1hKQ9tUO5IegHbZW2v25n%2FPkMCvzT8VhOyofqSMnmmnvrbOgM+Iv818P9i4nwrwcFxmVp1IJzb+K9kIGu374hZNm3mQ9R%2Ffp1rgEUSqBYpmPsC7nlfd%2F2u9I1Wv4hH503Av8fKkuy4UarST1AORihm41SHkKI4ZrGPW09CIyzQN8BTce1LmsFaliy2ACEM5KtM63wOvRTiNYlPoe7xhtjt01cmwPU65ubJbnscfG6jMeT8+qS%2FlWpwV96w2BEXN%2FHn2P9Fw%3D%3D&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1';
    var octetStringSHA256 = 'SAMLRequest=fZJbTwIxEIX%2Fyqbvy3Yv3BogQYiRBJWw6INvY3eAJt0WO10v%2F966YIKJkPRpek7nfDMdEdT6IKaN35s1vjVIPvqstSHRXoxZ44ywQIqEgRpJeCnK6f1SZB0uDs56K61mZ5brDiBC55U1LFrMx2wrB8P%2BIB%2FGeQHbuOgVwxigB3EqewXfDjDPZJ9Fz%2BgoWMYsvBB8RA0uDHkwPpR42o1THvNswzMRTtHtpEX2wqJ5QFEGfOvce38QSaKtBL235EXOeZoQ2aRUZqexVDvzaEp070pikveG3W5otTrx3ShTBdl1tNejiMTdZrOKV4%2FlhkXTX9yZNdTU6E4dntbLfzIVnGdtJpDEJqOfaYqW1k0ua2v0UIGHUXKuHx3X%2BhBSLuYrq5X8im6tq8Ffhkg7aVtRVbxtpQJrUHpaVQ6JAozW9mPmEDyGzYEmZMnk2PbvB5p8Aw%3D%3D&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256';
    var octetStringSHA512 = 'SAMLRequest=fZJfT8IwFMW%2FytL3sY5tCA0jQYiRBIUw9MG3a3cnTboWezv%2FfHvr0AQT9fX2nJ7zu%2B2UoNVHMe%2F8wezwuUPy0VurDYn%2BoGSdM8ICKRIGWiThpajmN2sxHHBxdNZbaTU7s%2FzvACJ0XlnDotWyZFBkDcAE47wZjeNcXqTxGAsZy0lR1EUzAiwaFt2jo2ApWbgh%2BIg6XBnyYHwY8bSIUx7z4Z4PRZaLbDLg4%2FyBRcuAogz43nnw%2FiiSRFsJ%2BmDJi4zzNCGySaXMk8ZKPZmNqdC9KIlJNgr5IWr7xXepTB1k%2F6M9nkQkrvf7bbzdVHsWzb9xF9ZQ16L7SrjbrX%2FplHM%2B7DuBJDabfm5T9LRu9re2RQ81eJgm5%2Frp6VlvQ8vVcmu1ku%2FRlXUt%2BL8h0kHaT1QdN71UYAtKz%2BvaIVGA0dq%2BLhyCx5I1oAlZMjvF%2FvxAsw8%3D&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha512';

    var signatureB64SHA512 = 'rLIExCcCVXup1szC1vh1Q+JZyRu5gXcAI3NuU3Wkws2uqBpgCjiKU0etFWTmakJHvomMlHkzjVgPJbZAnJYPGfY3PYenJmTrrYORcZ1O73Io0enQsMyF/fholtcFcHSM2dN1rBuMaImEUON+nrtcf0v4b73kVizLXLCejGPgXEoASLs6tk9nzDCNLRJECwkgmFRWwWoo4e57SyH5aWPUR0Vz7VV/UJ4TJgUpdWMOM65QVDBQDckpkttIcMssOl9WzOqJGXdSTTn5K7UlljK8mVh5V0zKSZnQld4qXicW+Dm+P1QCiwfcxf0IklYFoU6bd0LCuxyAW7pmwI8PYpA76Q==';
    var signatureB64SHA256 = 'iC7RXfHuIu4gBLGABv0qtt96XFvyC7QSX8cDyLjJj+WNOTRMO5J/AYKelVhuc2AZuyGcf/sfeeVmcW7wyKTBHiGS+AWUCljmG43mPWERPfsa7og+GxrsHDSFh5nD70mQF44bXvpo/oVOxHx/lPiDG5LZg2KBccNXqJxMVUhnyU6xeGBctYY5ZQ4y7MGOx7hWTWjHyv+wyFd44Bcq0kpunTls91z03GkYo/Oxd4KllbfR5D2v6awjrc79wMYL1CcZiKZ941ter6tHOHCwtZRhTqV3Dl42zOKUOCyGcjJnVzJre1QBA7hrn3WB5/fu5kE6/E9ENRWp8ZRJLbU8C2Oogg==';
    var signatureB64SHA1 = 'UKPzYQivZOavFV3QjOH/B9AwKls9n5hZIzOL+V93Yi7lJ7siNkAA9WZgErtFVpDTN6ngSwvlfP/hXZcS33RcCGBWi1SX+xuwuk2U7bZgdkkw4tIH8zcgiR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xQ21RS0lNQXdHQTFVZEV3UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFHNGxZWDNLUVhlbmV6NExwRG5aaGNGQkVaaTlZc3RVS1BGNUVLZCtXcGxwVmJjVFFjMUEzL1ordUhSbXlWOGgrcFF6ZUY2TGlvYjM3Rzg3WXBhY1BwbEpJNjZjZjJSajdqOGhTQk5iZHIrNjZFMnFwY0VoQUYxaUptekJOeWhiL3lkbEV1VnBuOC9Fc29QK0h2QmVpRGw1Z29uMzU2Mk16WklnVi9wTGRUZnhIeVc2aHpBUWhqR3EyVWhjdlIrZ1hOVkp2SFAyZVM0amxIbkprQjliZm8wa3ZmODdRK0Q2WEtYM3E1YzNtTzh0cVc2VXBxSFNDK3VMRXB6WmlOTGV1RmE0VFVJaGdCZ2pEamxSck5ES3U4bmRhbmNTbjN5QkhZbnFKMnQ5Y1IrY29Gbm5qWUFCUXBOcnZrNG10bVhZOFNYb0J6WUc5WStscWVBdW42KzBZeUU9PC9YNTA5Q2VydGlmaWNhdGU+PC9YNTA5RGF0YT48L0tleUluZm8+PC9TaWduYXR1cmU+PC9zYW1scDpBdXRoblJlcXVlc3Q+';

    describe('2.1 construct a SAML message signature', function() {
        it('RSA-SHA1', function(done) {
            (SamlLib.constructMessageSignature(octetString, _spPrivPem, _spPrivKeyPass).toString('base64')).should.be.equal(signatureB64SHA1);
            done();
github tngan / samlify / test / index.js View on Github external
describe('2. SamlLib.js', function() {
    var _originRequest = fs.readFileSync('./test/metadata/SAMLRequest.xml').toString();
    var _originResponse = fs.readFileSync('./test/metadata/SAMLResponse.xml').toString();

    var _decodedResponse = fs.readFileSync('./test/metadata/SignSAMLResponse.xml').toString();
    var _decodedResponseDoc = new dom().parseFromString(_decodedResponse);
    var _decodedResponseSignature = select(_decodedResponseDoc, "/*/*[local-name(.)='Signature']")[0];

    var _decodedRequestSHA256 = fs.readFileSync('./test/metadata/SignSAMLRequestSHA256.xml').toString();
    var _decodedRequestDocSHA256 = new dom().parseFromString(_decodedRequestSHA256);
    var _decodedRequestSignatureSHA256 = select(_decodedRequestDocSHA256, "/*/*[local-name(.)='Signature']")[0];

    var _decodedRequestSHA512 = fs.readFileSync('./test/metadata/SignSAMLRequestSHA512.xml').toString();
    var _decodedRequestDocSHA512 = new dom().parseFromString(_decodedRequestSHA512);
    var _decodedRequestSignatureSHA512 = select(_decodedRequestDocSHA512, "/*/*[local-name(.)='Signature']")[0];

    var octetString = 'SAMLRequest=fVNdj9MwEHxH4j9Yfm%2Fi5PpBrLaotEJUOrioKTzwgoy9oZZiO9ibu%2FLvcXLtKUhHnyzZM7Mzu+tlEKZp+abDkz3A7w4CkrNpbODDw4p23nIngg7cCgOBo+TV5vM9zxPGW+%2FQSdfQEeU2Q4QAHrWzlOx3K%2FrjHSsWbFEzdsfETDE2z5ksVKHqYlHP84WooVBS5lNKvoEPkbeiUYaS0rtHrcB%2FiRVWtCoJRuNRM4QO9jagsBiRLJtO2GKSzY%2F5HZ%2FlfDr7TskuIrUVOIidEFueplq1CZyFaRtIpDNpVT1U4B+1hKQ9tUO5IegHbZW2v25n%2FPkMCvzT8VhOyofqSMnmmnvrbOgM+Iv818P9i4nwrwcFxmVp1IJzb+K9kIGu374hZNm3mQ9R%2Ffp1rgEUSqBYpmPsC7nlfd%2F2u9I1Wv4hH503Av8fKkuy4UarST1AORihm41SHkKI4ZrGPW09CIyzQN8BTce1LmsFaliy2ACEM5KtM63wOvRTiNYlPoe7xhtjt01cmwPU65ubJbnscfG6jMeT8+qS%2FlWpwV96w2BEXN%2FHn2P9Fw%3D%3D&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1';
    var octetStringSHA256 = 'SAMLRequest=fZJbTwIxEIX%2Fyqbvy3Yv3BogQYiRBJWw6INvY3eAJt0WO10v%2F966YIKJkPRpek7nfDMdEdT6IKaN35s1vjVIPvqstSHRXoxZ44ywQIqEgRpJeCnK6f1SZB0uDs56K61mZ5brDiBC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Y3PYenJmTrrYORcZ1O73Io0enQsMyF/fholtcFcHSM2dN1rBuMaImEUON+nrtcf0v4b73kVizLXLCejGPgXEoASLs6tk9nzDCNLRJECwkgmFRWwWoo4e57SyH5aWPUR0Vz7VV/UJ4TJgUpdWMOM65QVDBQDckpkttIcMssOl9WzOqJGXdSTTn5K7UlljK8mVh5V0zKSZnQld4qXicW+Dm+P1QCiwfcxf0IklYFoU6bd0LCuxyAW7pmwI8PYpA76Q==';
    var signatureB64SHA256 = 'iC7RXfHuIu4gBLGABv0qtt96XFvyC7QSX8cDyLjJj+WNOTRMO5J/AYKelVhuc2AZuyGcf/sfeeVmcW7wyKTBHiGS+AWUCljmG43mPWERPfsa7og+GxrsHDSFh5nD70mQF44bXvpo/oVOxHx/lPiDG5LZg2KBccNXqJxMVUhnyU6xeGBctYY5ZQ4y7MGOx7hWTWjHyv+wyFd44Bcq0kpunTls91z03GkYo/Oxd4KllbfR5D2v6awjrc79wMYL1CcZiKZ941ter6tHOHCwtZRhTqV3Dl42zOKUOCyGcjJnVzJre1QBA7hrn3WB5/fu5kE6/E9ENRWp8ZRJLbU8C2Oogg==';
    var signatureB64SHA1 = 'UKPzYQivZOavFV3QjOH/B9AwKls9n5hZIzOL+V93Yi7lJ7siNkAA9WZgErtFVpDTN6ngSwvlfP/hXZcS33RcCGBWi1SX+xuwuk2U7bZgdkkw4tIH8zcgiRy8bK0IpMoXmLbApU2QsiNwRDMZq3iQdlaMhlsJh85VI+90SQk7fewseiw5Ui6BIpFSH96gLYjWMDPpwk+0GkhkkVaP5vo+I6mBQryD9YPFRu7JfCrnw2T6gldXlGu0IN326+qajKheAGmPSLWBmeFYhquJ5ipgfQGU/KCNIEUr6hkW8NU0+6EVaZl/A9Fyfs1+8KCQ6HxZ7FGyewQjJIx3a8XvBM5vDg==';
github auth0 / node-saml / test / utils.js View on Github external
exports.isValidSignature = 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 "";
    },
    getKey: function (keyInfo) {
      return cert;
    }
  };
  sig.loadSignature(signature.toString());
  return sig.checkSignature(assertion);
};
github yaronn / xml-crypto / example / example.js View on Github external
function validateXml(xml, key)
{
  var doc = new dom().parseFromString(xml)    
  var signature = select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]
  var sig = new SignedXml()
  sig.keyInfoProvider = new FileKeyInfo(key)
  sig.loadSignature(signature.toString())
  var res = sig.checkSignature(xml)
  if (!res) console.log(sig.validationErrors)
  return res;
}
github AzureAD / passport-azure-ad / lib / wsfedsaml.js View on Github external
SAML.prototype.validateSignature = function validateSignature(xml, cert, thumbprint) {
  const self = this;
  const doc = new xmldom.DOMParser().parseFromString(xml);
  const xpathExpression = '/*/*[local-name(.)="Signature" and namespace-uri(.)="http://www.w3.org/2000/09/xmldsig#"]';
  const signature = xmlCrypto.xpath(doc, xpathExpression)[0];
  const sig = new xmlCrypto.SignedXml(null, {
    idAttribute: 'AssertionID',
  });
  sig.keyInfoProvider = {
    getKeyInfo: () => {
      return '';
    },
    getKey: (keyInfo) => {
      if (thumbprint) {
        const embeddedSignature = keyInfo[0].getElementsByTagName('X509Certificate');
        if (embeddedSignature.length > 0) {
          const base64cer = embeddedSignature[0].firstChild.toString();
          const shasum = crypto.createHash('sha1');
          const der = new Buffer(base64cer, 'base64').toString('binary');
          shasum.update(der);
          self.calculatedThumbprint = shasum.digest('hex');
github leandrob / saml20 / lib / validateSignature.js View on Github external
module.exports = function validateSignature(xml, cert, certThumbprint) {
  var doc = new dom().parseFromString(xml);
  var signature = select(doc, '/*/*/*[local-name(.)=\'Signature\' and namespace-uri(.)=\'http://www.w3.org/2000/09/xmldsig#\']')[0]
    || select(doc, '/*/*[local-name(.)=\'Signature\' and namespace-uri(.)=\'http://www.w3.org/2000/09/xmldsig#\']')[0];
  var signed = new SignedXml(null, {
    idAttribute: 'AssertionID'
  });

  var calculatedThumbprint;

  signed.keyInfoProvider = {
    getKey: function getKey(keyInfo) {
      if (certThumbprint) {
        var embeddedSignature = keyInfo[0].getElementsByTagNameNS('http://www.w3.org/2000/09/xmldsig#', 'X509Certificate');

        if (embeddedSignature.length > 0) {
          var base64cer = embeddedSignature[0].firstChild.toString();

          calculatedThumbprint = thumbprint.calculate(base64cer);
github FabianBravoA / tbk_node / lib / tbk.js View on Github external
TBK.prototype.verifySignature 	= function(xml){
	var doc = new dom().parseFromString(xml)    

    var signature 	= select(doc, "//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0];
    var sig = new SignedXml();
    //Hack to check non-standard transbank SignedInfo node
	sig.__proto__.validateSignatureValue = function() {
	  	var signedInfo = select(doc, "//*[local-name(.)='SignedInfo']");
	  	if (signedInfo.length==0) throw new Error("could not find SignedInfo element in the message");
	  	var signedInfoCanon = this.getCanonXml([this.canonicalizationAlgorithm], signedInfo[0]);
		signedInfoCanon   = signedInfoCanon.toString().replace("xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"", "xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"");
	  	var signer = this.findSignatureAlgorithm(this.signatureAlgorithm);
	  	var res = signer.verifySignature(signedInfoCanon, this.signingKey, this.signatureValue);
	  	if (!res) this.validationErrors.push("invalid signature: the signature value " + this.signatureValue + " is incorrect");
	  	return res
	};

    sig.keyInfoProvider = new FileKeyInfo(this.config.WEBPAY_KEY);
    sig.loadSignature(signature);
    var res = sig.checkSignature(xml);

xml-crypto

Xml digital signature and encryption library for Node.js

MIT
Latest version published 9 months ago

Package Health Score

83 / 100
Full package analysis