src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 27747 jdk/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java@3a271dc8b758
child 50614 3810c9a2efa1
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     2
 * reserved comment block
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    11
 * "License"); you may not use this file except in compliance
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    12
 * with the License. You may obtain a copy of the License at
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    17
 * software distributed under the License is distributed on an
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    19
 * KIND, either express or implied. See the License for the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    21
 * under the License.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    22
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    23
/*
24251
da7dc40edb67 8038349: Signing XML with DSA throws Exception when key is larger than 1024 bits
mullan
parents: 23010
diff changeset
    24
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    25
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    26
/*
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    27
 * $Id: DOMXMLSignatureFactory.java 1333869 2012-05-04 10:42:44Z coheigea $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package org.jcp.xml.dsig.internal.dom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.xml.crypto.*;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    32
import javax.xml.crypto.dom.DOMCryptoContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.xml.crypto.dsig.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.xml.crypto.dsig.dom.DOMValidateContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.xml.crypto.dsig.keyinfo.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.xml.crypto.dsig.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    38
import java.security.InvalidAlgorithmParameterException;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    39
import java.security.NoSuchAlgorithmException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * DOM-based implementation of XMLSignatureFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public final class DOMXMLSignatureFactory extends XMLSignatureFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Initializes a new instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public DOMXMLSignatureFactory() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        return new DOMXMLSignature(si, ki, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki,
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    62
        List<? extends XMLObject> objects, String id, String signatureValueId) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return new DOMXMLSignature(si, ki, objects, id, signatureValueId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public Reference newReference(String uri, DigestMethod dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return newReference(uri, dm, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    70
    public Reference newReference(String uri, DigestMethod dm,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    71
        List<? extends Transform> transforms, String type, String id) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    72
        return new DOMReference(uri, type, dm, transforms, id, getProvider());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public Reference newReference(String uri, DigestMethod dm,
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    76
        List<? extends Transform> appliedTransforms, Data result,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    77
        List<? extends Transform> transforms, String type, String id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (appliedTransforms == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            throw new NullPointerException("appliedTransforms cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (appliedTransforms.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new NullPointerException("appliedTransforms cannot be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            throw new NullPointerException("result cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return new DOMReference
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    88
            (uri, type, dm, appliedTransforms, result, transforms, id, getProvider());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    91
    public Reference newReference(String uri, DigestMethod dm,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    92
        List<? extends Transform> transforms, String type, String id,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    93
        byte[] digestValue) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (digestValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new NullPointerException("digestValue cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return new DOMReference
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    98
            (uri, type, dm, null, null, transforms, id, digestValue, getProvider());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public SignedInfo newSignedInfo(CanonicalizationMethod cm,
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   102
        SignatureMethod sm, List<? extends Reference> references) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return newSignedInfo(cm, sm, references, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public SignedInfo newSignedInfo(CanonicalizationMethod cm,
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   107
        SignatureMethod sm, List<? extends Reference> references, String id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return new DOMSignedInfo(cm, sm, references, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // Object factory methods
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   112
    public XMLObject newXMLObject(List<? extends XMLStructure> content,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   113
        String id, String mimeType, String encoding) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return new DOMXMLObject(content, id, mimeType, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   117
    public Manifest newManifest(List<? extends Reference> references) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return newManifest(references, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   121
    public Manifest newManifest(List<? extends Reference> references,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   122
        String id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return new DOMManifest(references, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   126
    public SignatureProperties newSignatureProperties(
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   127
        List<? extends SignatureProperty> props, String id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return new DOMSignatureProperties(props, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public SignatureProperty newSignatureProperty
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   132
        (List<? extends XMLStructure> info, String target, String id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return new DOMSignatureProperty(info, target, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public XMLSignature unmarshalXMLSignature(XMLValidateContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        throws MarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new NullPointerException("context cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return unmarshal(((DOMValidateContext) context).getNode(), context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public XMLSignature unmarshalXMLSignature(XMLStructure xmlStructure)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        throws MarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (xmlStructure == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throw new NullPointerException("xmlStructure cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   151
        if (!(xmlStructure instanceof javax.xml.crypto.dom.DOMStructure)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   152
            throw new ClassCastException("xmlStructure must be of type DOMStructure");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   153
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return unmarshal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            (((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode(),
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   156
             new UnmarshalContext());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   159
    private static class UnmarshalContext extends DOMCryptoContext {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   160
        UnmarshalContext() {}
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   161
    }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   162
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   163
    private XMLSignature unmarshal(Node node, XMLCryptoContext context)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        throws MarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        node.normalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Element element = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            element = ((Document) node).getDocumentElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } else if (node.getNodeType() == Node.ELEMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            element = (Element) node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            throw new MarshalException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                ("Signature element is not a proper Node");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // check tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        String tag = element.getLocalName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (tag == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new MarshalException("Document implementation must " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                "support DOM Level 2 and be namespace aware");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (tag.equals("Signature")) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   185
            return new DOMXMLSignature(element, context, getProvider());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            throw new MarshalException("invalid Signature tag: " + tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public boolean isFeatureSupported(String feature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (feature == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public DigestMethod newDigestMethod(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        DigestMethodParameterSpec params) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (algorithm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (algorithm.equals(DigestMethod.SHA1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return new DOMDigestMethod.SHA1(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } else if (algorithm.equals(DigestMethod.SHA256)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return new DOMDigestMethod.SHA256(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } else if (algorithm.equals(DOMDigestMethod.SHA384)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return new DOMDigestMethod.SHA384(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } else if (algorithm.equals(DigestMethod.SHA512)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            return new DOMDigestMethod.SHA512(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            throw new NoSuchAlgorithmException("unsupported algorithm");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public SignatureMethod newSignatureMethod(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        SignatureMethodParameterSpec params) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (algorithm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (algorithm.equals(SignatureMethod.RSA_SHA1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return new DOMSignatureMethod.SHA1withRSA(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        } else if (algorithm.equals(DOMSignatureMethod.RSA_SHA256)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return new DOMSignatureMethod.SHA256withRSA(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } else if (algorithm.equals(DOMSignatureMethod.RSA_SHA384)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return new DOMSignatureMethod.SHA384withRSA(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        } else if (algorithm.equals(DOMSignatureMethod.RSA_SHA512)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return new DOMSignatureMethod.SHA512withRSA(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        } else if (algorithm.equals(SignatureMethod.DSA_SHA1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return new DOMSignatureMethod.SHA1withDSA(params);
24251
da7dc40edb67 8038349: Signing XML with DSA throws Exception when key is larger than 1024 bits
mullan
parents: 23010
diff changeset
   234
        } else if (algorithm.equals(DOMSignatureMethod.DSA_SHA256)) {
da7dc40edb67 8038349: Signing XML with DSA throws Exception when key is larger than 1024 bits
mullan
parents: 23010
diff changeset
   235
            return new DOMSignatureMethod.SHA256withDSA(params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } else if (algorithm.equals(SignatureMethod.HMAC_SHA1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return new DOMHMACSignatureMethod.SHA1(params);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   238
        } else if (algorithm.equals(DOMHMACSignatureMethod.HMAC_SHA256)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return new DOMHMACSignatureMethod.SHA256(params);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   240
        } else if (algorithm.equals(DOMHMACSignatureMethod.HMAC_SHA384)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return new DOMHMACSignatureMethod.SHA384(params);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   242
        } else if (algorithm.equals(DOMHMACSignatureMethod.HMAC_SHA512)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return new DOMHMACSignatureMethod.SHA512(params);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   244
        } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA1)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   245
            return new DOMSignatureMethod.SHA1withECDSA(params);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   246
        } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA256)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   247
            return new DOMSignatureMethod.SHA256withECDSA(params);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   248
        } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA384)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   249
            return new DOMSignatureMethod.SHA384withECDSA(params);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   250
        } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA512)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   251
            return new DOMSignatureMethod.SHA512withECDSA(params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throw new NoSuchAlgorithmException("unsupported algorithm");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Transform newTransform(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        TransformParameterSpec params) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        InvalidAlgorithmParameterException {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   260
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   261
        TransformService spi;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   262
        if (getProvider() == null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   263
            spi = TransformService.getInstance(algorithm, "DOM");
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   264
        } else {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   265
            try {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   266
                spi = TransformService.getInstance(algorithm, "DOM", getProvider());
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   267
            } catch (NoSuchAlgorithmException nsae) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   268
                spi = TransformService.getInstance(algorithm, "DOM");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   269
            }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   270
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   271
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        spi.init(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return new DOMTransform(spi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public Transform newTransform(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        XMLStructure params) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        InvalidAlgorithmParameterException {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   279
        TransformService spi;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   280
        if (getProvider() == null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   281
            spi = TransformService.getInstance(algorithm, "DOM");
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   282
        } else {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   283
            try {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   284
                spi = TransformService.getInstance(algorithm, "DOM", getProvider());
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   285
            } catch (NoSuchAlgorithmException nsae) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   286
                spi = TransformService.getInstance(algorithm, "DOM");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   287
            }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   288
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   289
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (params == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            spi.init(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            spi.init(params, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return new DOMTransform(spi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public CanonicalizationMethod newCanonicalizationMethod(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        C14NMethodParameterSpec params) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        InvalidAlgorithmParameterException {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   301
        TransformService spi;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   302
        if (getProvider() == null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   303
            spi = TransformService.getInstance(algorithm, "DOM");
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   304
        } else {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   305
            try {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   306
                spi = TransformService.getInstance(algorithm, "DOM", getProvider());
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   307
            } catch (NoSuchAlgorithmException nsae) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   308
                spi = TransformService.getInstance(algorithm, "DOM");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   309
            }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   310
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   311
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        spi.init(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return new DOMCanonicalizationMethod(spi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public CanonicalizationMethod newCanonicalizationMethod(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        XMLStructure params) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        InvalidAlgorithmParameterException {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   319
        TransformService spi;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   320
        if (getProvider() == null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   321
            spi = TransformService.getInstance(algorithm, "DOM");
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   322
        } else {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   323
            try {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   324
                spi = TransformService.getInstance(algorithm, "DOM", getProvider());
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   325
            } catch (NoSuchAlgorithmException nsae) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   326
                spi = TransformService.getInstance(algorithm, "DOM");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   327
            }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   328
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (params == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            spi.init(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            spi.init(params, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   334
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return new DOMCanonicalizationMethod(spi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public URIDereferencer getURIDereferencer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return DOMURIDereferencer.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
}