1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /** 6 * Licensed to the Apache Software Foundation (ASF) under one 7 * or more contributor license agreements. See the NOTICE file 8 * distributed with this work for additional information 9 * regarding copyright ownership. The ASF licenses this file 10 * to you under the Apache License, Version 2.0 (the 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 }