author | mullan |
Fri, 21 Nov 2014 15:23:36 -0500 | |
changeset 27747 | 3a271dc8b758 |
parent 25859 | 3317bb8137f4 |
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:
5506
diff
changeset
|
5 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
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:
5506
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:
5506
diff
changeset
|
8 |
* distributed with this work for additional information |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
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:
5506
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:
5506
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:
5506
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:
5506
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:
5506
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:
5506
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:
5506
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:
5506
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:
5506
diff
changeset
|
20 |
* specific language governing permissions and limitations |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
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:
5506
diff
changeset
|
27 |
* $Id: DOMKeyInfoFactory.java 1333869 2012-05-04 10:42:44Z coheigea $ |
2 | 28 |
*/ |
29 |
package org.jcp.xml.dsig.internal.dom; |
|
30 |
||
31 |
import java.math.BigInteger; |
|
1337 | 32 |
import java.security.KeyException; |
33 |
import java.security.PublicKey; |
|
2 | 34 |
import java.util.List; |
35 |
import javax.xml.crypto.*; |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
36 |
import javax.xml.crypto.dom.DOMCryptoContext; |
27747 | 37 |
import javax.xml.crypto.dsig.Transform; |
2 | 38 |
import javax.xml.crypto.dsig.keyinfo.*; |
39 |
import org.w3c.dom.Document; |
|
40 |
import org.w3c.dom.Element; |
|
41 |
import org.w3c.dom.Node; |
|
42 |
||
43 |
/** |
|
44 |
* DOM-based implementation of KeyInfoFactory. |
|
45 |
* |
|
46 |
* @author Sean Mullan |
|
47 |
*/ |
|
48 |
public final class DOMKeyInfoFactory extends KeyInfoFactory { |
|
49 |
||
50 |
public DOMKeyInfoFactory() { } |
|
51 |
||
27747 | 52 |
public KeyInfo newKeyInfo(List<? extends XMLStructure> content) { |
2 | 53 |
return newKeyInfo(content, null); |
54 |
} |
|
55 |
||
27747 | 56 |
public KeyInfo newKeyInfo(List<? extends XMLStructure> content, String id) { |
2 | 57 |
return new DOMKeyInfo(content, id); |
58 |
} |
|
59 |
||
60 |
public KeyName newKeyName(String name) { |
|
61 |
return new DOMKeyName(name); |
|
62 |
} |
|
63 |
||
64 |
public KeyValue newKeyValue(PublicKey key) throws KeyException { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
65 |
String algorithm = key.getAlgorithm(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
66 |
if (algorithm.equals("DSA")) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
67 |
return new DOMKeyValue.DSA(key); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
68 |
} else if (algorithm.equals("RSA")) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
69 |
return new DOMKeyValue.RSA(key); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
70 |
} else if (algorithm.equals("EC")) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
71 |
return new DOMKeyValue.EC(key); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
72 |
} else { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
73 |
throw new KeyException("unsupported key algorithm: " + algorithm); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
74 |
} |
2 | 75 |
} |
76 |
||
77 |
public PGPData newPGPData(byte[] keyId) { |
|
78 |
return newPGPData(keyId, null, null); |
|
79 |
} |
|
80 |
||
27747 | 81 |
public PGPData newPGPData(byte[] keyId, byte[] keyPacket, |
82 |
List<? extends XMLStructure> other) { |
|
2 | 83 |
return new DOMPGPData(keyId, keyPacket, other); |
84 |
} |
|
85 |
||
27747 | 86 |
public PGPData newPGPData(byte[] keyPacket, |
87 |
List<? extends XMLStructure> other) { |
|
2 | 88 |
return new DOMPGPData(keyPacket, other); |
89 |
} |
|
90 |
||
91 |
public RetrievalMethod newRetrievalMethod(String uri) { |
|
92 |
return newRetrievalMethod(uri, null, null); |
|
93 |
} |
|
94 |
||
95 |
public RetrievalMethod newRetrievalMethod(String uri, String type, |
|
27747 | 96 |
List<? extends Transform> transforms) { |
2 | 97 |
if (uri == null) { |
98 |
throw new NullPointerException("uri must not be null"); |
|
99 |
} |
|
100 |
return new DOMRetrievalMethod(uri, type, transforms); |
|
101 |
} |
|
102 |
||
27747 | 103 |
public X509Data newX509Data(List<?> content) { |
2 | 104 |
return new DOMX509Data(content); |
105 |
} |
|
106 |
||
107 |
public X509IssuerSerial newX509IssuerSerial(String issuerName, |
|
108 |
BigInteger serialNumber) { |
|
109 |
return new DOMX509IssuerSerial(issuerName, serialNumber); |
|
110 |
} |
|
111 |
||
112 |
public boolean isFeatureSupported(String feature) { |
|
113 |
if (feature == null) { |
|
114 |
throw new NullPointerException(); |
|
115 |
} else { |
|
116 |
return false; |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
public URIDereferencer getURIDereferencer() { |
|
121 |
return DOMURIDereferencer.INSTANCE; |
|
122 |
} |
|
123 |
||
124 |
public KeyInfo unmarshalKeyInfo(XMLStructure xmlStructure) |
|
125 |
throws MarshalException { |
|
126 |
if (xmlStructure == null) { |
|
127 |
throw new NullPointerException("xmlStructure cannot be null"); |
|
128 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
129 |
if (!(xmlStructure instanceof javax.xml.crypto.dom.DOMStructure)) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
130 |
throw new ClassCastException("xmlStructure must be of type DOMStructure"); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
131 |
} |
2 | 132 |
Node node = |
133 |
((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode(); |
|
134 |
node.normalize(); |
|
135 |
||
136 |
Element element = null; |
|
137 |
if (node.getNodeType() == Node.DOCUMENT_NODE) { |
|
138 |
element = ((Document) node).getDocumentElement(); |
|
139 |
} else if (node.getNodeType() == Node.ELEMENT_NODE) { |
|
140 |
element = (Element) node; |
|
141 |
} else { |
|
142 |
throw new MarshalException |
|
143 |
("xmlStructure does not contain a proper Node"); |
|
144 |
} |
|
145 |
||
146 |
// check tag |
|
147 |
String tag = element.getLocalName(); |
|
148 |
if (tag == null) { |
|
149 |
throw new MarshalException("Document implementation must " + |
|
150 |
"support DOM Level 2 and be namespace aware"); |
|
151 |
} |
|
152 |
if (tag.equals("KeyInfo")) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
153 |
return new DOMKeyInfo(element, new UnmarshalContext(), getProvider()); |
2 | 154 |
} else { |
155 |
throw new MarshalException("invalid KeyInfo tag: " + tag); |
|
156 |
} |
|
157 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
158 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
159 |
private static class UnmarshalContext extends DOMCryptoContext { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
160 |
UnmarshalContext() {} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
161 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
162 |
|
2 | 163 |
} |