jdk/test/javax/xml/crypto/dsig/ValidationTests.java
changeset 3462 4477fb399895
parent 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
3461:cbc3dfc3b609 3462:4477fb399895
     1 /*
     1 /*
     2  * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
     2  * Copyright 2005-2009 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * have any questions.
    21  * have any questions.
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 4635230
    26  * @bug 4635230 6365103 6366054 6824440
    27  * @bug 6365103
       
    28  * @bug 6366054
       
    29  * @summary Basic unit tests for validating XML Signatures with JSR 105
    27  * @summary Basic unit tests for validating XML Signatures with JSR 105
    30  * @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
    28  * @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
    31  *     X509KeySelector.java ValidationTests.java
    29  *     X509KeySelector.java ValidationTests.java
    32  * @run main ValidationTests
    30  * @run main ValidationTests
    33  * @author Sean Mullan
    31  * @author Sean Mullan
    40 import javax.xml.crypto.OctetStreamData;
    38 import javax.xml.crypto.OctetStreamData;
    41 import javax.xml.crypto.URIDereferencer;
    39 import javax.xml.crypto.URIDereferencer;
    42 import javax.xml.crypto.URIReference;
    40 import javax.xml.crypto.URIReference;
    43 import javax.xml.crypto.URIReferenceException;
    41 import javax.xml.crypto.URIReferenceException;
    44 import javax.xml.crypto.XMLCryptoContext;
    42 import javax.xml.crypto.XMLCryptoContext;
       
    43 import javax.xml.crypto.dsig.XMLSignatureException;
    45 import javax.xml.crypto.dsig.XMLSignatureFactory;
    44 import javax.xml.crypto.dsig.XMLSignatureFactory;
    46 
    45 
    47 /**
    46 /**
    48  * This is a testcase to validate all "merlin-xmldsig-twenty-three"
    47  * This is a testcase to validate all "merlin-xmldsig-twenty-three"
    49  * testcases from Baltimore
    48  * testcases from Baltimore
    66         "signature-enveloped-dsa.xml",
    65         "signature-enveloped-dsa.xml",
    67         "signature-enveloping-b64-dsa.xml",
    66         "signature-enveloping-b64-dsa.xml",
    68         "signature-enveloping-dsa.xml",
    67         "signature-enveloping-dsa.xml",
    69         "signature-enveloping-rsa.xml",
    68         "signature-enveloping-rsa.xml",
    70         "signature-enveloping-hmac-sha1.xml",
    69         "signature-enveloping-hmac-sha1.xml",
    71         "signature-enveloping-hmac-sha1-40.xml",
       
    72         "signature-external-dsa.xml",
    70         "signature-external-dsa.xml",
    73         "signature-external-b64-dsa.xml",
    71         "signature-external-b64-dsa.xml",
    74         "signature-retrievalmethod-rawx509crt.xml",
    72         "signature-retrievalmethod-rawx509crt.xml",
    75         "signature-keyname.xml",
    73         "signature-keyname.xml",
    76         "signature-x509-crt-crl.xml",
    74         "signature-x509-crt-crl.xml",
   104         KVKS,
   102         KVKS,
   105         KVKS,
   103         KVKS,
   106         KVKS,
   104         KVKS,
   107         KVKS,
   105         KVKS,
   108         SKKS,
   106         SKKS,
   109         SKKS,
       
   110         KVKS,
   107         KVKS,
   111         KVKS,
   108         KVKS,
   112         CKS,
   109         CKS,
   113         CKS,
   110         CKS,
   114         RXKS,
   111         RXKS,
   142         if (test_signature("sign-spec.xml", RXKS, true)) {
   139         if (test_signature("sign-spec.xml", RXKS, true)) {
   143             System.out.println("PASSED");
   140             System.out.println("PASSED");
   144         } else {
   141         } else {
   145             System.out.println("FAILED");
   142             System.out.println("FAILED");
   146             atLeastOneFailed = true;
   143             atLeastOneFailed = true;
       
   144         }
       
   145 
       
   146         System.out.println("Validating signature-enveloping-hmac-sha1-40.xml");
       
   147         try {
       
   148             test_signature("signature-enveloping-hmac-sha1-40.xml", SKKS, false);
       
   149             System.out.println("FAILED");
       
   150             atLeastOneFailed = true;
       
   151         } catch (XMLSignatureException xse) {
       
   152             System.out.println(xse.getMessage());
       
   153             System.out.println("PASSED");
       
   154         }
       
   155 
       
   156         System.out.println("Validating signature-enveloping-hmac-sha1-trunclen-0-attack.xml");
       
   157         try {
       
   158             test_signature("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", SKKS, false);
       
   159             System.out.println("FAILED");
       
   160             atLeastOneFailed = true;
       
   161         } catch (XMLSignatureException xse) {
       
   162             System.out.println(xse.getMessage());
       
   163             System.out.println("PASSED");
       
   164         }
       
   165 
       
   166         System.out.println("Validating signature-enveloping-hmac-sha1-trunclen-8-attack.xml");
       
   167         try {
       
   168             test_signature("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", SKKS, false);
       
   169             System.out.println("FAILED");
       
   170             atLeastOneFailed = true;
       
   171         } catch (XMLSignatureException xse) {
       
   172             System.out.println(xse.getMessage());
       
   173             System.out.println("PASSED");
   147         }
   174         }
   148 
   175 
   149         if (atLeastOneFailed) {
   176         if (atLeastOneFailed) {
   150             throw new Exception
   177             throw new Exception
   151                 ("At least one signature did not validate as expected");
   178                 ("At least one signature did not validate as expected");