author | weijun |
Thu, 10 Oct 2019 17:36:38 +0300 | |
changeset 59240 | b3116877866f |
parent 50614 | 3810c9a2efa1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
5 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
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:
18266
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:
18266
diff
changeset
|
8 |
* distributed with this work for additional information |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
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:
18266
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:
18266
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:
18266
diff
changeset
|
12 |
* with the License. You may obtain a copy of the License at |
2 | 13 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
2 | 15 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
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:
18266
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:
18266
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:
18266
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:
18266
diff
changeset
|
20 |
* specific language governing permissions and limitations |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
21 |
* under the License. |
2 | 22 |
*/ |
23 |
package com.sun.org.apache.xml.internal.security.signature; |
|
24 |
||
25 |
import java.io.ByteArrayInputStream; |
|
26 |
import java.io.ByteArrayOutputStream; |
|
27 |
import java.io.IOException; |
|
28 |
import java.io.InputStream; |
|
29 |
import java.io.OutputStream; |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
30 |
import java.nio.charset.StandardCharsets; |
2 | 31 |
import java.util.ArrayList; |
18266
26e69da689b9
8010714: XML DSig API allows a RetrievalMethod to reference another RetrievalMethod
mullan
parents:
18240
diff
changeset
|
32 |
import java.util.LinkedHashSet; |
2 | 33 |
import java.util.List; |
34 |
import java.util.Set; |
|
35 |
||
36 |
import javax.xml.parsers.ParserConfigurationException; |
|
37 |
||
38 |
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
39 |
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_OmitComments; |
2 | 40 |
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments; |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
41 |
import com.sun.org.apache.xml.internal.security.c14n.implementations.CanonicalizerBase; |
2 | 42 |
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityRuntimeException; |
43 |
import com.sun.org.apache.xml.internal.security.utils.JavaUtils; |
|
44 |
import com.sun.org.apache.xml.internal.security.utils.XMLUtils; |
|
45 |
import org.w3c.dom.Document; |
|
46 |
import org.w3c.dom.Node; |
|
47 |
import org.xml.sax.SAXException; |
|
48 |
||
49 |
/** |
|
50 |
* Class XMLSignatureInput |
|
51 |
* |
|
52 |
* $todo$ check whether an XMLSignatureInput can be _both_, octet stream _and_ node set? |
|
53 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
54 |
public class XMLSignatureInput { |
1337 | 55 |
/* |
2 | 56 |
* The XMLSignature Input can be either: |
57 |
* A byteArray like with/or without InputStream. |
|
1337 | 58 |
* Or a nodeSet like defined either: |
59 |
* * as a collection of nodes |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
60 |
* * or as subnode excluding or not comments and excluding or |
1337 | 61 |
* not other nodes. |
62 |
*/ |
|
2 | 63 |
|
1337 | 64 |
/** |
65 |
* Some InputStreams do not support the {@link java.io.InputStream#reset} |
|
66 |
* method, so we read it in completely and work on our Proxy. |
|
67 |
*/ |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
68 |
private InputStream inputOctetStreamProxy; |
1337 | 69 |
/** |
70 |
* The original NodeSet for this XMLSignatureInput |
|
71 |
*/ |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
72 |
private Set<Node> inputNodeSet; |
1337 | 73 |
/** |
74 |
* The original Element |
|
75 |
*/ |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
76 |
private Node subNode; |
1337 | 77 |
/** |
78 |
* Exclude Node *for enveloped transformations* |
|
79 |
*/ |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
80 |
private Node excludeNode; |
1337 | 81 |
/** |
82 |
* |
|
83 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
84 |
private boolean excludeComments = false; |
2 | 85 |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
86 |
private boolean isNodeSet = false; |
1337 | 87 |
/** |
88 |
* A cached bytes |
|
89 |
*/ |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
90 |
private byte[] bytes; |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
91 |
private boolean secureValidation; |
1337 | 92 |
|
93 |
/** |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
94 |
* Some Transforms may require explicit MIME type, charset (IANA registered |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
95 |
* "character set"), or other such information concerning the data they are |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
96 |
* receiving from an earlier Transform or the source data, although no |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
97 |
* Transform algorithm specified in this document needs such explicit |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
98 |
* information. Such data characteristics are provided as parameters to the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
99 |
* Transform algorithm and should be described in the specification for the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
100 |
* algorithm. |
1337 | 101 |
*/ |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
102 |
private String mimeType; |
2 | 103 |
|
1337 | 104 |
/** |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
105 |
* Field sourceURI |
1337 | 106 |
*/ |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
107 |
private String sourceURI; |
1337 | 108 |
|
109 |
/** |
|
110 |
* Node Filter list. |
|
111 |
*/ |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
112 |
private List<NodeFilter> nodeFilters = new ArrayList<>(); |
2 | 113 |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
114 |
private boolean needsToBeExpanded = false; |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
115 |
private OutputStream outputStream; |
2 | 116 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
117 |
/** |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
118 |
* Pre-calculated digest value of the object in base64. |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
119 |
*/ |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
120 |
private String preCalculatedDigest; |
2 | 121 |
|
1337 | 122 |
/** |
123 |
* Construct a XMLSignatureInput from an octet array. |
|
124 |
* <p> |
|
125 |
* This is a comfort method, which internally converts the byte[] array into |
|
126 |
* an InputStream |
|
127 |
* <p>NOTE: no defensive copy</p> |
|
128 |
* @param inputOctets an octet array which including XML document or node |
|
129 |
*/ |
|
130 |
public XMLSignatureInput(byte[] inputOctets) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
131 |
// NO defensive copy |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
132 |
this.bytes = inputOctets; |
1337 | 133 |
} |
2 | 134 |
|
1337 | 135 |
/** |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
136 |
* Constructs a {@code XMLSignatureInput} from an octet stream. The |
1337 | 137 |
* stream is directly read. |
138 |
* |
|
139 |
* @param inputOctetStream |
|
140 |
*/ |
|
141 |
public XMLSignatureInput(InputStream inputOctetStream) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
142 |
this.inputOctetStreamProxy = inputOctetStream; |
1337 | 143 |
} |
2 | 144 |
|
1337 | 145 |
/** |
146 |
* Construct a XMLSignatureInput from a subtree rooted by rootNode. This |
|
147 |
* method included the node and <I>all</I> his descendants in the output. |
|
148 |
* |
|
149 |
* @param rootNode |
|
150 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
151 |
public XMLSignatureInput(Node rootNode) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
152 |
this.subNode = rootNode; |
1337 | 153 |
} |
2 | 154 |
|
1337 | 155 |
/** |
156 |
* Constructor XMLSignatureInput |
|
157 |
* |
|
158 |
* @param inputNodeSet |
|
159 |
*/ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
160 |
public XMLSignatureInput(Set<Node> inputNodeSet) { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
161 |
this.inputNodeSet = inputNodeSet; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
162 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
163 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
164 |
/** |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
165 |
* Construct a {@code XMLSignatureInput} from a known digest value in Base64. |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
166 |
* This makes it possible to compare the element digest with the provided digest value. |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
167 |
* @param preCalculatedDigest digest value in base64. |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
168 |
*/ |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
169 |
public XMLSignatureInput(String preCalculatedDigest) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
170 |
this.preCalculatedDigest = preCalculatedDigest; |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
171 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
172 |
|
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
173 |
/** |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
174 |
* Check if the structure needs to be expanded. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
175 |
* @return true if so. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
176 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
177 |
public boolean isNeedsToBeExpanded() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
178 |
return needsToBeExpanded; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
179 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
180 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
181 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
182 |
* Set if the structure needs to be expanded. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
183 |
* @param needsToBeExpanded true if so. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
184 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
185 |
public void setNeedsToBeExpanded(boolean needsToBeExpanded) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
186 |
this.needsToBeExpanded = needsToBeExpanded; |
1337 | 187 |
} |
2 | 188 |
|
1337 | 189 |
/** |
190 |
* Returns the node set from input which was specified as the parameter of |
|
191 |
* {@link XMLSignatureInput} constructor |
|
192 |
* |
|
193 |
* @return the node set |
|
194 |
* @throws SAXException |
|
195 |
* @throws IOException |
|
196 |
* @throws ParserConfigurationException |
|
197 |
* @throws CanonicalizationException |
|
198 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
199 |
public Set<Node> getNodeSet() throws CanonicalizationException, ParserConfigurationException, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
200 |
IOException, SAXException { |
1337 | 201 |
return getNodeSet(false); |
202 |
} |
|
203 |
||
204 |
/** |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
205 |
* Get the Input NodeSet. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
206 |
* @return the Input NodeSet. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
207 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
208 |
public Set<Node> getInputNodeSet() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
209 |
return inputNodeSet; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
210 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
211 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
212 |
/** |
1337 | 213 |
* Returns the node set from input which was specified as the parameter of |
214 |
* {@link XMLSignatureInput} constructor |
|
215 |
* @param circumvent |
|
216 |
* |
|
217 |
* @return the node set |
|
218 |
* @throws SAXException |
|
219 |
* @throws IOException |
|
220 |
* @throws ParserConfigurationException |
|
221 |
* @throws CanonicalizationException |
|
222 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
223 |
public Set<Node> getNodeSet(boolean circumvent) throws ParserConfigurationException, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
224 |
IOException, SAXException, CanonicalizationException { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
225 |
if (inputNodeSet != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
226 |
return inputNodeSet; |
1337 | 227 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
228 |
if (inputOctetStreamProxy == null && subNode != null) { |
1337 | 229 |
if (circumvent) { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
230 |
XMLUtils.circumventBug2650(XMLUtils.getOwnerDocument(subNode)); |
2 | 231 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
232 |
inputNodeSet = new LinkedHashSet<Node>(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
233 |
XMLUtils.getSet(subNode, inputNodeSet, excludeNode, excludeComments); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
234 |
return inputNodeSet; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
235 |
} else if (isOctetStream()) { |
1337 | 236 |
convertToNodes(); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
237 |
Set<Node> result = new LinkedHashSet<Node>(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
238 |
XMLUtils.getSet(subNode, result, null, false); |
2 | 239 |
return result; |
1337 | 240 |
} |
2 | 241 |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
242 |
throw new RuntimeException("getNodeSet() called but no input data present"); |
1337 | 243 |
} |
2 | 244 |
|
1337 | 245 |
/** |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
246 |
* Returns the Octet stream(byte Stream) from input which was specified as |
1337 | 247 |
* the parameter of {@link XMLSignatureInput} constructor |
248 |
* |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
249 |
* @return the Octet stream(byte Stream) from input which was specified as |
1337 | 250 |
* the parameter of {@link XMLSignatureInput} constructor |
251 |
* @throws IOException |
|
252 |
*/ |
|
253 |
public InputStream getOctetStream() throws IOException { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
254 |
if (inputOctetStreamProxy != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
255 |
return inputOctetStreamProxy; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
256 |
} |
2 | 257 |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
258 |
if (bytes != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
259 |
inputOctetStreamProxy = new ByteArrayInputStream(bytes); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
260 |
return inputOctetStreamProxy; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
261 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
262 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
263 |
return null; |
1337 | 264 |
} |
2 | 265 |
|
1337 | 266 |
/** |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
267 |
* @return real octet stream |
2 | 268 |
*/ |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
269 |
public InputStream getOctetStreamReal() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
270 |
return inputOctetStreamProxy; |
1337 | 271 |
} |
272 |
||
273 |
/** |
|
274 |
* Returns the byte array from input which was specified as the parameter of |
|
275 |
* {@link XMLSignatureInput} constructor |
|
276 |
* |
|
277 |
* @return the byte[] from input which was specified as the parameter of |
|
278 |
* {@link XMLSignatureInput} constructor |
|
279 |
* |
|
280 |
* @throws CanonicalizationException |
|
281 |
* @throws IOException |
|
282 |
*/ |
|
283 |
public byte[] getBytes() throws IOException, CanonicalizationException { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
284 |
byte[] inputBytes = getBytesFromInputStream(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
285 |
if (inputBytes != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
286 |
return inputBytes; |
1337 | 287 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
288 |
Canonicalizer20010315OmitComments c14nizer = new Canonicalizer20010315OmitComments(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
289 |
bytes = c14nizer.engineCanonicalize(this); |
2 | 290 |
return bytes; |
1337 | 291 |
} |
2 | 292 |
|
1337 | 293 |
/** |
294 |
* Determines if the object has been set up with a Node set |
|
295 |
* |
|
296 |
* @return true if the object has been set up with a Node set |
|
297 |
*/ |
|
298 |
public boolean isNodeSet() { |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
299 |
return inputOctetStreamProxy == null && inputNodeSet != null || isNodeSet; |
1337 | 300 |
} |
301 |
||
302 |
/** |
|
303 |
* Determines if the object has been set up with an Element |
|
304 |
* |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
305 |
* @return true if the object has been set up with an Element |
1337 | 306 |
*/ |
307 |
public boolean isElement() { |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
308 |
return inputOctetStreamProxy == null && subNode != null |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
309 |
&& inputNodeSet == null && !isNodeSet; |
1337 | 310 |
} |
2 | 311 |
|
1337 | 312 |
/** |
313 |
* Determines if the object has been set up with an octet stream |
|
314 |
* |
|
315 |
* @return true if the object has been set up with an octet stream |
|
316 |
*/ |
|
317 |
public boolean isOctetStream() { |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
318 |
return (inputOctetStreamProxy != null || bytes != null) |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
319 |
&& inputNodeSet == null && subNode == null; |
1337 | 320 |
} |
2 | 321 |
|
1337 | 322 |
/** |
323 |
* Determines if {@link #setOutputStream} has been called with a |
|
324 |
* non-null OutputStream. |
|
325 |
* |
|
326 |
* @return true if {@link #setOutputStream} has been called with a |
|
327 |
* non-null OutputStream |
|
328 |
*/ |
|
329 |
public boolean isOutputStreamSet() { |
|
330 |
return outputStream != null; |
|
331 |
} |
|
332 |
||
333 |
/** |
|
334 |
* Determines if the object has been set up with a ByteArray |
|
335 |
* |
|
336 |
* @return true is the object has been set up with an octet stream |
|
337 |
*/ |
|
338 |
public boolean isByteArray() { |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
339 |
return bytes != null && this.inputNodeSet == null && subNode == null; |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
340 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
341 |
|
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
342 |
/** |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
343 |
* Determines if the object has been set up with a pre-calculated digest. |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
344 |
* @return |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
345 |
*/ |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
346 |
public boolean isPreCalculatedDigest() { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
347 |
return preCalculatedDigest != null; |
1337 | 348 |
} |
2 | 349 |
|
1337 | 350 |
/** |
351 |
* Is the object correctly set up? |
|
352 |
* |
|
353 |
* @return true if the object has been set up correctly |
|
354 |
*/ |
|
355 |
public boolean isInitialized() { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
356 |
return isOctetStream() || isNodeSet(); |
1337 | 357 |
} |
2 | 358 |
|
1337 | 359 |
/** |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
360 |
* Returns mimeType |
1337 | 361 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
362 |
* @return mimeType |
1337 | 363 |
*/ |
364 |
public String getMIMEType() { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
365 |
return mimeType; |
1337 | 366 |
} |
2 | 367 |
|
1337 | 368 |
/** |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
369 |
* Sets mimeType |
1337 | 370 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
371 |
* @param mimeType |
1337 | 372 |
*/ |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
373 |
public void setMIMEType(String mimeType) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
374 |
this.mimeType = mimeType; |
1337 | 375 |
} |
2 | 376 |
|
1337 | 377 |
/** |
378 |
* Return SourceURI |
|
379 |
* |
|
380 |
* @return SourceURI |
|
381 |
*/ |
|
382 |
public String getSourceURI() { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
383 |
return sourceURI; |
1337 | 384 |
} |
2 | 385 |
|
1337 | 386 |
/** |
387 |
* Sets SourceURI |
|
388 |
* |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
389 |
* @param sourceURI |
1337 | 390 |
*/ |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
391 |
public void setSourceURI(String sourceURI) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
392 |
this.sourceURI = sourceURI; |
1337 | 393 |
} |
2 | 394 |
|
1337 | 395 |
/** |
396 |
* Method toString |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
397 |
* {@inheritDoc} |
1337 | 398 |
*/ |
399 |
public String toString() { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
400 |
if (isNodeSet()) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
401 |
return "XMLSignatureInput/NodeSet/" + inputNodeSet.size() |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
402 |
+ " nodes/" + getSourceURI(); |
1337 | 403 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
404 |
if (isElement()) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
405 |
return "XMLSignatureInput/Element/" + subNode |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
406 |
+ " exclude "+ excludeNode + " comments:" |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
407 |
+ excludeComments +"/" + getSourceURI(); |
1337 | 408 |
} |
409 |
try { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
410 |
return "XMLSignatureInput/OctetStream/" + getBytes().length |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
411 |
+ " octets/" + getSourceURI(); |
1337 | 412 |
} catch (IOException iex) { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
413 |
return "XMLSignatureInput/OctetStream//" + getSourceURI(); |
1337 | 414 |
} catch (CanonicalizationException cex) { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
415 |
return "XMLSignatureInput/OctetStream//" + getSourceURI(); |
1337 | 416 |
} |
417 |
} |
|
2 | 418 |
|
1337 | 419 |
/** |
420 |
* Method getHTMLRepresentation |
|
421 |
* |
|
422 |
* @throws XMLSignatureException |
|
423 |
* @return The HTML representation for this XMLSignature |
|
424 |
*/ |
|
425 |
public String getHTMLRepresentation() throws XMLSignatureException { |
|
426 |
XMLSignatureInputDebugger db = new XMLSignatureInputDebugger(this); |
|
427 |
return db.getHTMLRepresentation(); |
|
428 |
} |
|
429 |
||
430 |
/** |
|
431 |
* Method getHTMLRepresentation |
|
432 |
* |
|
433 |
* @param inclusiveNamespaces |
|
434 |
* @throws XMLSignatureException |
|
435 |
* @return The HTML representation for this XMLSignature |
|
436 |
*/ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
437 |
public String getHTMLRepresentation(Set<String> inclusiveNamespaces) |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
438 |
throws XMLSignatureException { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
439 |
XMLSignatureInputDebugger db = |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
440 |
new XMLSignatureInputDebugger(this, inclusiveNamespaces); |
1337 | 441 |
return db.getHTMLRepresentation(); |
442 |
} |
|
2 | 443 |
|
1337 | 444 |
/** |
445 |
* Gets the exclude node of this XMLSignatureInput |
|
446 |
* @return Returns the excludeNode. |
|
447 |
*/ |
|
2 | 448 |
public Node getExcludeNode() { |
1337 | 449 |
return excludeNode; |
2 | 450 |
} |
451 |
||
452 |
/** |
|
453 |
* Sets the exclude node of this XMLSignatureInput |
|
454 |
* @param excludeNode The excludeNode to set. |
|
455 |
*/ |
|
1337 | 456 |
public void setExcludeNode(Node excludeNode) { |
457 |
this.excludeNode = excludeNode; |
|
458 |
} |
|
2 | 459 |
|
1337 | 460 |
/** |
461 |
* Gets the node of this XMLSignatureInput |
|
462 |
* @return The excludeNode set. |
|
463 |
*/ |
|
464 |
public Node getSubNode() { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
465 |
return subNode; |
1337 | 466 |
} |
467 |
||
468 |
/** |
|
469 |
* @return Returns the excludeComments. |
|
470 |
*/ |
|
471 |
public boolean isExcludeComments() { |
|
2 | 472 |
return excludeComments; |
1337 | 473 |
} |
474 |
||
475 |
/** |
|
476 |
* @param excludeComments The excludeComments to set. |
|
477 |
*/ |
|
478 |
public void setExcludeComments(boolean excludeComments) { |
|
2 | 479 |
this.excludeComments = excludeComments; |
1337 | 480 |
} |
2 | 481 |
|
1337 | 482 |
/** |
483 |
* @param diOs |
|
484 |
* @throws IOException |
|
485 |
* @throws CanonicalizationException |
|
486 |
*/ |
|
487 |
public void updateOutputStream(OutputStream diOs) |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
488 |
throws CanonicalizationException, IOException { |
1337 | 489 |
updateOutputStream(diOs, false); |
490 |
} |
|
491 |
||
492 |
public void updateOutputStream(OutputStream diOs, boolean c14n11) |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
493 |
throws CanonicalizationException, IOException { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
494 |
if (diOs == outputStream) { |
1337 | 495 |
return; |
2 | 496 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
497 |
if (bytes != null) { |
2 | 498 |
diOs.write(bytes); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
499 |
} else if (inputOctetStreamProxy == null) { |
1337 | 500 |
CanonicalizerBase c14nizer = null; |
501 |
if (c14n11) { |
|
502 |
c14nizer = new Canonicalizer11_OmitComments(); |
|
503 |
} else { |
|
504 |
c14nizer = new Canonicalizer20010315OmitComments(); |
|
505 |
} |
|
506 |
c14nizer.setWriter(diOs); |
|
2 | 507 |
c14nizer.engineCanonicalize(this); |
1337 | 508 |
} else { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
509 |
byte[] buffer = new byte[4 * 1024]; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
510 |
int bytesread = 0; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
511 |
try { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
512 |
while ((bytesread = inputOctetStreamProxy.read(buffer)) != -1) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
513 |
diOs.write(buffer, 0, bytesread); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
514 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
515 |
} catch (IOException ex) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
516 |
inputOctetStreamProxy.close(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
517 |
throw ex; |
2 | 518 |
} |
519 |
} |
|
1337 | 520 |
} |
2 | 521 |
|
1337 | 522 |
/** |
523 |
* @param os |
|
524 |
*/ |
|
525 |
public void setOutputStream(OutputStream os) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
526 |
outputStream = os; |
1337 | 527 |
} |
2 | 528 |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
529 |
private byte[] getBytesFromInputStream() throws IOException { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
530 |
if (bytes != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
531 |
return bytes; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
532 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
533 |
if (inputOctetStreamProxy == null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
534 |
return null; |
2 | 535 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
536 |
try { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
537 |
bytes = JavaUtils.getBytesFromStream(inputOctetStreamProxy); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
538 |
} finally { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
539 |
inputOctetStreamProxy.close(); |
2 | 540 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
541 |
return bytes; |
2 | 542 |
} |
543 |
||
1337 | 544 |
/** |
545 |
* @param filter |
|
546 |
*/ |
|
547 |
public void addNodeFilter(NodeFilter filter) { |
|
548 |
if (isOctetStream()) { |
|
549 |
try { |
|
550 |
convertToNodes(); |
|
551 |
} catch (Exception e) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
552 |
throw new XMLSecurityRuntimeException( |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
553 |
"signature.XMLSignatureInput.nodesetReference", e |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
554 |
); |
1337 | 555 |
} |
2 | 556 |
} |
1337 | 557 |
nodeFilters.add(filter); |
558 |
} |
|
2 | 559 |
|
1337 | 560 |
/** |
561 |
* @return the node filters |
|
562 |
*/ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
563 |
public List<NodeFilter> getNodeFilters() { |
1337 | 564 |
return nodeFilters; |
565 |
} |
|
2 | 566 |
|
1337 | 567 |
/** |
568 |
* @param b |
|
569 |
*/ |
|
570 |
public void setNodeSet(boolean b) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
571 |
isNodeSet = b; |
1337 | 572 |
} |
2 | 573 |
|
1337 | 574 |
void convertToNodes() throws CanonicalizationException, |
575 |
ParserConfigurationException, IOException, SAXException { |
|
2 | 576 |
// select all nodes, also the comments. |
577 |
try { |
|
59240
b3116877866f
8231507: Update Apache Santuario (XML Signature) to version 2.1.4
weijun
parents:
50614
diff
changeset
|
578 |
Document doc = XMLUtils.read(this.getOctetStream(), secureValidation); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
579 |
this.subNode = doc; |
2 | 580 |
} catch (SAXException ex) { |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
581 |
byte[] result = null; |
1337 | 582 |
// if a not-wellformed nodeset exists, put a container around it... |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
583 |
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { |
2 | 584 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
585 |
baos.write("<container>".getBytes(StandardCharsets.UTF_8)); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
586 |
baos.write(this.getBytes()); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
587 |
baos.write("</container>".getBytes(StandardCharsets.UTF_8)); |
2 | 588 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
589 |
result = baos.toByteArray(); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
590 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
591 |
try (InputStream is = new ByteArrayInputStream(result)) { |
59240
b3116877866f
8231507: Update Apache Santuario (XML Signature) to version 2.1.4
weijun
parents:
50614
diff
changeset
|
592 |
Document document = XMLUtils.read(is, secureValidation); |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
593 |
this.subNode = document.getDocumentElement().getFirstChild().getFirstChild(); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
594 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
595 |
} finally { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
596 |
if (this.inputOctetStreamProxy != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
597 |
this.inputOctetStreamProxy.close(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
598 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
599 |
this.inputOctetStreamProxy = null; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
600 |
this.bytes = null; |
2 | 601 |
} |
1337 | 602 |
} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
603 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
604 |
public boolean isSecureValidation() { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
605 |
return secureValidation; |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
606 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
607 |
|
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
608 |
public void setSecureValidation(boolean secureValidation) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
609 |
this.secureValidation = secureValidation; |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
610 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
611 |
|
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
612 |
public String getPreCalculatedDigest() { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
613 |
return preCalculatedDigest; |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
614 |
} |
2 | 615 |
} |