1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /** 6 * Licensed to the Apache Software Foundation (ASF) under one 7 * or more contributor license agreements. See the NOTICE file 8 * distributed with this work for additional information 9 * regarding copyright ownership. The ASF licenses this file 10 * to you under the Apache License, Version 2.0 (the 11 * "License"); you may not use this file except in compliance 12 * with the License. You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, 17 * software distributed under the License is distributed on an 18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 * KIND, either express or implied. See the License for the 20 * specific language governing permissions and limitations 21 * under the License. 22 */ 23 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; 24 25 import java.security.PrivateKey; 26 import java.security.PublicKey; 27 import java.security.cert.X509Certificate; 28 29 import javax.crypto.SecretKey; 30 31 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 32 import com.sun.org.apache.xml.internal.security.keys.content.DEREncodedKeyValue; 33 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException; 34 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; 35 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 36 import com.sun.org.apache.xml.internal.security.utils.Constants; 37 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 38 import org.w3c.dom.Element; 39 40 /** 41 * KeyResolverSpi implementation which resolves public keys from a 42 * {@code dsig11:DEREncodedKeyValue} element. 43 * 44 */ 45 public class DEREncodedKeyValueResolver extends KeyResolverSpi { 46 47 private static final com.sun.org.slf4j.internal.Logger LOG = 48 com.sun.org.slf4j.internal.LoggerFactory.getLogger(DEREncodedKeyValueResolver.class); 49 50 /** {{@inheritDoc}}. */ engineCanResolve(Element element, String baseURI, StorageResolver storage)51 public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) { 52 return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_DERENCODEDKEYVALUE); 53 } 54 55 /** {{@inheritDoc}}. */ engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)56 public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage) 57 throws KeyResolverException { 58 59 LOG.debug("Can I resolve {}", element.getTagName()); 60 61 if (!engineCanResolve(element, baseURI, storage)) { 62 return null; 63 } 64 65 try { 66 DEREncodedKeyValue derKeyValue = new DEREncodedKeyValue(element, baseURI); 67 return derKeyValue.getPublicKey(); 68 } catch (XMLSecurityException e) { 69 LOG.debug("XMLSecurityException", e); 70 } 71 72 return null; 73 } 74 75 /** {{@inheritDoc}}. */ engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)76 public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage) 77 throws KeyResolverException { 78 return null; 79 } 80 81 /** {{@inheritDoc}}. */ engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)82 public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage) 83 throws KeyResolverException { 84 return null; 85 } 86 87 /** {{@inheritDoc}}. */ engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)88 public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage) 89 throws KeyResolverException { 90 return null; 91 } 92 93 94 95 } 96