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 */ 23package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; 24 25import java.security.PublicKey; 26import java.security.cert.X509Certificate; 27 28 29import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 30import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue; 31import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; 32import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 33import com.sun.org.apache.xml.internal.security.utils.Constants; 34import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 35import org.w3c.dom.Element; 36 37public class RSAKeyValueResolver extends KeyResolverSpi { 38 39 /** {@link org.apache.commons.logging} logging facility */ 40 private static java.util.logging.Logger log = 41 java.util.logging.Logger.getLogger(RSAKeyValueResolver.class.getName()); 42 43 44 /** @inheritDoc */ 45 public PublicKey engineLookupAndResolvePublicKey( 46 Element element, String BaseURI, StorageResolver storage 47 ) { 48 if (log.isLoggable(java.util.logging.Level.FINE)) { 49 log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName()); 50 } 51 if (element == null) { 52 return null; 53 } 54 55 boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE); 56 Element rsaKeyElement = null; 57 if (isKeyValue) { 58 rsaKeyElement = 59 XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0); 60 } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RSAKEYVALUE)) { 61 // this trick is needed to allow the RetrievalMethodResolver to eat a 62 // ds:RSAKeyValue directly (without KeyValue) 63 rsaKeyElement = element; 64 } 65 66 if (rsaKeyElement == null) { 67 return null; 68 } 69 70 try { 71 RSAKeyValue rsaKeyValue = new RSAKeyValue(rsaKeyElement, BaseURI); 72 73 return rsaKeyValue.getPublicKey(); 74 } catch (XMLSecurityException ex) { 75 if (log.isLoggable(java.util.logging.Level.FINE)) { 76 log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex); 77 } 78 } 79 80 return null; 81 } 82 83 /** @inheritDoc */ 84 public X509Certificate engineLookupResolveX509Certificate( 85 Element element, String BaseURI, StorageResolver storage 86 ) { 87 return null; 88 } 89 90 /** @inheritDoc */ 91 public javax.crypto.SecretKey engineLookupAndResolveSecretKey( 92 Element element, String BaseURI, StorageResolver storage 93 ) { 94 return null; 95 } 96} 97