author | jlahoda |
Tue, 24 Sep 2019 15:40:26 +0200 | |
branch | JDK-8226585-branch |
changeset 58290 | d885633d9de4 |
parent 53998 | d870bb08194a |
permissions | -rw-r--r-- |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
1 |
/* |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
2 |
* reserved comment block |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
3 |
* DO NOT REMOVE OR ALTER! |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
4 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
5 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
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:
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:
diff
changeset
|
8 |
* distributed with this work for additional information |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
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:
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:
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:
diff
changeset
|
12 |
* with the License. You may obtain a copy of the License at |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
13 |
* |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
15 |
* |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
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:
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:
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:
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:
diff
changeset
|
20 |
* specific language governing permissions and limitations |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
21 |
* under the License. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
22 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
23 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
24 |
package org.jcp.xml.dsig.internal.dom; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
25 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
26 |
import java.security.Key; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
27 |
import java.security.InvalidAlgorithmParameterException; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
28 |
import java.security.InvalidKeyException; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
29 |
import java.security.SignatureException; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
30 |
import java.security.spec.AlgorithmParameterSpec; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
31 |
import javax.xml.crypto.MarshalException; |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
32 |
import javax.xml.crypto.dom.DOMCryptoContext; |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
33 |
import javax.xml.crypto.dsig.SignatureMethod; |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
34 |
import javax.xml.crypto.dsig.SignedInfo; |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
35 |
import javax.xml.crypto.dsig.XMLSignature; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
36 |
import javax.xml.crypto.dsig.XMLSignatureException; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
37 |
import javax.xml.crypto.dsig.XMLSignContext; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
38 |
import javax.xml.crypto.dsig.XMLValidateContext; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
39 |
import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec; |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
40 |
import org.w3c.dom.Document; |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
41 |
import org.w3c.dom.Element; |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
42 |
import org.w3c.dom.Node; |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
43 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
44 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
45 |
* An abstract class representing a SignatureMethod. Subclasses implement |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
46 |
* a specific XML DSig signature algorithm. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
47 |
*/ |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
48 |
abstract class AbstractDOMSignatureMethod extends DOMStructure |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
49 |
implements SignatureMethod { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
50 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
51 |
// denotes the type of signature algorithm |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
52 |
enum Type { DSA, RSA, ECDSA, HMAC } |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
53 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
54 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
55 |
* Verifies the passed-in signature with the specified key, using the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
56 |
* underlying Signature or Mac algorithm. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
57 |
* |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
58 |
* @param key the verification key |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
59 |
* @param si the SignedInfo |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
60 |
* @param sig the signature bytes to be verified |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
61 |
* @param context the XMLValidateContext |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
62 |
* @return {@code true} if the signature verified successfully, |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
63 |
* {@code false} if not |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
64 |
* @throws NullPointerException if {@code key}, {@code si} or |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
65 |
* {@code sig} are {@code null} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
66 |
* @throws InvalidKeyException if the key is improperly encoded, of |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
67 |
* the wrong type, or parameters are missing, etc |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
68 |
* @throws SignatureException if an unexpected error occurs, such |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
69 |
* as the passed in signature is improperly encoded |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
70 |
* @throws XMLSignatureException if an unexpected error occurs |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
71 |
*/ |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
72 |
abstract boolean verify(Key key, SignedInfo si, byte[] sig, |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
73 |
XMLValidateContext context) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
74 |
throws InvalidKeyException, SignatureException, XMLSignatureException; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
75 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
76 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
77 |
* Signs the bytes with the specified key, using the underlying |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
78 |
* Signature or Mac algorithm. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
79 |
* |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
80 |
* @param key the signing key |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
81 |
* @param si the SignedInfo |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
82 |
* @param context the XMLSignContext |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
83 |
* @return the signature |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
84 |
* @throws NullPointerException if {@code key} or |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
85 |
* {@code si} are {@code null} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
86 |
* @throws InvalidKeyException if the key is improperly encoded, of |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
87 |
* the wrong type, or parameters are missing, etc |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
88 |
* @throws XMLSignatureException if an unexpected error occurs |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
89 |
*/ |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
90 |
abstract byte[] sign(Key key, SignedInfo si, XMLSignContext context) |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
91 |
throws InvalidKeyException, XMLSignatureException; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
92 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
93 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
94 |
* Returns the java.security.Signature or javax.crypto.Mac standard |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
95 |
* algorithm name. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
96 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
97 |
abstract String getJCAAlgorithm(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
98 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
99 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
100 |
* Returns the type of signature algorithm. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
101 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
102 |
abstract Type getAlgorithmType(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
103 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
104 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
105 |
* This method invokes the {@link #marshalParams marshalParams} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
106 |
* method to marshal any algorithm-specific parameters. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
107 |
*/ |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
108 |
@Override |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
109 |
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
110 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
111 |
{ |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
112 |
Document ownerDoc = DOMUtils.getOwnerDocument(parent); |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
113 |
|
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
114 |
Element smElem = DOMUtils.createElement(ownerDoc, "SignatureMethod", |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
115 |
XMLSignature.XMLNS, dsPrefix); |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
116 |
DOMUtils.setAttribute(smElem, "Algorithm", getAlgorithm()); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
117 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
118 |
if (getParameterSpec() != null) { |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
119 |
marshalParams(smElem, dsPrefix); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
120 |
} |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
121 |
|
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
122 |
parent.appendChild(smElem); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
123 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
124 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
125 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
126 |
* Marshals the algorithm-specific parameters to an Element and |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
127 |
* appends it to the specified parent element. By default, this method |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
128 |
* throws an exception since most SignatureMethod algorithms do not have |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
129 |
* parameters. Subclasses should override it if they have parameters. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
130 |
* |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
131 |
* @param parent the parent element to append the parameters to |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
132 |
* @param paramsPrefix the algorithm parameters prefix to use |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
133 |
* @throws MarshalException if the parameters cannot be marshalled |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
134 |
*/ |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
135 |
void marshalParams(Element parent, String paramsPrefix) |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
136 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
137 |
{ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
138 |
throw new MarshalException("no parameters should " + |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
139 |
"be specified for the " + getAlgorithm() + |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
140 |
" SignatureMethod algorithm"); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
141 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
142 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
143 |
/** |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
144 |
* Unmarshals {@code SignatureMethodParameterSpec} from the specified |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
145 |
* {@code Element}. By default, this method throws an exception since |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
146 |
* most SignatureMethod algorithms do not have parameters. Subclasses should |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
147 |
* override it if they have parameters. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
148 |
* |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
149 |
* @param paramsElem the {@code Element} holding the input params |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
150 |
* @return the algorithm-specific {@code SignatureMethodParameterSpec} |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
151 |
* @throws MarshalException if the parameters cannot be unmarshalled |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
152 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
153 |
SignatureMethodParameterSpec unmarshalParams(Element paramsElem) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
154 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
155 |
{ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
156 |
throw new MarshalException("no parameters should " + |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
157 |
"be specified for the " + getAlgorithm() + |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
158 |
" SignatureMethod algorithm"); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
159 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
160 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
161 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
162 |
* Checks if the specified parameters are valid for this algorithm. By |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
163 |
* default, this method throws an exception if parameters are specified |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
164 |
* since most SignatureMethod algorithms do not have parameters. Subclasses |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
165 |
* should override it if they have parameters. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
166 |
* |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
167 |
* @param params the algorithm-specific params (may be {@code null}) |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
168 |
* @throws InvalidAlgorithmParameterException if the parameters are not |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
169 |
* appropriate for this signature method |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
170 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
171 |
void checkParams(SignatureMethodParameterSpec params) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
172 |
throws InvalidAlgorithmParameterException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
173 |
{ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
174 |
if (params != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
175 |
throw new InvalidAlgorithmParameterException("no parameters " + |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
176 |
"should be specified for the " + getAlgorithm() + |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
177 |
" SignatureMethod algorithm"); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
178 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
179 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
180 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
181 |
@Override |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
182 |
public boolean equals(Object o) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
183 |
{ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
184 |
if (this == o) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
185 |
return true; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
186 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
187 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
188 |
if (!(o instanceof SignatureMethod)) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
189 |
return false; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
190 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
191 |
SignatureMethod osm = (SignatureMethod)o; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
192 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
193 |
return getAlgorithm().equals(osm.getAlgorithm()) && |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
194 |
paramsEqual(osm.getParameterSpec()); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
195 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
196 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
197 |
@Override |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
198 |
public int hashCode() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
199 |
int result = 17; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
200 |
result = 31 * result + getAlgorithm().hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
201 |
AlgorithmParameterSpec spec = getParameterSpec(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
202 |
if (spec != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
203 |
result = 31 * result + spec.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
204 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
205 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
206 |
return result; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
207 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
208 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
209 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
210 |
* Returns true if parameters are equal; false otherwise. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
211 |
* |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
212 |
* Subclasses should override this method to compare algorithm-specific |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
213 |
* parameters. |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
214 |
*/ |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
215 |
boolean paramsEqual(AlgorithmParameterSpec spec) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
216 |
{ |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
217 |
return getParameterSpec() == spec; |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
218 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
diff
changeset
|
219 |
} |