javax.xml.crypto.dsig.XMLDSigSecurity Maven / Gradle / Ivy
The newest version!
/* */ package javax.xml.crypto.dsig;
/* */
/* */ import java.security.NoSuchAlgorithmException;
/* */ import java.security.Provider;
/* */ import java.security.Security;
/* */ import java.util.Enumeration;
/* */ import java.util.Map.Entry;
/* */ import java.util.Set;
/* */ import javax.xml.crypto.NoSuchMechanismException;
/* */ import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
/* */
/* */ final class XMLDSigSecurity
/* */ {
/* */ private static ProviderProperty getEngineClassName(String alg, Map.Entry attr, String engineType, String key, boolean mech)
/* */ throws NoSuchAlgorithmException
/* */ {
/* 50 */ Provider[] provs = Security.getProviders();
/* */
/* 54 */ boolean found = false;
/* 55 */ ProviderProperty entry = null;
/* 56 */ for (int i = 0; (i < provs.length) && (!found); i++)
/* */ try {
/* 58 */ entry = getEngineClassName(alg, attr, engineType, key, provs[i], mech);
/* */
/* 60 */ found = true;
/* */ }
/* */ catch (Exception e)
/* */ {
/* */ }
/* 65 */ if (!found) {
/* 66 */ if (mech) {
/* 67 */ throw new NoSuchMechanismException("Mechanism type " + alg + " not available");
/* */ }
/* */
/* 70 */ throw new NoSuchAlgorithmException("Algorithm type " + alg + " not available");
/* */ }
/* */
/* 74 */ return entry;
/* */ }
/* */
/* */ private static ProviderProperty getEngineClassName(String alg, Map.Entry attr, String engineType, String key, Provider provider, boolean mech)
/* */ throws NoSuchAlgorithmException
/* */ {
/* 84 */ String className = getProviderProperty(key, attr, provider);
/* 85 */ if (className == null)
/* */ {
/* 87 */ String stdName = getStandardName(alg, engineType, provider);
/* 88 */ if (stdName != null) {
/* 89 */ key = engineType + "." + stdName;
/* */ }
/* 91 */ if ((stdName == null) || ((className = getProviderProperty(key, attr, provider)) == null))
/* */ {
/* 93 */ if (mech) {
/* 94 */ throw new NoSuchMechanismException("no such mechanism type: " + alg + " for provider " + provider.getName());
/* */ }
/* */
/* 98 */ throw new NoSuchAlgorithmException("no such algorithm: " + alg + " for provider " + provider.getName());
/* */ }
/* */
/* */ }
/* */
/* 105 */ ProviderProperty entry = new ProviderProperty(null);
/* 106 */ entry.className = className;
/* 107 */ entry.provider = provider;
/* 108 */ return entry;
/* */ }
/* */
/* */ private static boolean checkSuperclass(Class subclass, Class superclass) {
/* 112 */ return superclass.isAssignableFrom(subclass);
/* */ }
/* */
/* */ static Object[] getImpl(String mechType, String type, Provider provider)
/* */ throws NoSuchAlgorithmException
/* */ {
/* 126 */ return getImpl(mechType, null, type, provider);
/* */ }
/* */
/* */ static Object[] getImpl(String alg, Map.Entry attr, String type, Provider provider) throws NoSuchAlgorithmException
/* */ {
/* 131 */ Class typeClass = null;
/* 132 */ boolean m = true;
/* 133 */ if (type.equals("XMLSignatureFactory")) {
/* 134 */ typeClass = XMLSignatureFactory.class;
/* 135 */ } else if (type.equals("KeyInfoFactory")) {
/* 136 */ typeClass = KeyInfoFactory.class;
/* 137 */ } else if (type.equals("TransformService")) {
/* 138 */ typeClass = TransformService.class;
/* 139 */ m = false;
/* */ }
/* 141 */ String key = type + "." + alg;
/* 142 */ if (provider == null) {
/* 143 */ return doGetImpl(type, typeClass, getEngineClassName(alg, attr, type, key, m), m);
/* */ }
/* */
/* 147 */ return doGetImpl(type, typeClass, getEngineClassName(alg, attr, type, key, provider, m), m);
/* */ }
/* */
/* */ private static Object[] doGetImpl(String type, Class typeClass, ProviderProperty pp, boolean mech)
/* */ throws NoSuchAlgorithmException
/* */ {
/* 156 */ String className = pp.className;
/* 157 */ String providerName = pp.provider.getName();
/* */ try
/* */ {
/* 168 */ ClassLoader cl = pp.provider.getClass().getClassLoader();
/* */ Class implClass;
/* */ Class implClass;
/* 170 */ if (cl != null)
/* 171 */ implClass = cl.loadClass(className);
/* */ else {
/* 173 */ implClass = Class.forName(className);
/* */ }
/* */
/* 176 */ if (checkSuperclass(implClass, typeClass)) {
/* 177 */ return new Object[] { implClass.newInstance(), pp.provider };
/* */ }
/* 179 */ if (mech) {
/* 180 */ throw new NoSuchMechanismException("class configured for " + type + ": " + className + " not a " + type);
/* */ }
/* */
/* 184 */ throw new NoSuchAlgorithmException("class configured for " + type + ": " + className + " not a " + type);
/* */ }
/* */ catch (ClassNotFoundException e)
/* */ {
/* 190 */ if (mech) {
/* 191 */ throw new NoSuchMechanismException("class configured for " + type + "(provider: " + providerName + ")" + "cannot be found.\n", e);
/* */ }
/* */
/* 195 */ throw ((NoSuchAlgorithmException)new NoSuchAlgorithmException("class configured for " + type + "(provider: " + providerName + ")" + "cannot be found.\n").initCause(e));
/* */ }
/* */ catch (InstantiationException e)
/* */ {
/* 200 */ if (mech) {
/* 201 */ throw new NoSuchMechanismException("class " + className + " configured for " + type + "(provider: " + providerName + ") cannot be " + "instantiated. ", e);
/* */ }
/* */
/* 206 */ throw ((NoSuchAlgorithmException)new NoSuchAlgorithmException("class " + className + " configured for " + type + "(provider: " + providerName + ") cannot be " + "instantiated. ").initCause(e));
/* */ }
/* */ catch (IllegalAccessException e)
/* */ {
/* 212 */ if (mech) {
/* 213 */ throw new NoSuchMechanismException("class " + className + " configured for " + type + "(provider: " + providerName + ") cannot be accessed.\n", e);
/* */ }
/* */
/* 218 */ throw ((NoSuchAlgorithmException)new NoSuchAlgorithmException("class " + className + " configured for " + type + "(provider: " + providerName + ") cannot be accessed.\n").initCause(e));
/* */ }
/* */ }
/* */
/* */ private static String getProviderProperty(String key, Map.Entry attr, Provider prov)
/* */ {
/* 231 */ String prop = prov.getProperty(key);
/* */ Enumeration e;
/* 232 */ if (prop == null)
/* */ {
/* 235 */ for (e = prov.keys(); e.hasMoreElements(); ) {
/* 236 */ String matchKey = (String)e.nextElement();
/* 237 */ if (key.equalsIgnoreCase(matchKey)) {
/* 238 */ prop = prov.getProperty(matchKey);
/* 239 */ break;
/* */ }
/* */ }
/* */ }
/* */
/* 244 */ if ((prop != null) && (attr != null) &&
/* 245 */ (!prov.entrySet().contains(attr)))
/* */ {
/* 247 */ if ((!attr.getValue().equals("DOM")) || (prov.get(attr.getKey()) != null))
/* */ {
/* 249 */ prop = null;
/* */ }
/* */
/* */ }
/* */
/* 254 */ return prop;
/* */ }
/* */
/* */ private static String getStandardName(String alias, String engineType, Provider prov)
/* */ {
/* 262 */ return getProviderProperty("Alg.Alias." + engineType + "." + alias, null, prov);
/* */ }
/* */
/* */ private static class ProviderProperty
/* */ {
/* */ String className;
/* */ Provider provider;
/* */
/* */ private ProviderProperty()
/* */ {
/* */ }
/* */
/* */ ProviderProperty(XMLDSigSecurity.1 x0)
/* */ {
/* 30 */ this();
/* */ }
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: javax.xml.crypto.dsig.XMLDSigSecurity
* JD-Core Version: 0.6.2
*/