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 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 26 import com.sun.org.apache.xml.internal.security.keys.content.X509Data; 27 import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509IssuerSerial; 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.signature.XMLSignatureException; 32 import com.sun.org.apache.xml.internal.security.utils.Constants; 33 import org.w3c.dom.Element ; 34 35 36 40 public class X509IssuerSerialResolver extends KeyResolverSpi { 41 42 43 static java.util.logging.Logger log = 44 java.util.logging.Logger.getLogger( 45 X509IssuerSerialResolver.class.getName()); 46 47 48 public boolean engineCanResolve(Element element, String BaseURI, 49 StorageResolver storage) { 50 if (true) 51 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?"); 52 53 X509Data x509data = null; 54 try { 55 x509data = new X509Data(element, BaseURI); 56 } catch (XMLSignatureException ex) { 57 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 58 59 return false; 60 } catch (XMLSecurityException ex) { 61 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 62 63 return false; 64 } 65 66 if (x509data == null) { 67 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 68 return false; 69 } 70 71 if (x509data.containsIssuerSerial()) { 72 return true; 73 } 74 75 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I can't"); 76 return false; 77 } 78 79 80 public PublicKey engineResolvePublicKey( 81 Element element, String BaseURI, StorageResolver storage) 82 throws KeyResolverException { 83 84 X509Certificate cert = this.engineResolveX509Certificate(element, 85 BaseURI, storage); 86 87 if (cert != null) { 88 return cert.getPublicKey(); 89 } 90 91 return null; 92 } 93 94 95 public X509Certificate engineResolveX509Certificate( 96 Element element, String BaseURI, StorageResolver storage) 97 throws KeyResolverException { 98 99 try { 100 if (storage == null) { 101 Object exArgs[] = { Constants._TAG_X509ISSUERSERIAL }; 102 KeyResolverException ex = 103 new KeyResolverException("KeyResolver.needStorageResolver", 104 exArgs); 105 106 if (log.isLoggable(java.util.logging.Level.INFO)) log.log(java.util.logging.Level.INFO, "", ex); 107 throw ex; 108 } 109 110 X509Data x509data = new X509Data(element, BaseURI); 111 int noOfISS = x509data.lengthIssuerSerial(); 112 113 while (storage.hasNext()) { 114 X509Certificate cert = storage.next(); 115 XMLX509IssuerSerial certSerial = new XMLX509IssuerSerial(element.getOwnerDocument(), cert); 116 117 if (true) { 118 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Found Certificate Issuer: " 119 + certSerial.getIssuerName()); 120 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Found Certificate Serial: " 121 + certSerial.getSerialNumber().toString()); 122 } 123 124 for (int i=0; i<noOfISS; i++) { 125 XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i); 126 127 if (true) { 128 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Found Element Issuer: " 129 + xmliss.getIssuerName()); 130 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Found Element Serial: " 131 + xmliss.getSerialNumber().toString()); 132 } 133 134 if (certSerial.equals(xmliss)) { 135 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "match !!! "); 136 137 return cert; 138 } 139 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "no match..."); 140 } 141 } 142 143 return null; 144 } catch (XMLSecurityException ex) { 145 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex); 146 147 throw new KeyResolverException("generic.EmptyMessage", ex); 148 } 149 } 150 151 152 public javax.crypto.SecretKey engineResolveSecretKey( 153 Element element, String BaseURI, StorageResolver storage) { 154 return null; 155 } 156 } 157 | Popular Tags |