J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * reserved comment block |
| 3 | * DO NOT REMOVE OR ALTER! |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Copyright 1999-2004 The Apache Software Foundation. |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | */ |
| 22 | package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; |
| 23 | |
| 24 | |
| 25 | |
| 26 | import java.security.PublicKey; |
| 27 | import java.security.cert.X509Certificate; |
| 28 | |
| 29 | |
| 30 | import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; |
| 31 | import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue; |
| 32 | import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; |
| 33 | import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; |
| 34 | import com.sun.org.apache.xml.internal.security.utils.Constants; |
| 35 | import com.sun.org.apache.xml.internal.security.utils.XMLUtils; |
| 36 | import org.w3c.dom.Element; |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * |
| 41 | * @author $Author: raul $ |
| 42 | */ |
| 43 | public class RSAKeyValueResolver extends KeyResolverSpi { |
| 44 | |
| 45 | /** {@link java.util.logging} logging facility */ |
| 46 | static java.util.logging.Logger log = |
| 47 | java.util.logging.Logger.getLogger( |
| 48 | RSAKeyValueResolver.class.getName()); |
| 49 | |
| 50 | /** Field _rsaKeyElement */ |
| 51 | private Element _rsaKeyElement = null; |
| 52 | |
| 53 | /** @inheritDoc */ |
| 54 | public boolean engineCanResolve(Element element, String BaseURI, |
| 55 | StorageResolver storage) { |
| 56 | if (true) |
| 57 | if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName()); |
| 58 | |
| 59 | if (element == null) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, |
| 64 | Constants._TAG_KEYVALUE); |
| 65 | boolean isRSAKeyValue = XMLUtils.elementIsInSignatureSpace(element, |
| 66 | Constants._TAG_RSAKEYVALUE); |
| 67 | |
| 68 | if (isKeyValue) { |
| 69 | this._rsaKeyElement = XMLUtils.selectDsNode(element.getFirstChild(), |
| 70 | Constants._TAG_RSAKEYVALUE, 0); |
| 71 | |
| 72 | if (this._rsaKeyElement != null) { |
| 73 | return true; |
| 74 | } |
| 75 | } else if (isRSAKeyValue) { |
| 76 | |
| 77 | // this trick is needed to allow the RetrievalMethodResolver to eat a |
| 78 | // ds:RSAKeyValue directly (without KeyValue) |
| 79 | this._rsaKeyElement = element; |
| 80 | |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | /** @inheritDoc */ |
| 88 | public PublicKey engineResolvePublicKey( |
| 89 | Element element, String BaseURI, StorageResolver storage) { |
| 90 | |
| 91 | if (this._rsaKeyElement == null) { |
| 92 | boolean weCanResolve = this.engineCanResolve(element, BaseURI, |
| 93 | storage); |
| 94 | |
| 95 | if (!weCanResolve || (this._rsaKeyElement == null)) { |
| 96 | return null; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | try { |
| 101 | RSAKeyValue rsaKeyValue = new RSAKeyValue(this._rsaKeyElement, |
| 102 | BaseURI); |
| 103 | |
| 104 | return rsaKeyValue.getPublicKey(); |
| 105 | } catch (XMLSecurityException ex) { |
| 106 | if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex); |
| 107 | } |
| 108 | |
| 109 | return null; |
| 110 | } |
| 111 | |
| 112 | /** @inheritDoc */ |
| 113 | public X509Certificate engineResolveX509Certificate( |
| 114 | Element element, String BaseURI, StorageResolver storage) { |
| 115 | return null; |
| 116 | } |
| 117 | |
| 118 | /** @inheritDoc */ |
| 119 | public javax.crypto.SecretKey engineResolveSecretKey( |
| 120 | Element element, String BaseURI, StorageResolver storage) { |
| 121 | return null; |
| 122 | } |
| 123 | } |