Skip to content

Add tests for sha256-rsa-MGF1#1

Open
kaibernhard wants to merge 4 commits intoStadtLandNetz:masterfrom
digitalservicebund:StadtLandNetz
Open

Add tests for sha256-rsa-MGF1#1
kaibernhard wants to merge 4 commits intoStadtLandNetz:masterfrom
digitalservicebund:StadtLandNetz

Conversation

@kaibernhard
Copy link

Add unit tests for signing and verifying with all signature algorithms and saml response tests with sha256-rsa-MGF1.

valid_saml_sha256_rsa_mgf1.xml has been signed with:

xmlsectool --sign \
           --inFile unsigned_saml_response.xml \
           --outFile valid_saml_sha256_rsa_mgf1.xml \
           --keyFile idp_private_key.pem \
           --certificate idp_certificate.pem \
           --signatureAlgorithm http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1

valid_saml_sha256_rsa_mgf1.xml has been signed with:

xmlsectool --sign \
           --inFile unsigned_saml_response.xml \
           --outFile valid_saml_sha256_rsa_mgf1.xml \
           --keyFile idp_private_key.pem \
           --certificate idp_certificate.pem \
           --signatureAlgorithm http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1
const xml = signWith(signatureAlgorithm)
const sig = loadSignature(xml)
const res = sig.checkSignature(xml);
expect(res, "expected all signatures to be valid, but some reported invalid").to.be.true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error should vary with the test, thus, I'd expect ${signatureAlgorithm} to be in the expect().

expect(nodes.length).to.equal(1)
const node = nodes[0];
isDomNode.assertIsElementNode(node);
const targetElement = node as Element;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, did you do this because the type narrowing on isDomNode.assertIsElementNode(node) isn't working?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isDomNode.assertIsElementNode on the result of xpath.select failed with Error: Value is not of type ELEMENT_NODE, but I realized that I can use select1 and simplify that code. Thanks!


const sig = loadSignature(manipulatedXml)
const res = sig.checkSignature(manipulatedXml);
expect(res, "expected all signatures to be invalid, but some reported valid").to.be.false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous note about errors varying with the test.

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

Successfully merging this pull request may close these issues.

2 participants