1 2 18 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; 19 20 21 22 import java.security.PublicKey ; 23 import java.security.cert.X509Certificate ; 24 25 26 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 27 import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate; 28 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException; 29 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; 30 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 31 import com.sun.org.apache.xml.internal.security.utils.Constants; 32 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 33 import org.w3c.dom.Element ; 34 35 36 42 public class X509CertificateResolver extends KeyResolverSpi { 43 44 45 static java.util.logging.Logger log = 46 java.util.logging.Logger.getLogger(X509CertificateResolver.class.getName()); 47 48 49 Element [] _x509CertKeyElements = null; 50 51 59 public boolean engineCanResolve(Element element, String BaseURI, 60 StorageResolver storage) { 61 if (true) 62 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?"); 63 64 if (!XMLUtils.elementIsInSignatureSpace(element, 65 Constants._TAG_X509DATA)) { 66 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 67 68 return false; 69 } 70 71 72 this._x509CertKeyElements = XMLUtils.selectDsNodes(element.getFirstChild(), 73 Constants._TAG_X509CERTIFICATE); 74 75 if ((this._x509CertKeyElements != null) 76 && (this._x509CertKeyElements.length > 0)) { 77 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Yes Sir, I can"); 78 79 return true; 80 } 81 82 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 83 84 return false; 85 } 86 87 88 XMLX509Certificate _x509certObject[] = null; 89 90 99 public PublicKey engineResolvePublicKey( 100 Element element, String BaseURI, StorageResolver storage) 101 throws KeyResolverException { 102 103 X509Certificate cert = this.engineResolveX509Certificate(element, 104 BaseURI, storage); 105 106 if (cert != null) { 107 return cert.getPublicKey(); 108 } 109 110 return null; 111 } 112 113 122 public X509Certificate engineResolveX509Certificate( 123 Element element, String BaseURI, StorageResolver storage) 124 throws KeyResolverException { 125 126 try { 127 if ((this._x509CertKeyElements == null) 128 || (this._x509CertKeyElements.length == 0)) { 129 boolean weCanResolve = this.engineCanResolve(element, BaseURI, 130 storage); 131 132 if (!weCanResolve || (this._x509CertKeyElements == null) 133 || (this._x509CertKeyElements.length == 0)) { 134 return null; 135 } 136 } 137 138 this._x509certObject = 139 new XMLX509Certificate[this._x509CertKeyElements.length]; 140 141 for (int i = 0; i < this._x509CertKeyElements.length; i++) { 143 this._x509certObject[i] = 144 new XMLX509Certificate(this._x509CertKeyElements[i] 145 , BaseURI); 146 } 147 148 for (int i = 0; i < this._x509certObject.length; i++) { 149 X509Certificate cert = this._x509certObject[i].getX509Certificate(); 150 151 if (cert != null) { 152 return cert; 153 } 154 } 155 156 return null; 157 } catch (XMLSecurityException ex) { 158 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex); 159 160 throw new KeyResolverException("generic.EmptyMessage", ex); 161 } 162 } 163 164 172 public javax.crypto.SecretKey engineResolveSecretKey( 173 Element element, String BaseURI, StorageResolver storage) 174 { 175 return null; 176 } 177 } 178 | Popular Tags |