jdk/test/javax/xml/crypto/dsig/ValidationTests.java
author juh
Fri, 09 Jan 2015 11:58:34 -0800
changeset 28308 5fdc6e6c0b97
parent 18240 cda839ac048f
child 30648 91e34299190c
permissions -rw-r--r--
8046724: XML Signature ECKeyValue elements cannot be marshalled or unmarshalled Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28308
5fdc6e6c0b97 8046724: XML Signature ECKeyValue elements cannot be marshalled or unmarshalled
juh
parents: 18240
diff changeset
     2
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3462
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3462
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3462
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
28308
5fdc6e6c0b97 8046724: XML Signature ECKeyValue elements cannot be marshalled or unmarshalled
juh
parents: 18240
diff changeset
    26
 * @bug 4635230 6365103 6366054 6824440 7131084 8046724
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Basic unit tests for validating XML Signatures with JSR 105
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *     X509KeySelector.java ValidationTests.java
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 11674
diff changeset
    30
 * @run main/othervm ValidationTests
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.xml.crypto.Data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.xml.crypto.KeySelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.xml.crypto.OctetStreamData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.xml.crypto.URIDereferencer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.xml.crypto.URIReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.xml.crypto.URIReferenceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.xml.crypto.XMLCryptoContext;
3462
4477fb399895 6824440: XML Signature HMAC issue
mullan
parents: 2
diff changeset
    43
import javax.xml.crypto.dsig.XMLSignatureException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.xml.crypto.dsig.XMLSignatureFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class ValidationTests {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static SignatureValidator validator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private final static String DIR = System.getProperty("test.src", ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private final static String DATA_DIR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        DIR + System.getProperty("file.separator") + "data";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final static String KEYSTORE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        DATA_DIR + System.getProperty("file.separator") + "certs" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        System.getProperty("file.separator") + "xmldsig.jks";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private final static String STYLESHEET =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        "http://www.w3.org/TR/xml-stylesheet";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private final static String STYLESHEET_B64 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        "http://www.w3.org/Signature/2002/04/xml-stylesheet.b64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    60
    static class Test {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    61
        String file;
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    62
        KeySelector ks;
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    63
        Test(String file, KeySelector ks) {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    64
            this.file = file;
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    65
            this.ks = ks;
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    66
        }
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    67
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    static KeySelector skks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            skks =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                new KeySelectors.SecretKeySelector("secret".getBytes("ASCII"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            //should not occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private final static KeySelector SKKS = skks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private final static KeySelector KVKS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new KeySelectors.KeyValueKeySelector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private final static KeySelector CKS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        new KeySelectors.CollectionKeySelector(new File(DATA_DIR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private final static KeySelector RXKS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        new KeySelectors.RawX509KeySelector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private final static KeySelector XKS = null;
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    86
    private static URIDereferencer httpUd = null;
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    87
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    88
    private final static Test[] VALID_TESTS = {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    89
        new Test("signature-enveloped-dsa.xml", KVKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    90
        new Test("signature-enveloping-b64-dsa.xml", KVKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    91
        new Test("signature-enveloping-dsa.xml", KVKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    92
        new Test("signature-enveloping-rsa.xml", KVKS),
28308
5fdc6e6c0b97 8046724: XML Signature ECKeyValue elements cannot be marshalled or unmarshalled
juh
parents: 18240
diff changeset
    93
        new Test("signature-enveloping-p256-sha1.xml", KVKS),
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    94
        new Test("signature-enveloping-hmac-sha1.xml", SKKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    95
        new Test("signature-external-dsa.xml", KVKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    96
        new Test("signature-external-b64-dsa.xml", KVKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    97
        new Test("signature-retrievalmethod-rawx509crt.xml", CKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    98
        new Test("signature-keyname.xml", CKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
    99
        new Test("signature-x509-crt-crl.xml", RXKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   100
        new Test("signature-x509-crt.xml", RXKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   101
        new Test("signature-x509-is.xml", CKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   102
        new Test("signature-x509-ski.xml", CKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   103
        new Test("signature-x509-sn.xml", CKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   104
        new Test("signature.xml", XKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   105
        new Test("exc-signature.xml", KVKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   106
        new Test("sign-spec.xml", RXKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   107
        new Test("xmldsig-xfilter2.xml", KVKS)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    };
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   109
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   110
    private final static Test[] INVALID_TESTS = {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   111
        new Test("signature-enveloping-hmac-sha1-40.xml", SKKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   112
        new Test("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", SKKS),
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   113
        new Test("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", SKKS)
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   114
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        httpUd = new HttpURIDereferencer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        validator = new SignatureValidator(new File(DATA_DIR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        boolean atLeastOneFailed = false;
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   122
        for (Test test : VALID_TESTS) {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   123
            System.out.println("Validating " + test.file);
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   124
            if (test_signature(test)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                System.out.println("PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                System.out.println("FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                atLeastOneFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // test with reference caching enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        System.out.println("Validating sign-spec.xml with caching enabled");
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   133
        if (test_signature(new Test("sign-spec.xml", RXKS), true)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            System.out.println("PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            System.out.println("FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            atLeastOneFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   140
        for (Test test : INVALID_TESTS) {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   141
            System.out.println("Validating " + test.file);
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   142
            try {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   143
                test_signature(test);
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   144
                System.out.println("FAILED");
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   145
                atLeastOneFailed = true;
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   146
            } catch (XMLSignatureException xse) {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   147
                System.out.println(xse.getMessage());
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   148
                System.out.println("PASSED");
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   149
            }
3462
4477fb399895 6824440: XML Signature HMAC issue
mullan
parents: 2
diff changeset
   150
        }
4477fb399895 6824440: XML Signature HMAC issue
mullan
parents: 2
diff changeset
   151
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (atLeastOneFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throw new Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                ("At least one signature did not validate as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   158
    public static boolean test_signature(Test test) throws Exception {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   159
        return test_signature(test, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   162
    public static boolean test_signature(Test test, boolean cache)
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   163
        throws Exception
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   164
    {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   165
        if (test.ks == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            KeyStore keystore = KeyStore.getInstance("JKS");
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   167
            try (FileInputStream fis = new FileInputStream(KEYSTORE)) {
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   168
                keystore.load(fis, "changeit".toCharArray());
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   169
                test.ks = new X509KeySelector(keystore, false);
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   170
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
11674
a657f8ba55fc 7131084: XMLDSig XPathFilter2Transform regression involving intersect filter
mullan
parents: 5506
diff changeset
   172
        return validator.validate(test.file, test.ks, httpUd, cache);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * This URIDereferencer returns locally cached copies of http content to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * avoid test failures due to network glitches, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static class HttpURIDereferencer implements URIDereferencer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        private URIDereferencer defaultUd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        HttpURIDereferencer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            defaultUd = XMLSignatureFactory.getInstance().getURIDereferencer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        public Data dereference(final URIReference ref, XMLCryptoContext ctx)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        throws URIReferenceException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            String uri = ref.getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (uri.equals(STYLESHEET) || uri.equals(STYLESHEET_B64)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    FileInputStream fis = new FileInputStream(new File
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        (DATA_DIR, uri.substring(uri.lastIndexOf('/'))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    return new OctetStreamData(fis,ref.getURI(),ref.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                } catch (Exception e) { throw new URIReferenceException(e); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // fallback on builtin deref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            return defaultUd.dereference(ref, ctx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}