1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; 6 7 import java.security.PrivateKey; 8 import java.security.PublicKey; 9 import java.security.cert.X509Certificate; 10 11 import javax.crypto.SecretKey; 12 13 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 14 import com.sun.org.apache.xml.internal.security.keys.content.DEREncodedKeyValue; 15 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException; 16 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; 17 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 18 import com.sun.org.apache.xml.internal.security.utils.Constants; 19 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 20 import org.w3c.dom.Element; 21 22 /** 23 * KeyResolverSpi implementation which resolves public keys from a 24 * <code>dsig11:DEREncodedKeyValue</code> element. 25 * 26 * @author Brent Putman (putmanb@georgetown.edu) 27 */ 28 public class DEREncodedKeyValueResolver extends KeyResolverSpi { 29 30 /** {@link org.apache.commons.logging} logging facility */ 31 private static java.util.logging.Logger log = 32 java.util.logging.Logger.getLogger(DEREncodedKeyValueResolver.class.getName()); 33 34 /** {@inheritDoc}. */ 35 public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) { 36 return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_DERENCODEDKEYVALUE); 37 } 38 39 /** {@inheritDoc}. */ 40 public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage) 41 throws KeyResolverException { 42 43 if (log.isLoggable(java.util.logging.Level.FINE)) { 44 log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName()); 45 } 46 47 if (!engineCanResolve(element, baseURI, storage)) { 48 return null; 49 } 50 51 try { 52 DEREncodedKeyValue derKeyValue = new DEREncodedKeyValue(element, baseURI); 53 return derKeyValue.getPublicKey(); 54 } catch (XMLSecurityException e) { 55 if (log.isLoggable(java.util.logging.Level.FINE)) { 56 log.log(java.util.logging.Level.FINE, "XMLSecurityException", e); 57 } 58 } 59 60 return null; 61 } 62 63 /** {@inheritDoc}. */ 64 public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage) 65 throws KeyResolverException { 66 return null; 67 } 68 69 /** {@inheritDoc}. */ 70 public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage) 71 throws KeyResolverException { 72 return null; 73 } 74 75 /** {@inheritDoc}. */ 76 public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage) 77 throws KeyResolverException { 78 return null; 79 } 80 81 82 83 }