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 | * Copyright 1999-2004 The Apache Software Foundation. |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | * |
| 20 | */ |
| 21 | package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; |
| 22 | |
| 23 | |
| 24 | |
| 25 | import java.security.PublicKey; |
| 26 | import java.security.cert.X509Certificate; |
| 27 | |
| 28 | |
| 29 | import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; |
| 30 | import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue; |
| 31 | import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; |
| 32 | import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; |
| 33 | import com.sun.org.apache.xml.internal.security.utils.Constants; |
| 34 | import com.sun.org.apache.xml.internal.security.utils.XMLUtils; |
| 35 | import org.w3c.dom.Element; |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * |
| 40 | * @author $Author: raul $ |
| 41 | */ |
| 42 | public class DSAKeyValueResolver extends KeyResolverSpi { |
| 43 | |
| 44 | /** Field _dsaKeyElement */ |
| 45 | private Element _dsaKeyElement = null; |
| 46 | |
| 47 | /** @inheritDoc */ |
| 48 | public boolean engineCanResolve(Element element, String BaseURI, |
| 49 | StorageResolver storage) { |
| 50 | |
| 51 | if (element == null) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, |
| 56 | Constants._TAG_KEYVALUE); |
| 57 | boolean isDSAKeyValue = XMLUtils.elementIsInSignatureSpace(element, |
| 58 | Constants._TAG_DSAKEYVALUE); |
| 59 | |
| 60 | if (isKeyValue) { |
| 61 | |
| 62 | this._dsaKeyElement = |
| 63 | XMLUtils.selectDsNode(element.getFirstChild(),Constants._TAG_DSAKEYVALUE,0); |
| 64 | |
| 65 | if (this._dsaKeyElement != null) { |
| 66 | return true; |
| 67 | } |
| 68 | } else if (isDSAKeyValue) { |
| 69 | |
| 70 | // this trick is needed to allow the RetrievalMethodResolver to eat a |
| 71 | // ds:DSAKeyValue directly (without KeyValue) |
| 72 | this._dsaKeyElement = element; |
| 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Method engineResolvePublicKey |
| 82 | * |
| 83 | * @param element |
| 84 | * @param BaseURI |
| 85 | * @param storage |
| 86 | * @return null if no {@link PublicKey} could be obtained |
| 87 | */ |
| 88 | public PublicKey engineResolvePublicKey( |
| 89 | Element element, String BaseURI, StorageResolver storage) { |
| 90 | |
| 91 | if (this._dsaKeyElement == null) { |
| 92 | boolean weCanResolve = this.engineCanResolve(element, BaseURI, |
| 93 | storage); |
| 94 | |
| 95 | if (!weCanResolve || (this._dsaKeyElement == null)) { |
| 96 | return null; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | try { |
| 101 | DSAKeyValue dsaKeyValue = new DSAKeyValue(this._dsaKeyElement, |
| 102 | BaseURI); |
| 103 | PublicKey pk = dsaKeyValue.getPublicKey(); |
| 104 | |
| 105 | return pk; |
| 106 | } catch (XMLSecurityException ex) { |
| 107 | //do nothing |
| 108 | } |
| 109 | |
| 110 | return null; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /** @inheritDoc */ |
| 115 | public X509Certificate engineResolveX509Certificate( |
| 116 | Element element, String BaseURI, StorageResolver storage) { |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | /** @inheritDoc */ |
| 121 | public javax.crypto.SecretKey engineResolveSecretKey( |
| 122 | Element element, String BaseURI, StorageResolver storage){ |
| 123 | return null; |
| 124 | } |
| 125 | } |