jdk/src/share/classes/com/sun/org/apache/xml/internal/security/signature/SignedInfo.java
author mullan
Mon, 22 Apr 2013 11:23:33 +0100
changeset 18240 cda839ac048f
parent 1337 e8d6cef36199
child 18780 f47b920867e7
permissions -rw-r--r--
6741606: Integrate Apache Santuario Reviewed-by: vinnie, hawtin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.crypto.spec.SecretKeySpec;
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 1337
diff changeset
    28
import javax.xml.XMLConstants;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.xml.parsers.ParserConfigurationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.security.utils.Constants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import org.xml.sax.SAXException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Handles <code>&lt;ds:SignedInfo&gt;</code> elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This <code>SignedInfo<code> element includes the canonicalization algorithm,
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    47
 * a signature algorithm, and one or more references.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    48
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class SignedInfo extends Manifest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    53
    /** Field _signatureAlgorithm */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    54
    private SignatureAlgorithm _signatureAlgorithm = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    56
    /** Field _c14nizedBytes           */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    57
    private byte[] _c14nizedBytes = null;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    58
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    59
    private Element c14nMethod;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    60
    private Element signatureMethod;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    62
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    63
     * Overwrites {@link Manifest#addDocument} because it creates another
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    64
     * Element.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    65
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    66
     * @param doc the {@link Document} in which <code>XMLsignature</code> will
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    67
     *    be placed
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    68
     * @throws XMLSecurityException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    69
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    70
    public SignedInfo(Document doc) throws XMLSecurityException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    71
        this(doc, XMLSignature.ALGO_ID_SIGNATURE_DSA,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    72
             Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    73
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    75
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    76
     * Constructs {@link SignedInfo} using given Canonicalization algorithm and
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    77
     * Signature algorithm.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    78
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    79
     * @param doc <code>SignedInfo</code> is placed in this document
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    80
     * @param signatureMethodURI URI representation of the Digest and
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    81
     *    Signature algorithm
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    82
     * @param canonicalizationMethodURI URI representation of the
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    83
     *    Canonicalization method
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    84
     * @throws XMLSecurityException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    85
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    86
    public SignedInfo(Document doc, String signatureMethodURI,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    87
        String canonicalizationMethodURI)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
              throws XMLSecurityException {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    89
        this(doc, signatureMethodURI, 0, canonicalizationMethodURI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    90
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    92
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    93
     * Constructor SignedInfo
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    94
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    95
     * @param doc <code>SignedInfo</code> is placed in this document
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    96
     * @param signatureMethodURI URI representation of the Digest and
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    97
     *    Signature algorithm
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    98
     * @param hMACOutputLength
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    99
     * @param canonicalizationMethodURI URI representation of the
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   100
     *    Canonicalization method
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   101
     * @throws XMLSecurityException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   102
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   103
    public SignedInfo(Document doc, String signatureMethodURI,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   104
        int hMACOutputLength, String canonicalizationMethodURI)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
              throws XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   107
        super(doc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   109
        c14nMethod = XMLUtils.createElementInSignatureSpace(this._doc,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                Constants._TAG_CANONICALIZATIONMETHOD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   112
        c14nMethod.setAttributeNS(null, Constants._ATT_ALGORITHM,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   113
                                  canonicalizationMethodURI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   114
        this._constructionElement.appendChild(c14nMethod);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   115
        XMLUtils.addReturnToElement(this._constructionElement);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   116
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   117
        if (hMACOutputLength > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            this._signatureAlgorithm = new SignatureAlgorithm(this._doc,
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   119
                    signatureMethodURI, hMACOutputLength);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   120
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            this._signatureAlgorithm = new SignatureAlgorithm(this._doc,
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   122
                    signatureMethodURI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   123
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   125
        signatureMethod = this._signatureAlgorithm.getElement();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   126
        this._constructionElement.appendChild(signatureMethod);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   127
        XMLUtils.addReturnToElement(this._constructionElement);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   128
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   130
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   131
     * @param doc
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   132
     * @param signatureMethodElem
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   133
     * @param canonicalizationMethodElem
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   134
     * @throws XMLSecurityException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   135
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   136
    public SignedInfo(Document doc, Element signatureMethodElem,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   137
        Element canonicalizationMethodElem) throws XMLSecurityException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   139
        super(doc);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   140
        // Check this?
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   141
        this.c14nMethod = canonicalizationMethodElem;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   142
        this._constructionElement.appendChild(c14nMethod);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   143
        XMLUtils.addReturnToElement(this._constructionElement);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   145
        this._signatureAlgorithm =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   146
            new SignatureAlgorithm(signatureMethodElem, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   148
        signatureMethod = this._signatureAlgorithm.getElement();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   149
        this._constructionElement.appendChild(signatureMethod);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   150
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   151
        XMLUtils.addReturnToElement(this._constructionElement);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   152
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   154
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   155
     * Build a {@link SignedInfo} from an {@link Element}
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   156
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   157
     * @param element <code>SignedInfo</code>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   158
     * @param baseURI the URI of the resource where the XML instance was stored
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   159
     * @throws XMLSecurityException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   160
     * @see <A HREF="http://lists.w3.org/Archives/Public/w3c-ietf-xmldsig/2001OctDec/0033.html">Question</A>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   161
     * @see <A HREF="http://lists.w3.org/Archives/Public/w3c-ietf-xmldsig/2001OctDec/0054.html">Answer</A>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   162
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   163
    public SignedInfo(Element element, String baseURI)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
           throws XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   166
        // Parse the Reference children and Id attribute in the Manifest
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   167
        super(element, baseURI);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   169
        /* canonicalize ds:SignedInfo, reparse it into a new document
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   170
         * and replace the original not-canonicalized ds:SignedInfo by
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   171
         * the re-parsed canonicalized one.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   172
         */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   173
        c14nMethod = XMLUtils.getNextElement(element.getFirstChild());
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   174
        String c14nMethodURI = this.getCanonicalizationMethodURI();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   175
        if (!(c14nMethodURI.equals(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS) ||
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   176
              c14nMethodURI.equals(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS) ||
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   177
              c14nMethodURI.equals(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS) ||
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   178
              c14nMethodURI.equals(Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS))) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   179
            // the c14n is not a secure one and can rewrite the URIs or like
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   180
            // that reparse the SignedInfo to be sure
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   181
            try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   182
                Canonicalizer c14nizer =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   183
                Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   185
                this._c14nizedBytes =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   186
                    c14nizer.canonicalizeSubtree(this._constructionElement);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   187
                javax.xml.parsers.DocumentBuilderFactory dbf =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   188
                    javax.xml.parsers.DocumentBuilderFactory.newInstance();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   189
                dbf.setNamespaceAware(true);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 1337
diff changeset
   190
                dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 1337
diff changeset
   191
                               Boolean.TRUE);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   192
                javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 1337
diff changeset
   193
                Document newdoc =
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   194
                    db.parse(new ByteArrayInputStream(this._c14nizedBytes));
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   195
                Node imported =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   196
                    this._doc.importNode(newdoc.getDocumentElement(), true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   198
                this._constructionElement.getParentNode().replaceChild(imported,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   199
                    this._constructionElement);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   201
                this._constructionElement = (Element) imported;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   202
            } catch (ParserConfigurationException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   203
                throw new XMLSecurityException("empty", ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   204
            } catch (IOException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   205
                throw new XMLSecurityException("empty", ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   206
            } catch (SAXException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   207
                throw new XMLSecurityException("empty", ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   208
            }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   209
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   210
        signatureMethod = XMLUtils.getNextElement(c14nMethod.getNextSibling());
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   211
        this._signatureAlgorithm =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   212
            new SignatureAlgorithm(signatureMethod, this.getBaseURI());
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   213
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    * Tests core validation process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    * @return true if verification was successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    * @throws MissingResourceFailureException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    * @throws XMLSecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
   public boolean verify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
           throws MissingResourceFailureException, XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
      return super.verifyReferences(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    * Tests core validation process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    * @param followManifests defines whether the verification process has to verify referenced <CODE>ds:Manifest</CODE>s, too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    * @return true if verification was successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    * @throws MissingResourceFailureException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    * @throws XMLSecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
   public boolean verify(boolean followManifests)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
           throws MissingResourceFailureException, XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      return super.verifyReferences(followManifests);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    * Returns getCanonicalizedOctetStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    * @return the canonicalization result octedt stream of <code>SignedInfo</code> element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    * @throws InvalidCanonicalizerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    * @throws XMLSecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
   public byte[] getCanonicalizedOctetStream()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
           throws CanonicalizationException, InvalidCanonicalizerException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                 XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      if ((this._c14nizedBytes == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
              /*&& (this._state == ElementProxy.MODE_SIGN)*/) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         Canonicalizer c14nizer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         this._c14nizedBytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            c14nizer.canonicalizeSubtree(this._constructionElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      // make defensive copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      byte[] output = new byte[this._c14nizedBytes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      System.arraycopy(this._c14nizedBytes, 0, output, 0, output.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
      return output;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    *  Output the C14n stream to the give outputstream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    * @param os
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    * @throws InvalidCanonicalizerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    * @throws XMLSecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
   public void signInOctectStream(OutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
       throws CanonicalizationException, InvalidCanonicalizerException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
           XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if ((this._c14nizedBytes == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
       Canonicalizer c14nizer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
          Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
       c14nizer.setWriter(os);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
       String inclusiveNamespaces = this.getInclusiveNamespaces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
       if(inclusiveNamespaces == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        c14nizer.canonicalizeSubtree(this._constructionElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
       else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        c14nizer.canonicalizeSubtree(this._constructionElement, inclusiveNamespaces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        os.write(this._c14nizedBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        throw new RuntimeException(""+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    * Returns the Canonicalization method URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    * @return the Canonicalization method URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
   public String getCanonicalizationMethodURI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   306
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   307
     return c14nMethod.getAttributeNS(null, Constants._ATT_ALGORITHM);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    * Returns the Signature method URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    * @return the Signature method URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
   public String getSignatureMethodURI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      Element signatureElement = this.getSignatureMethodElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      if (signatureElement != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         return signatureElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    * Method getSignatureMethodElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    * @return gets The SignatureMethod Node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
   public Element getSignatureMethodElement() {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   332
           return signatureMethod;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    * Creates a SecretKey for the appropriate Mac algorithm based on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    * byte[] array password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    * @param secretKeyBytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    * @return the secret key for the SignedInfo element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
   public SecretKey createSecretKey(byte[] secretKeyBytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
      return new SecretKeySpec(secretKeyBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                               this._signatureAlgorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                  .getJCEAlgorithmString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   350
   protected SignatureAlgorithm getSignatureAlgorithm() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   351
           return _signatureAlgorithm;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   352
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    * Method getBaseLocalName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    * @inheritDoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
   public String getBaseLocalName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
      return Constants._TAG_SIGNEDINFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
   public String getInclusiveNamespaces() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   364
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   366
     String c14nMethodURI = c14nMethod.getAttributeNS(null, Constants._ATT_ALGORITHM);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     if(!(c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                        c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#WithComments"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   372
     Element inclusiveElement = XMLUtils.getNextElement(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   373
                 c14nMethod.getFirstChild());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     if(inclusiveElement != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
             String inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                         InclusiveNamespaces.ExclusiveCanonicalizationNamespace).getInclusiveNamespaces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
             return inclusiveNamespaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         catch (XMLSecurityException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
}