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.XMLX509SKI; 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 41 public class X509SKIResolver extends KeyResolverSpi { 42 43 44 static java.util.logging.Logger log = 45 java.util.logging.Logger.getLogger(X509SKIResolver.class.getName()); 46 47 48 private Element _x509childNodes[] = null; 49 50 51 private XMLX509SKI _x509childObject[] = null; 52 53 61 public boolean engineCanResolve(Element element, String BaseURI, 62 StorageResolver storage) { 63 if (true) { 64 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?"); 65 } 66 67 if (!XMLUtils.elementIsInSignatureSpace(element, 68 Constants._TAG_X509DATA)) { 69 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 70 71 return false; 72 } 73 74 75 76 77 this._x509childNodes = XMLUtils.selectDsNodes(element, 78 Constants._TAG_X509SKI); 79 80 if ((this._x509childNodes != null) 81 && (this._x509childNodes.length > 0)) { 82 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Yes Sir, I can"); 83 84 return true; 85 } 86 87 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 88 89 return false; 90 } 91 92 101 public PublicKey engineResolvePublicKey( 102 Element element, String BaseURI, StorageResolver storage) 103 throws KeyResolverException { 104 105 X509Certificate cert = this.engineResolveX509Certificate(element, 106 BaseURI, storage); 107 108 if (cert != null) { 109 return cert.getPublicKey(); 110 } 111 112 return null; 113 } 114 115 124 public X509Certificate engineResolveX509Certificate( 125 Element element, String BaseURI, StorageResolver storage) 126 throws KeyResolverException { 127 128 try { 129 if (this._x509childNodes == null) { 130 boolean weCanResolve = this.engineCanResolve(element, BaseURI, 131 storage); 132 133 if (!weCanResolve || (this._x509childNodes == null)) { 134 return null; 135 } 136 } 137 138 if (storage == null) { 139 Object exArgs[] = { Constants._TAG_X509SKI }; 140 KeyResolverException ex = 141 new KeyResolverException("KeyResolver.needStorageResolver", 142 exArgs); 143 144 if (log.isLoggable(java.util.logging.Level.INFO)) log.log(java.util.logging.Level.INFO, "", ex); 145 146 throw ex; 147 } 148 149 this._x509childObject = 150 new XMLX509SKI[this._x509childNodes.length]; 151 152 for (int i = 0; i < this._x509childNodes.length; i++) { 153 this._x509childObject[i] = 154 new XMLX509SKI(this._x509childNodes[i], BaseURI); 155 } 156 157 while (storage.hasNext()) { 158 X509Certificate cert = storage.next(); 159 XMLX509SKI certSKI = new XMLX509SKI(element.getOwnerDocument(), cert); 160 161 for (int i = 0; i < this._x509childObject.length; i++) { 162 if (certSKI.equals(this._x509childObject[i])) { 163 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Return PublicKey from " 164 + cert.getSubjectDN().getName()); 165 166 return cert; 167 } 168 } 169 } 170 } catch (XMLSecurityException ex) { 171 throw new KeyResolverException("empty", ex); 172 } 173 174 return null; 175 } 176 177 185 public javax.crypto.SecretKey engineResolveSecretKey( 186 Element element, String BaseURI, StorageResolver storage) 187 { 188 return null; 189 } 190 } 191 | Popular Tags |