test/javax/xml/crypto/dsig/ValidationTests.java

Print this page

        

*** 33,42 **** --- 33,43 ---- import java.io.File; import java.io.FileInputStream; import java.security.*; import javax.xml.crypto.Data; import javax.xml.crypto.KeySelector; + import javax.xml.crypto.MarshalException; import javax.xml.crypto.OctetStreamData; import javax.xml.crypto.URIDereferencer; import javax.xml.crypto.URIReference; import javax.xml.crypto.URIReferenceException; import javax.xml.crypto.XMLCryptoContext;
*** 58,70 **** "http://www.w3.org/Signature/2002/04/xml-stylesheet.b64"; static class Test { String file; KeySelector ks; ! Test(String file, KeySelector ks) { this.file = file; this.ks = ks; } } static KeySelector skks; static { --- 59,79 ---- "http://www.w3.org/Signature/2002/04/xml-stylesheet.b64"; static class Test { String file; KeySelector ks; ! Class exception; ! ! Test(String file, KeySelector ks, Class exception) { this.file = file; this.ks = ks; + this.exception = exception; + } + + // XMLSignatureException is expected by default + Test(String file, KeySelector ks) { + this(file, ks, XMLSignatureException.class); } } static KeySelector skks; static {
*** 108,118 **** }; private final static Test[] INVALID_TESTS = { new Test("signature-enveloping-hmac-sha1-40.xml", SKKS), new Test("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", SKKS), ! new Test("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", SKKS) }; public static void main(String args[]) throws Exception { httpUd = new HttpURIDereferencer(); --- 117,137 ---- }; private final static Test[] INVALID_TESTS = { new Test("signature-enveloping-hmac-sha1-40.xml", SKKS), new Test("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", SKKS), ! new Test("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", SKKS), ! new Test("signature-extra-text-in-signed-info.xml", SKKS, ! MarshalException.class), ! new Test("signature-wrong-canonicalization-method-algorithm.xml", SKKS, ! MarshalException.class), ! new Test("signature-wrong-transform-algorithm.xml", SKKS, ! MarshalException.class), ! new Test("signature-no-reference-uri.xml", SKKS), ! new Test("signature-wrong-signature-method-algorithm.xml", SKKS, ! MarshalException.class), ! new Test("signature-wrong-tag-names.xml", SKKS, MarshalException.class) }; public static void main(String args[]) throws Exception { httpUd = new HttpURIDereferencer();
*** 141,155 **** System.out.println("Validating " + test.file); try { test_signature(test); System.out.println("FAILED"); atLeastOneFailed = true; ! } catch (XMLSignatureException xse) { ! System.out.println(xse.getMessage()); System.out.println("PASSED"); } } if (atLeastOneFailed) { throw new Exception ("At least one signature did not validate as expected"); } --- 160,179 ---- System.out.println("Validating " + test.file); try { test_signature(test); System.out.println("FAILED"); atLeastOneFailed = true; ! } catch (Exception e) { ! System.out.println("Exception: " + e); ! if (e.getClass() != test.exception) { ! System.out.println("FAILED: unexpected exception"); ! atLeastOneFailed = true; ! } else { System.out.println("PASSED"); } } + } if (atLeastOneFailed) { throw new Exception ("At least one signature did not validate as expected"); }