author | mullan |
Fri, 21 Nov 2014 15:23:36 -0500 | |
changeset 27747 | 3a271dc8b758 |
parent 25859 | 3317bb8137f4 |
child 40551 | 05eba5515cbb |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1337 | 2 |
* reserved comment block |
3 |
* DO NOT REMOVE OR ALTER! |
|
2 | 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 |
1337 | 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 |
1337 | 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. |
1337 | 22 |
*/ |
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 | 25 |
*/ |
26 |
/* |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
27 |
* $Id: DOMSignedInfo.java 1333415 2012-05-03 12:03:51Z coheigea $ |
2 | 28 |
*/ |
29 |
package org.jcp.xml.dsig.internal.dom; |
|
30 |
||
31 |
import javax.xml.crypto.*; |
|
32 |
import javax.xml.crypto.dom.DOMCryptoContext; |
|
33 |
import javax.xml.crypto.dsig.*; |
|
34 |
||
35 |
import java.io.ByteArrayInputStream; |
|
36 |
import java.io.ByteArrayOutputStream; |
|
37 |
import java.io.InputStream; |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
38 |
import java.io.OutputStream; |
2 | 39 |
import java.io.IOException; |
1337 | 40 |
import java.security.Provider; |
2 | 41 |
import java.util.*; |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
42 |
|
2 | 43 |
import org.w3c.dom.Document; |
44 |
import org.w3c.dom.Element; |
|
45 |
import org.w3c.dom.Node; |
|
46 |
||
47 |
import com.sun.org.apache.xml.internal.security.utils.Base64; |
|
18240 | 48 |
import com.sun.org.apache.xml.internal.security.utils.Constants; |
2 | 49 |
import com.sun.org.apache.xml.internal.security.utils.UnsyncBufferedOutputStream; |
50 |
||
51 |
/** |
|
52 |
* DOM-based implementation of SignedInfo. |
|
53 |
* |
|
54 |
* @author Sean Mullan |
|
55 |
*/ |
|
56 |
public final class DOMSignedInfo extends DOMStructure implements SignedInfo { |
|
57 |
||
18240 | 58 |
/** |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
59 |
* The maximum number of references per Manifest, if secure validation is enabled. |
18240 | 60 |
*/ |
61 |
public static final int MAXIMUM_REFERENCE_COUNT = 30; |
|
62 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
63 |
private static java.util.logging.Logger log = |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
64 |
java.util.logging.Logger.getLogger("org.jcp.xml.dsig.internal.dom"); |
18240 | 65 |
|
66 |
/** Signature - NOT Recommended RSAwithMD5 */ |
|
67 |
private static final String ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5 = |
|
68 |
Constants.MoreAlgorithmsSpecNS + "rsa-md5"; |
|
69 |
||
70 |
/** HMAC - NOT Recommended HMAC-MD5 */ |
|
71 |
private static final String ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5 = |
|
72 |
Constants.MoreAlgorithmsSpecNS + "hmac-md5"; |
|
73 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
74 |
private List<Reference> references; |
2 | 75 |
private CanonicalizationMethod canonicalizationMethod; |
76 |
private SignatureMethod signatureMethod; |
|
77 |
private String id; |
|
78 |
private Document ownerDoc; |
|
79 |
private Element localSiElem; |
|
80 |
private InputStream canonData; |
|
81 |
||
82 |
/** |
|
83 |
* Creates a <code>DOMSignedInfo</code> from the specified parameters. Use |
|
84 |
* this constructor when the <code>Id</code> is not specified. |
|
85 |
* |
|
86 |
* @param cm the canonicalization method |
|
87 |
* @param sm the signature method |
|
88 |
* @param references the list of references. The list is copied. |
|
89 |
* @throws NullPointerException if |
|
90 |
* <code>cm</code>, <code>sm</code>, or <code>references</code> is |
|
91 |
* <code>null</code> |
|
92 |
* @throws IllegalArgumentException if <code>references</code> is empty |
|
93 |
* @throws ClassCastException if any of the references are not of |
|
94 |
* type <code>Reference</code> |
|
95 |
*/ |
|
96 |
public DOMSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
97 |
List<? extends Reference> references) { |
2 | 98 |
if (cm == null || sm == null || references == null) { |
99 |
throw new NullPointerException(); |
|
100 |
} |
|
101 |
this.canonicalizationMethod = cm; |
|
102 |
this.signatureMethod = sm; |
|
27747 | 103 |
List<Reference> tempList = |
104 |
Collections.checkedList(new ArrayList<Reference>(), |
|
105 |
Reference.class); |
|
106 |
tempList.addAll(references); |
|
107 |
if (tempList.isEmpty()) { |
|
108 |
throw new IllegalArgumentException("references cannot be empty"); |
|
2 | 109 |
} |
27747 | 110 |
this.references = Collections.unmodifiableList(tempList); |
2 | 111 |
} |
112 |
||
113 |
/** |
|
114 |
* Creates a <code>DOMSignedInfo</code> from the specified parameters. |
|
115 |
* |
|
116 |
* @param cm the canonicalization method |
|
117 |
* @param sm the signature method |
|
118 |
* @param references the list of references. The list is copied. |
|
119 |
* @param id an optional identifer that will allow this |
|
120 |
* <code>SignedInfo</code> to be referenced by other signatures and |
|
121 |
* objects |
|
122 |
* @throws NullPointerException if <code>cm</code>, <code>sm</code>, |
|
123 |
* or <code>references</code> is <code>null</code> |
|
124 |
* @throws IllegalArgumentException if <code>references</code> is empty |
|
125 |
* @throws ClassCastException if any of the references are not of |
|
126 |
* type <code>Reference</code> |
|
127 |
*/ |
|
128 |
public DOMSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
129 |
List<? extends Reference> references, String id) { |
2 | 130 |
this(cm, sm, references); |
131 |
this.id = id; |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* Creates a <code>DOMSignedInfo</code> from an element. |
|
136 |
* |
|
137 |
* @param siElem a SignedInfo element |
|
138 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
139 |
public DOMSignedInfo(Element siElem, XMLCryptoContext context, Provider provider) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
140 |
throws MarshalException { |
2 | 141 |
localSiElem = siElem; |
142 |
ownerDoc = siElem.getOwnerDocument(); |
|
143 |
||
144 |
// get Id attribute, if specified |
|
145 |
id = DOMUtils.getAttributeValue(siElem, "Id"); |
|
146 |
||
147 |
// unmarshal CanonicalizationMethod |
|
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
148 |
Element cmElem = DOMUtils.getFirstChildElement(siElem, |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
149 |
"CanonicalizationMethod"); |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
150 |
canonicalizationMethod = new DOMCanonicalizationMethod(cmElem, context, |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
151 |
provider); |
2 | 152 |
|
153 |
// unmarshal SignatureMethod |
|
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
154 |
Element smElem = DOMUtils.getNextSiblingElement(cmElem, |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
155 |
"SignatureMethod"); |
2 | 156 |
signatureMethod = DOMSignatureMethod.unmarshal(smElem); |
157 |
||
18240 | 158 |
boolean secVal = Utils.secureValidation(context); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
159 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
160 |
String signatureMethodAlgorithm = signatureMethod.getAlgorithm(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
161 |
if (secVal && ((ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5.equals(signatureMethodAlgorithm) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
162 |
|| ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5.equals(signatureMethodAlgorithm)))) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
163 |
throw new MarshalException( |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
164 |
"It is forbidden to use algorithm " + signatureMethod + " when secure validation is enabled" |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
165 |
); |
18240 | 166 |
} |
167 |
||
2 | 168 |
// unmarshal References |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
169 |
ArrayList<Reference> refList = new ArrayList<Reference>(5); |
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
170 |
Element refElem = DOMUtils.getNextSiblingElement(smElem, "Reference"); |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
171 |
refList.add(new DOMReference(refElem, context, provider)); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
172 |
|
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
173 |
refElem = DOMUtils.getNextSiblingElement(refElem); |
2 | 174 |
while (refElem != null) { |
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
175 |
String name = refElem.getLocalName(); |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
176 |
if (!name.equals("Reference")) { |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
177 |
throw new MarshalException("Invalid element name: " + |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
178 |
name + ", expected Reference"); |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
179 |
} |
1337 | 180 |
refList.add(new DOMReference(refElem, context, provider)); |
18240 | 181 |
|
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
182 |
if (secVal && (refList.size() > MAXIMUM_REFERENCE_COUNT)) { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
183 |
String error = "A maxiumum of " + MAXIMUM_REFERENCE_COUNT + " " |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
184 |
+ "references per Manifest are allowed with secure validation"; |
18240 | 185 |
throw new MarshalException(error); |
186 |
} |
|
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
187 |
refElem = DOMUtils.getNextSiblingElement(refElem); |
2 | 188 |
} |
189 |
references = Collections.unmodifiableList(refList); |
|
190 |
} |
|
191 |
||
192 |
public CanonicalizationMethod getCanonicalizationMethod() { |
|
193 |
return canonicalizationMethod; |
|
194 |
} |
|
195 |
||
196 |
public SignatureMethod getSignatureMethod() { |
|
197 |
return signatureMethod; |
|
198 |
} |
|
199 |
||
200 |
public String getId() { |
|
201 |
return id; |
|
202 |
} |
|
203 |
||
24970
094bfaa699c3
8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents:
23010
diff
changeset
|
204 |
public List<Reference> getReferences() { |
2 | 205 |
return references; |
206 |
} |
|
207 |
||
208 |
public InputStream getCanonicalizedData() { |
|
209 |
return canonData; |
|
210 |
} |
|
211 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
212 |
public void canonicalize(XMLCryptoContext context, ByteArrayOutputStream bos) |
2 | 213 |
throws XMLSignatureException { |
214 |
if (context == null) { |
|
215 |
throw new NullPointerException("context cannot be null"); |
|
216 |
} |
|
217 |
||
218 |
OutputStream os = new UnsyncBufferedOutputStream(bos); |
|
25391
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
219 |
|
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
220 |
DOMSubTreeData subTree = new DOMSubTreeData(localSiElem, true); |
2 | 221 |
try { |
25391
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
222 |
((DOMCanonicalizationMethod) |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
223 |
canonicalizationMethod).canonicalize(subTree, context, os); |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
224 |
} catch (TransformException te) { |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
225 |
throw new XMLSignatureException(te); |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
226 |
} |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
227 |
|
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
228 |
try { |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
229 |
os.flush(); |
2 | 230 |
} catch (IOException e) { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
231 |
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
|
232 |
log.log(java.util.logging.Level.FINE, e.getMessage(), e); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
233 |
} |
2 | 234 |
// Impossible |
235 |
} |
|
236 |
||
237 |
byte[] signedInfoBytes = bos.toByteArray(); |
|
238 |
||
239 |
// this whole block should only be done if logging is enabled |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
240 |
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
|
241 |
log.log(java.util.logging.Level.FINE, "Canonicalized SignedInfo:"); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
242 |
StringBuilder sb = new StringBuilder(signedInfoBytes.length); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
243 |
for (int i = 0; i < signedInfoBytes.length; i++) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
244 |
sb.append((char)signedInfoBytes[i]); |
1337 | 245 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
246 |
log.log(java.util.logging.Level.FINE, sb.toString()); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
247 |
log.log(java.util.logging.Level.FINE, "Data to be signed/verified:" + Base64.encode(signedInfoBytes)); |
2 | 248 |
} |
249 |
||
250 |
this.canonData = new ByteArrayInputStream(signedInfoBytes); |
|
25391
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
251 |
|
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
252 |
try { |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
253 |
os.close(); |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
254 |
} catch (IOException e) { |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
255 |
if (log.isLoggable(java.util.logging.Level.FINE)) { |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
256 |
log.log(java.util.logging.Level.FINE, e.getMessage(), e); |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
257 |
} |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
258 |
// Impossible |
f5e21d481e41
8049244: XML Signature performance issue caused by unbuffered signature data
mullan
parents:
24970
diff
changeset
|
259 |
} |
2 | 260 |
} |
261 |
||
262 |
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
|
263 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
264 |
{ |
2 | 265 |
ownerDoc = DOMUtils.getOwnerDocument(parent); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
266 |
Element siElem = DOMUtils.createElement(ownerDoc, "SignedInfo", |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
267 |
XMLSignature.XMLNS, dsPrefix); |
2 | 268 |
|
269 |
// create and append CanonicalizationMethod element |
|
270 |
DOMCanonicalizationMethod dcm = |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
271 |
(DOMCanonicalizationMethod)canonicalizationMethod; |
2 | 272 |
dcm.marshal(siElem, dsPrefix, context); |
273 |
||
274 |
// create and append SignatureMethod element |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
275 |
((DOMStructure)signatureMethod).marshal(siElem, dsPrefix, context); |
2 | 276 |
|
277 |
// create and append Reference elements |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
278 |
for (Reference reference : references) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
279 |
((DOMReference)reference).marshal(siElem, dsPrefix, context); |
2 | 280 |
} |
281 |
||
282 |
// append Id attribute |
|
283 |
DOMUtils.setAttributeID(siElem, "Id", id); |
|
284 |
||
285 |
parent.appendChild(siElem); |
|
286 |
localSiElem = siElem; |
|
287 |
} |
|
288 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
289 |
@Override |
2 | 290 |
public boolean equals(Object o) { |
291 |
if (this == o) { |
|
292 |
return true; |
|
293 |
} |
|
294 |
||
295 |
if (!(o instanceof SignedInfo)) { |
|
296 |
return false; |
|
297 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
298 |
SignedInfo osi = (SignedInfo)o; |
2 | 299 |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
300 |
boolean idEqual = (id == null ? osi.getId() == null |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
301 |
: id.equals(osi.getId())); |
2 | 302 |
|
303 |
return (canonicalizationMethod.equals(osi.getCanonicalizationMethod()) |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
304 |
&& signatureMethod.equals(osi.getSignatureMethod()) && |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
305 |
references.equals(osi.getReferences()) && idEqual); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
306 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
307 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
308 |
@Override |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
309 |
public int hashCode() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
310 |
int result = 17; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
311 |
if (id != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
312 |
result = 31 * result + id.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
313 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
314 |
result = 31 * result + canonicalizationMethod.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
315 |
result = 31 * result + signatureMethod.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
316 |
result = 31 * result + references.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
317 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
318 |
return result; |
2 | 319 |
} |
320 |
} |