11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 */
23 /*
24 * ===========================================================================
25 *
26 * (C) Copyright IBM Corp. 2003 All Rights Reserved.
27 *
28 * ===========================================================================
29 */
30 /*
31 * Copyright (c) 2005, 2014 Oracle and/or its affiliates. All rights reserved.
32 */
33 /*
34 * $Id: XMLDSigRI.java 1400021 2012-10-19 10:16:04Z coheigea $
35 */
36 package org.jcp.xml.dsig.internal.dom;
37
38 import java.util.*;
39 import java.security.*;
40
41 import javax.xml.crypto.dsig.*;
42
43 /**
44 * The XMLDSig RI Provider.
45 *
46 * @author Joyce Leung
47 */
48
49 /**
50 * Defines the XMLDSigRI provider.
51 */
52
53 public final class XMLDSigRI extends Provider {
54
55 static final long serialVersionUID = -5049765099299494554L;
56
57 private static final String INFO = "XMLDSig " +
58 "(DOM XMLSignatureFactory; DOM KeyInfoFactory; " +
59 "C14N 1.0, C14N 1.1, Exclusive C14N, Base64, Enveloped, XPath, " +
60 "XPath2, XSLT TransformServices)";
61
62 public XMLDSigRI() {
63 /* We are the XMLDSig provider */
64 super("XMLDSig", 1.9d, INFO);
65
66 final Map<Object, Object> map = new HashMap<Object, Object>();
67 map.put("XMLSignatureFactory.DOM",
68 "org.jcp.xml.dsig.internal.dom.DOMXMLSignatureFactory");
69 map.put("KeyInfoFactory.DOM",
70 "org.jcp.xml.dsig.internal.dom.DOMKeyInfoFactory");
71
72
73 // Inclusive C14N
74 map.put("TransformService." + CanonicalizationMethod.INCLUSIVE,
75 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14NMethod");
76 map.put("Alg.Alias.TransformService.INCLUSIVE",
77 CanonicalizationMethod.INCLUSIVE);
78 map.put("TransformService." + CanonicalizationMethod.INCLUSIVE +
79 " MechanismType", "DOM");
80
81 // InclusiveWithComments C14N
82 map.put("TransformService." +
83 CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
84 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14NMethod");
85 map.put("Alg.Alias.TransformService.INCLUSIVE_WITH_COMMENTS",
86 CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS);
87 map.put("TransformService." +
88 CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS +
89 " MechanismType", "DOM");
90
91 // Inclusive C14N 1.1
92 map.put("TransformService.http://www.w3.org/2006/12/xml-c14n11",
93 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14N11Method");
94 map.put("TransformService.http://www.w3.org/2006/12/xml-c14n11" +
95 " MechanismType", "DOM");
96
97 // InclusiveWithComments C14N 1.1
98 map.put("TransformService.http://www.w3.org/2006/12/xml-c14n11#WithComments",
99 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14N11Method");
100 map.put("TransformService.http://www.w3.org/2006/12/xml-c14n11#WithComments" +
101 " MechanismType", "DOM");
102
103 // Exclusive C14N
104 map.put("TransformService." + CanonicalizationMethod.EXCLUSIVE,
105 "org.jcp.xml.dsig.internal.dom.DOMExcC14NMethod");
106 map.put("Alg.Alias.TransformService.EXCLUSIVE",
107 CanonicalizationMethod.EXCLUSIVE);
108 map.put("TransformService." + CanonicalizationMethod.EXCLUSIVE +
109 " MechanismType", "DOM");
110
111 // ExclusiveWithComments C14N
112 map.put("TransformService." +
113 CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS,
114 "org.jcp.xml.dsig.internal.dom.DOMExcC14NMethod");
115 map.put("Alg.Alias.TransformService.EXCLUSIVE_WITH_COMMENTS",
116 CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS);
117 map.put("TransformService." +
118 CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS +
119 " MechanismType", "DOM");
120
121 // Base64 Transform
122 map.put("TransformService." + Transform.BASE64,
123 "org.jcp.xml.dsig.internal.dom.DOMBase64Transform");
124 map.put("Alg.Alias.TransformService.BASE64", Transform.BASE64);
125 map.put("TransformService." + Transform.BASE64 +
126 " MechanismType", "DOM");
127
128 // Enveloped Transform
129 map.put("TransformService." + Transform.ENVELOPED,
130 "org.jcp.xml.dsig.internal.dom.DOMEnvelopedTransform");
131 map.put("Alg.Alias.TransformService.ENVELOPED", Transform.ENVELOPED);
132 map.put("TransformService." + Transform.ENVELOPED +
133 " MechanismType", "DOM");
134
135 // XPath2 Transform
136 map.put("TransformService." + Transform.XPATH2,
137 "org.jcp.xml.dsig.internal.dom.DOMXPathFilter2Transform");
138 map.put("Alg.Alias.TransformService.XPATH2", Transform.XPATH2);
139 map.put("TransformService." + Transform.XPATH2 +
140 " MechanismType", "DOM");
141
142 // XPath Transform
143 map.put("TransformService." + Transform.XPATH,
144 "org.jcp.xml.dsig.internal.dom.DOMXPathTransform");
145 map.put("Alg.Alias.TransformService.XPATH", Transform.XPATH);
146 map.put("TransformService." + Transform.XPATH +
147 " MechanismType", "DOM");
148
149 // XSLT Transform
150 map.put("TransformService." + Transform.XSLT,
151 "org.jcp.xml.dsig.internal.dom.DOMXSLTTransform");
152 map.put("Alg.Alias.TransformService.XSLT", Transform.XSLT);
153 map.put("TransformService." + Transform.XSLT + " MechanismType", "DOM");
154
155 AccessController.doPrivileged(new PrivilegedAction<Void>() {
156 public Void run() {
157 putAll(map);
158 return null;
159 }
160 });
161 }
162 }
|
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 */
23 /*
24 * ===========================================================================
25 *
26 * (C) Copyright IBM Corp. 2003 All Rights Reserved.
27 *
28 * ===========================================================================
29 */
30 /*
31 * Copyright (c) 2005, 2015 Oracle and/or its affiliates. All rights reserved.
32 */
33 /*
34 * $Id: XMLDSigRI.java 1400021 2012-10-19 10:16:04Z coheigea $
35 */
36 package org.jcp.xml.dsig.internal.dom;
37
38 import java.util.*;
39 import java.security.*;
40
41 import javax.xml.crypto.dsig.*;
42
43 /**
44 * The XMLDSig RI Provider.
45 *
46 * @author Joyce Leung
47 */
48
49 /**
50 * Defines the XMLDSigRI provider.
51 */
52
53 public final class XMLDSigRI extends Provider {
54
55 static final long serialVersionUID = -5049765099299494554L;
56
57 private static final String INFO = "XMLDSig " +
58 "(DOM XMLSignatureFactory; DOM KeyInfoFactory; " +
59 "C14N 1.0, C14N 1.1, Exclusive C14N, Base64, Enveloped, XPath, " +
60 "XPath2, XSLT TransformServices)";
61
62 private static final class ProviderService extends Provider.Service {
63
64 ProviderService(Provider p, String type, String algo, String cn) {
65 super(p, type, algo, cn, null, null);
66 }
67
68 ProviderService(Provider p, String type, String algo, String cn,
69 String[] aliases) {
70 super(p, type, algo, cn,
71 (aliases == null? null : Arrays.asList(aliases)), null);
72 }
73
74 ProviderService(Provider p, String type, String algo, String cn,
75 String[] aliases, HashMap<String, String> attrs) {
76 super(p, type, algo, cn,
77 (aliases == null? null : Arrays.asList(aliases)), attrs);
78 }
79
80 @Override
81 public Object newInstance(Object ctrParamObj)
82 throws NoSuchAlgorithmException {
83 String type = getType();
84 if (ctrParamObj != null) {
85 throw new InvalidParameterException
86 ("constructorParameter not used with " + type + " engines");
87 }
88
89 String algo = getAlgorithm();
90 try {
91 if (type.equals("XMLSignatureFactory")) {
92 if (algo.equals("DOM")) {
93 return new DOMXMLSignatureFactory();
94 }
95 } else if (type.equals("KeyInfoFactory")) {
96 if (algo.equals("DOM")) {
97 return new DOMKeyInfoFactory();
98 }
99 } else if (type.equals("TransformService")) {
100 if (algo.equals(CanonicalizationMethod.INCLUSIVE) ||
101 algo.equals(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS)) {
102 return new DOMCanonicalXMLC14NMethod();
103 } else if (algo.equals("http://www.w3.org/2006/12/xml-c14n11") ||
104 algo.equals("http://www.w3.org/2006/12/xml-c14n11#WithComments")) {
105 return new DOMCanonicalXMLC14N11Method();
106 } else if (algo.equals(CanonicalizationMethod.EXCLUSIVE) ||
107 algo.equals(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS)) {
108 return new DOMExcC14NMethod();
109 } else if (algo.equals(Transform.BASE64)) {
110 return new DOMBase64Transform();
111 } else if (algo.equals(Transform.ENVELOPED)) {
112 return new DOMEnvelopedTransform();
113 } else if (algo.equals(Transform.XPATH2)) {
114 return new DOMXPathFilter2Transform();
115 } else if (algo.equals(Transform.XPATH)) {
116 return new DOMXPathTransform();
117 } else if (algo.equals(Transform.XSLT)) {
118 return new DOMXSLTTransform();
119 }
120 }
121 } catch (Exception ex) {
122 throw new NoSuchAlgorithmException("Error constructing " +
123 type + " for " + algo + " using XMLDSig", ex);
124 }
125 throw new ProviderException("No impl for " + algo +
126 " " + type);
127 }
128 }
129
130 public XMLDSigRI() {
131 /* We are the XMLDSig provider */
132 super("XMLDSig", 1.9d, INFO);
133
134 final Provider p = this;
135 AccessController.doPrivileged(new PrivilegedAction<Void>() {
136 public Void run() {
137 HashMap<String, String> MECH_TYPE = new HashMap<>();
138 MECH_TYPE.put("MechanismType", "DOM");
139
140 putService(new ProviderService(p, "XMLSignatureFactory",
141 "DOM", "org.jcp.xml.dsig.internal.dom.DOMXMLSignatureFactory"));
142
143 putService(new ProviderService(p, "KeyInfoFactory",
144 "DOM", "org.jcp.xml.dsig.internal.dom.DOMKeyInfoFactory"));
145
146
147 // Inclusive C14N
148 putService(new ProviderService(p, "TransformService",
149 CanonicalizationMethod.INCLUSIVE,
150 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14NMethod",
151 new String[] {"INCLUSIVE"}, MECH_TYPE));
152
153 // InclusiveWithComments C14N
154 putService(new ProviderService(p, "TransformService",
155 CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
156 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14NMethod",
157 new String[] {"INCLUSIVE_WITH_COMMENTS"}, MECH_TYPE));
158
159 // Inclusive C14N 1.1
160 putService(new ProviderService(p, "TransformService",
161 "http://www.w3.org/2006/12/xml-c14n11",
162 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14N11Method",
163 null, MECH_TYPE));
164
165 // InclusiveWithComments C14N 1.1
166 putService(new ProviderService(p, "TransformService",
167 "http://www.w3.org/2006/12/xml-c14n11#WithComments",
168 "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14N11Method",
169 null, MECH_TYPE));
170
171 // Exclusive C14N
172 putService(new ProviderService(p, "TransformService",
173 CanonicalizationMethod.EXCLUSIVE,
174 "org.jcp.xml.dsig.internal.dom.DOMExcC14NMethod",
175 new String[] {"EXCLUSIVE"}, MECH_TYPE));
176
177 // ExclusiveWithComments C14N
178 putService(new ProviderService(p, "TransformService",
179 CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS,
180 "org.jcp.xml.dsig.internal.dom.DOMExcC14NMethod",
181 new String[] {"EXCLUSIVE_WITH_COMMENTS"}, MECH_TYPE));
182
183 // Base64 Transform
184 putService(new ProviderService(p, "TransformService",
185 Transform.BASE64,
186 "org.jcp.xml.dsig.internal.dom.DOMBase64Transform",
187 new String[] {"BASE64"}, MECH_TYPE));
188
189 // Enveloped Transform
190 putService(new ProviderService(p, "TransformService",
191 Transform.ENVELOPED,
192 "org.jcp.xml.dsig.internal.dom.DOMEnvelopedTransform",
193 new String[] {"ENVELOPED"}, MECH_TYPE));
194
195 // XPath2 Transform
196 putService(new ProviderService(p, "TransformService",
197 Transform.XPATH2,
198 "org.jcp.xml.dsig.internal.dom.DOMXPathFilter2Transform",
199 new String[] {"XPATH2"}, MECH_TYPE));
200
201 // XPath Transform
202 putService(new ProviderService(p, "TransformService",
203 Transform.XPATH,
204 "org.jcp.xml.dsig.internal.dom.DOMXPathTransform",
205 new String[] {"XPATH"}, MECH_TYPE));
206
207 // XSLT Transform
208 putService(new ProviderService(p, "TransformService",
209 Transform.XSLT,
210 "org.jcp.xml.dsig.internal.dom.DOMXSLTTransform",
211 new String[] {"XSLT"}, MECH_TYPE));
212 return null;
213 }
214 });
215 }
216 }
|