1 17 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; 18 19 20 21 import java.security.PublicKey ; 22 import java.security.cert.X509Certificate ; 23 24 25 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 26 import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SubjectName; 27 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException; 28 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; 29 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 30 import com.sun.org.apache.xml.internal.security.utils.Constants; 31 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 32 import org.w3c.dom.Element ; 33 34 35 39 public class X509SubjectNameResolver extends KeyResolverSpi { 40 41 42 static java.util.logging.Logger log = 43 java.util.logging.Logger.getLogger( 44 X509SubjectNameResolver.class.getName()); 45 46 47 private Element [] _x509childNodes = null; 48 49 50 private XMLX509SubjectName _x509childObject[] = null; 51 52 60 public boolean engineCanResolve(Element element, String BaseURI, 61 StorageResolver storage) { 62 if (true) 63 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?"); 64 65 66 if (!XMLUtils.elementIsInSignatureSpace(element, 67 Constants._TAG_X509DATA) ) { 68 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 69 70 return false; 71 } 72 73 74 75 this._x509childNodes = XMLUtils.selectDsNodes(element, 76 Constants._TAG_X509SUBJECTNAME); 77 78 if ((this._x509childNodes != null) 79 && (this._x509childNodes.length > 0)) { 80 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Yes Sir, I can"); 81 82 return true; 83 } 84 85 86 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 87 88 return false; 89 } 90 91 100 public PublicKey engineResolvePublicKey( 101 Element element, String BaseURI, StorageResolver storage) 102 throws KeyResolverException { 103 104 X509Certificate cert = this.engineResolveX509Certificate(element, 105 BaseURI, storage); 106 107 if (cert != null) { 108 return cert.getPublicKey(); 109 } 110 111 return null; 112 } 113 114 123 public X509Certificate engineResolveX509Certificate( 124 Element element, String BaseURI, StorageResolver storage) 125 throws KeyResolverException { 126 127 try { 128 if (this._x509childNodes == null) { 129 boolean weCanResolve = this.engineCanResolve(element, BaseURI, 130 storage); 131 132 if (!weCanResolve || (this._x509childNodes == null)) { 133 return null; 134 } 135 } 136 137 if (storage == null) { 138 Object exArgs[] = { Constants._TAG_X509SUBJECTNAME }; 139 KeyResolverException ex = 140 new KeyResolverException("KeyResolver.needStorageResolver", 141 exArgs); 142 143 if (log.isLoggable(java.util.logging.Level.INFO)) log.log(java.util.logging.Level.INFO, "", ex); 144 145 throw ex; 146 } 147 148 this._x509childObject = 149 new XMLX509SubjectName[this._x509childNodes.length]; 150 151 for (int i = 0; i < this._x509childNodes.length; i++) { 152 this._x509childObject[i] = 153 new XMLX509SubjectName(this._x509childNodes[i], 154 BaseURI); 155 } 156 157 while (storage.hasNext()) { 158 X509Certificate cert = storage.next(); 159 XMLX509SubjectName certSN = 160 new XMLX509SubjectName(element.getOwnerDocument(), cert); 161 162 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Found Certificate SN: " + certSN.getSubjectName()); 163 164 for (int i = 0; i < this._x509childObject.length; i++) { 165 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Found Element SN: " 166 + this._x509childObject[i].getSubjectName()); 167 168 if (certSN.equals(this._x509childObject[i])) { 169 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "match !!! "); 170 171 return cert; 172 } 173 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "no match..."); 174 } 175 } 176 177 return null; 178 } catch (XMLSecurityException ex) { 179 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex); 180 181 throw new KeyResolverException("generic.EmptyMessage", ex); 182 } 183 } 184 185 193 public javax.crypto.SecretKey engineResolveSecretKey( 194 Element element, String BaseURI, StorageResolver storage) 195 { 196 return null; 197 } 198 } 199 | Popular Tags |