jdk/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXMLSignature.java
author mullan
Fri, 21 Nov 2014 15:23:36 -0500
changeset 27747 3a271dc8b758
parent 25859 3317bb8137f4
permissions -rw-r--r--
8046949: Generify the javax.xml.crypto API Reviewed-by: xuelei
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!
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
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: 18240
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: 18240
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
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: 18240
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: 18240
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: 18240
diff changeset
    12
 * with the License. You may obtain a copy of the License at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
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: 18240
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: 18240
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: 18240
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: 18240
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    21
 * under the License.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    23
/*
24970
094bfaa699c3 8046044: Fix raw and unchecked lint warnings in XML Signature Impl
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
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * (C) Copyright IBM Corp. 2003 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    34
 * $Id: DOMXMLSignature.java 1333415 2012-05-03 12:03:51Z coheigea $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
package org.jcp.xml.dsig.internal.dom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.xml.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.xml.crypto.dom.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.xml.crypto.dsig.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.xml.crypto.dsig.dom.DOMSignContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.xml.crypto.dsig.dom.DOMValidateContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.InvalidKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.Key;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    47
import java.security.Provider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.List;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    52
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
    53
import org.w3c.dom.Attr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import com.sun.org.apache.xml.internal.security.utils.Base64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * DOM-based implementation of XMLSignature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author Joyce Leung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
public final class DOMXMLSignature extends DOMStructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    implements XMLSignature {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    70
    private static java.util.logging.Logger log =
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    71
        java.util.logging.Logger.getLogger("org.jcp.xml.dsig.internal.dom");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private SignatureValue sv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private KeyInfo ki;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    75
    private List<XMLObject> objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private SignedInfo si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private Document ownerDoc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private Element localSigElem = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private Element sigElem = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private boolean validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private boolean validated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private KeySelectorResult ksr;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    83
    private HashMap<String, XMLStructure> signatureIdMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        com.sun.org.apache.xml.internal.security.Init.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Creates a <code>DOMXMLSignature</code> from the specified components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param si the <code>SignedInfo</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param ki the <code>KeyInfo</code>, or <code>null</code> if not specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param objs a list of <code>XMLObject</code>s or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *  if not specified. The list is copied to protect against subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *  modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param id an optional id (specify <code>null</code> to omit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param signatureValueId an optional id (specify <code>null</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *  omit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @throws NullPointerException if <code>si</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   102
    public DOMXMLSignature(SignedInfo si, KeyInfo ki,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   103
                           List<? extends XMLObject> objs,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   104
                           String id, String signatureValueId)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (si == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throw new NullPointerException("signedInfo cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this.si = si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.sv = new DOMSignatureValue(signatureValueId);
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   112
        List<XMLObject> tempList =
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   113
            Collections.checkedList(new ArrayList<XMLObject>(),
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   114
                                    XMLObject.class);
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   115
        if (objs != null) {
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   116
            tempList.addAll(objs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   118
        this.objects = Collections.unmodifiableList(tempList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.ki = ki;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Creates a <code>DOMXMLSignature</code> from XML.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param sigElem Signature element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @throws MarshalException if XMLSignature cannot be unmarshalled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   128
    public DOMXMLSignature(Element sigElem, XMLCryptoContext context,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   129
                           Provider provider)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   130
        throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   131
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        localSigElem = sigElem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        ownerDoc = localSigElem.getOwnerDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // get Id attribute, if specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        id = DOMUtils.getAttributeValue(localSigElem, "Id");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // unmarshal SignedInfo
19051
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   139
        Element siElem = DOMUtils.getFirstChildElement(localSigElem,
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   140
                                                       "SignedInfo");
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   141
        si = new DOMSignedInfo(siElem, context, provider);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // unmarshal SignatureValue
19051
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   144
        Element sigValElem = DOMUtils.getNextSiblingElement(siElem,
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   145
                                                            "SignatureValue");
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   146
        sv = new DOMSignatureValue(sigValElem, context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // unmarshal KeyInfo, if specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        Element nextSibling = DOMUtils.getNextSiblingElement(sigValElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (nextSibling != null && nextSibling.getLocalName().equals("KeyInfo")) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   151
            ki = new DOMKeyInfo(nextSibling, context, provider);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // unmarshal Objects, if specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (nextSibling == null) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   157
            objects = Collections.emptyList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } else {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   159
            List<XMLObject> tempObjects = new ArrayList<XMLObject>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            while (nextSibling != null) {
19051
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   161
                String name = nextSibling.getLocalName();
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   162
                if (!name.equals("Object")) {
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   163
                    throw new MarshalException("Invalid element name: " + name +
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   164
                                               ", expected KeyInfo or Object");
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   165
                }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   166
                tempObjects.add(new DOMXMLObject(nextSibling,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   167
                                                 context, provider));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            objects = Collections.unmodifiableList(tempObjects);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public String getId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public KeyInfo getKeyInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return ki;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public SignedInfo getSignedInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
24970
094bfaa699c3 8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents: 23010
diff changeset
   186
    public List<XMLObject> getObjects() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return objects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public SignatureValue getSignatureValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return sv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public KeySelectorResult getKeySelectorResult() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return ksr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   199
        throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   200
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        marshal(parent, null, dsPrefix, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void marshal(Node parent, Node nextSibling, String dsPrefix,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   205
                        DOMCryptoContext context)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   206
        throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   207
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        ownerDoc = DOMUtils.getOwnerDocument(parent);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   209
        sigElem = DOMUtils.createElement(ownerDoc, "Signature",
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   210
                                         XMLSignature.XMLNS, dsPrefix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // append xmlns attribute
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   213
        if (dsPrefix == null || dsPrefix.length() == 0) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   214
            sigElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns",
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   215
                                   XMLSignature.XMLNS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } else {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   217
            sigElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" +
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   218
                                   dsPrefix, XMLSignature.XMLNS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        // create and append SignedInfo element
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   222
        ((DOMSignedInfo)si).marshal(sigElem, dsPrefix, context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // create and append SignatureValue element
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   225
        ((DOMSignatureValue)sv).marshal(sigElem, dsPrefix, context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // create and append KeyInfo element if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (ki != null) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   229
            ((DOMKeyInfo)ki).marshal(sigElem, null, dsPrefix, context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // create and append Object elements if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        for (int i = 0, size = objects.size(); i < size; i++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   234
            ((DOMXMLObject)objects.get(i)).marshal(sigElem, dsPrefix, context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        // append Id attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        DOMUtils.setAttributeID(sigElem, "Id", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        parent.insertBefore(sigElem, nextSibling);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public boolean validate(XMLValidateContext vc)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   244
        throws XMLSignatureException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   245
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (vc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            throw new NullPointerException("validateContext is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (!(vc instanceof DOMValidateContext)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            throw new ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                ("validateContext must be of type DOMValidateContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (validated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // validate the signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        boolean sigValidity = sv.validate(vc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (!sigValidity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            validationStatus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            validated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // validate all References
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   268
        List<Reference> refs = this.si.getReferences();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        boolean validateRefs = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        for (int i = 0, size = refs.size(); validateRefs && i < size; i++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   271
            Reference ref = refs.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            boolean refValid = ref.validate(vc);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   273
            if (log.isLoggable(java.util.logging.Level.FINE)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   274
                log.log(java.util.logging.Level.FINE, "Reference[" + ref.getURI() + "] is valid: " + refValid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            validateRefs &= refValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (!validateRefs) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   279
            if (log.isLoggable(java.util.logging.Level.FINE)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   280
                log.log(java.util.logging.Level.FINE, "Couldn't validate the References");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            validationStatus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            validated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // validate Manifests, if property set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        boolean validateMans = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (Boolean.TRUE.equals(vc.getProperty
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   290
                                ("org.jcp.xml.dsig.validateManifests")))
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   291
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            for (int i=0, size=objects.size(); validateMans && i < size; i++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   293
                XMLObject xo = objects.get(i);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   294
                List<XMLStructure> content = xo.getContent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                int csize = content.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                for (int j = 0; validateMans && j < csize; j++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   297
                    XMLStructure xs = content.get(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    if (xs instanceof Manifest) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   299
                        if (log.isLoggable(java.util.logging.Level.FINE)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   300
                            log.log(java.util.logging.Level.FINE, "validating manifest");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   302
                        Manifest man = (Manifest)xs;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   303
                        List<Reference> manRefs = man.getReferences();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        int rsize = manRefs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        for (int k = 0; validateMans && k < rsize; k++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   306
                            Reference ref = manRefs.get(k);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                            boolean refValid = ref.validate(vc);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   308
                            if (log.isLoggable(java.util.logging.Level.FINE)) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   309
                                log.log(java.util.logging.Level.FINE,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   310
                                    "Manifest ref[" + ref.getURI() + "] is valid: " + refValid
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   311
                                );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            validateMans &= refValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        validationStatus = validateMans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        validated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public void sign(XMLSignContext signContext)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   326
        throws MarshalException, XMLSignatureException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   327
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (signContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            throw new NullPointerException("signContext cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   331
        DOMSignContext context = (DOMSignContext)signContext;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   332
        marshal(context.getParent(), context.getNextSibling(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                DOMUtils.getSignaturePrefix(context), context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        // generate references and signature value
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   336
        List<Reference> allReferences = new ArrayList<Reference>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        // traverse the Signature and register all objects with IDs that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        // may contain References
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   340
        signatureIdMap = new HashMap<String, XMLStructure>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        signatureIdMap.put(id, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        signatureIdMap.put(si.getId(), si);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   343
        List<Reference> refs = si.getReferences();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   344
        for (Reference ref : refs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            signatureIdMap.put(ref.getId(), ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   347
        for (XMLObject obj : objects) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            signatureIdMap.put(obj.getId(), obj);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   349
            List<XMLStructure> content = obj.getContent();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   350
            for (XMLStructure xs : content) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                if (xs instanceof Manifest) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   352
                    Manifest man = (Manifest)xs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    signatureIdMap.put(man.getId(), man);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   354
                    List<Reference> manRefs = man.getReferences();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   355
                    for (Reference ref : manRefs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                        allReferences.add(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        signatureIdMap.put(ref.getId(), ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
4506
402b248b41de 6867348: Digest Value of References inside Manifest - calculation order problem
mullan
parents: 1337
diff changeset
   362
        // always add SignedInfo references after Manifest references so
402b248b41de 6867348: Digest Value of References inside Manifest - calculation order problem
mullan
parents: 1337
diff changeset
   363
        // that Manifest reference are digested first
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   364
        allReferences.addAll(refs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // generate/digest each reference
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   367
        for (Reference ref : allReferences) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   368
            digestReference((DOMReference)ref, signContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        // do final sweep to digest any references that were skipped or missed
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   372
        for (Reference ref : allReferences) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   373
            if (((DOMReference)ref).isDigested()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   376
            ((DOMReference)ref).digest(signContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Key signingKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        KeySelectorResult ksr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        try {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   382
            ksr = signContext.getKeySelector().select(ki,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   383
                                                      KeySelector.Purpose.SIGN,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   384
                                                      si.getSignatureMethod(),
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   385
                                                      signContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            signingKey = ksr.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (signingKey == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                throw new XMLSignatureException("the keySelector did not " +
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   389
                                                "find a signing key");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } catch (KeySelectorException kse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            throw new XMLSignatureException("cannot find signing key", kse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        // calculate signature value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        try {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   397
            byte[] val = ((AbstractDOMSignatureMethod)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   398
                si.getSignatureMethod()).sign(signingKey, si, signContext);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   399
            ((DOMSignatureValue)sv).setValue(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } catch (InvalidKeyException ike) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            throw new XMLSignatureException(ike);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        this.localSigElem = sigElem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        this.ksr = ksr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   408
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (this == o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (!(o instanceof XMLSignature)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   417
        XMLSignature osig = (XMLSignature)o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        boolean idEqual =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            (id == null ? osig.getId() == null : id.equals(osig.getId()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        boolean keyInfoEqual =
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   422
            (ki == null ? osig.getKeyInfo() == null
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   423
                        : ki.equals(osig.getKeyInfo()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return (idEqual && keyInfoEqual &&
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   426
                sv.equals(osig.getSignatureValue()) &&
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   427
                si.equals(osig.getSignedInfo()) &&
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   428
                objects.equals(osig.getObjects()));
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   429
    }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   430
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   431
    @Override
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   432
    public int hashCode() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   433
        int result = 17;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   434
        if (id != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   435
            result = 31 * result + id.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   436
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   437
        if (ki != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   438
            result = 31 * result + ki.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   439
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   440
        result = 31 * result + sv.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   441
        result = 31 * result + si.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   442
        result = 31 * result + objects.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   443
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   444
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    private void digestReference(DOMReference ref, XMLSignContext signContext)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   448
        throws XMLSignatureException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   449
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (ref.isDigested()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        // check dependencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        String uri = ref.getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (Utils.sameDocumentURI(uri)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            String id = Utils.parseIdFromSameDocumentURI(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (id != null && signatureIdMap.containsKey(id)) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   458
                XMLStructure xs = signatureIdMap.get(id);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   459
                if (xs instanceof DOMReference) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   460
                    digestReference((DOMReference)xs, signContext);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   461
                } else if (xs instanceof Manifest) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   462
                    Manifest man = (Manifest)xs;
24970
094bfaa699c3 8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents: 23010
diff changeset
   463
                    List<Reference> manRefs =
094bfaa699c3 8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents: 23010
diff changeset
   464
                        DOMManifest.getManifestReferences(man);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    for (int i = 0, size = manRefs.size(); i < size; i++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   466
                        digestReference((DOMReference)manRefs.get(i),
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   467
                                        signContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            // if uri="" and there are XPath Transforms, there may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            // reference dependencies in the XPath Transform - so be on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            // the safe side, and skip and do at end in the final sweep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (uri.length() == 0) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   475
                List<Transform> transforms = ref.getTransforms();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   476
                for (Transform transform : transforms) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    String transformAlg = transform.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    if (transformAlg.equals(Transform.XPATH) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        transformAlg.equals(Transform.XPATH2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        ref.digest(signContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public class DOMSignatureValue extends DOMStructure
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   489
        implements SignatureValue
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   490
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        private String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        private byte[] value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        private String valueBase64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        private Element sigValueElem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        private boolean validated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        private boolean validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        DOMSignatureValue(String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   502
        DOMSignatureValue(Element sigValueElem, XMLCryptoContext context)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   503
            throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   504
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                // base64 decode signatureValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                value = Base64.decode(sigValueElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            } catch (Base64DecodingException bde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                throw new MarshalException(bde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   512
            Attr attr = sigValueElem.getAttributeNodeNS(null, "Id");
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   513
            if (attr != null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   514
                id = attr.getValue();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   515
                sigValueElem.setIdAttributeNode(attr, true);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   516
            } else {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   517
                id = null;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   518
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            this.sigValueElem = sigValueElem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        public String getId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        public byte[] getValue() {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 19051
diff changeset
   527
            return (value == null) ? null : value.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        public boolean validate(XMLValidateContext validateContext)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   531
            throws XMLSignatureException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   532
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            if (validateContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                throw new NullPointerException("context cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (validated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                return validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            // get validating key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            SignatureMethod sm = si.getSignatureMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            Key validationKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            KeySelectorResult ksResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                ksResult = validateContext.getKeySelector().select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    (ki, KeySelector.Purpose.VERIFY, sm, validateContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                validationKey = ksResult.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                if (validationKey == null) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   550
                    throw new XMLSignatureException("the keyselector did not " +
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   551
                                                    "find a validation key");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            } catch (KeySelectorException kse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                throw new XMLSignatureException("cannot find validation " +
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   555
                                                "key", kse);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            // canonicalize SignedInfo and verify signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            try {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   560
                validationStatus = ((AbstractDOMSignatureMethod)sm).verify
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   561
                    (validationKey, si, value, validateContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                throw new XMLSignatureException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            validated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            ksr = ksResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return validationStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   571
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            if (this == o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if (!(o instanceof SignatureValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   580
            SignatureValue osv = (SignatureValue)o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            boolean idEqual =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                (id == null ? osv.getId() == null : id.equals(osv.getId()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            //XXX compare signature values?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            return idEqual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   589
        @Override
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   590
        public int hashCode() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   591
            int result = 17;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   592
            if (id != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   593
                result = 31 * result + id.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   594
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   596
            return result;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   597
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   598
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   599
        public void marshal(Node parent, String dsPrefix,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   600
                            DOMCryptoContext context)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   601
            throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   602
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            // create SignatureValue element
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   604
            sigValueElem = DOMUtils.createElement(ownerDoc, "SignatureValue",
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   605
                                                  XMLSignature.XMLNS, dsPrefix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (valueBase64 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            // append Id attribute, if specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            DOMUtils.setAttributeID(sigValueElem, "Id", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            parent.appendChild(sigValueElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        void setValue(byte[] value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            valueBase64 = Base64.encode(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
}