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.x509.XMLX509Certificate; 31 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException; 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 * Resolves Certificates which are directly contained inside a 41 * <CODE>ds:X509Certificate</CODE> Element. 42 * 43 * @author $Author: mullan $ 44 */ 45 public class X509CertificateResolver extends KeyResolverSpi { 46 47 /** {@link java.util.logging} logging facility */ 48 static java.util.logging.Logger log = 49 java.util.logging.Logger.getLogger(X509CertificateResolver.class.getName()); 50 51 52 53 /** 54 * Method engineResolvePublicKey 55 * @inheritDoc 56 * @param element 57 * @param BaseURI 58 * @param storage 59 * 60 * @throws KeyResolverException 61 */ 62 public PublicKey engineLookupAndResolvePublicKey( 63 Element element, String BaseURI, StorageResolver storage) 64 throws KeyResolverException { 65 66 X509Certificate cert = this.engineLookupResolveX509Certificate(element, 67 BaseURI, storage); 68 69 if (cert != null) { 70 return cert.getPublicKey(); 71 } 72 73 return null; 74 } 75 76 /** 77 * Method engineResolveX509Certificate 78 * @inheritDoc 79 * @param element 80 * @param BaseURI 81 * @param storage 82 * 83 * @throws KeyResolverException 84 */ 85 public X509Certificate engineLookupResolveX509Certificate( 86 Element element, String BaseURI, StorageResolver storage) 87 throws KeyResolverException { 88 89 try { 90 Element[] els=XMLUtils.selectDsNodes(element.getFirstChild(), 91 Constants._TAG_X509CERTIFICATE); 92 if ((els == null) || (els.length == 0)) { 93 Element el=XMLUtils.selectDsNode(element.getFirstChild(), 94 Constants._TAG_X509DATA,0); 95 if (el!=null) { 96 return engineLookupResolveX509Certificate(el, BaseURI, storage); 97 } 98 return null; 99 } 100 101 // populate Object array 102 for (int i = 0; i < els.length; i++) { 103 XMLX509Certificate xmlCert=new XMLX509Certificate(els[i], BaseURI); 104 X509Certificate cert = xmlCert.getX509Certificate(); 105 if (cert!=null) { 106 return cert; 107 } 108 } 109 return null; 110 } catch (XMLSecurityException ex) { 111 log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex); 112 113 throw new KeyResolverException("generic.EmptyMessage", ex); 114 } 115 } 116 117 /** 118 * Method engineResolveSecretKey 119 * @inheritDoc 120 * @param element 121 * @param BaseURI 122 * @param storage 123 * 124 */ 125 public javax.crypto.SecretKey engineLookupAndResolveSecretKey( 126 Element element, String BaseURI, StorageResolver storage) 127 { 128 return null; 129 } 130 } | 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.PublicKey; 26 import java.security.cert.X509Certificate; 27 28 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 29 import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate; 30 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException; 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 * Resolves Certificates which are directly contained inside a 39 * <CODE>ds:X509Certificate</CODE> Element. 40 * 41 * @author $Author: coheigea $ 42 */ 43 public class X509CertificateResolver extends KeyResolverSpi { 44 45 /** {@link org.apache.commons.logging} logging facility */ 46 private static java.util.logging.Logger log = 47 java.util.logging.Logger.getLogger(X509CertificateResolver.class.getName()); 48 49 /** 50 * Method engineResolvePublicKey 51 * @inheritDoc 52 * @param element 53 * @param BaseURI 54 * @param storage 55 * 56 * @throws KeyResolverException 57 */ 58 public PublicKey engineLookupAndResolvePublicKey( 59 Element element, String BaseURI, StorageResolver storage 60 ) throws KeyResolverException { 61 62 X509Certificate cert = 63 this.engineLookupResolveX509Certificate(element, BaseURI, storage); 64 65 if (cert != null) { 66 return cert.getPublicKey(); 67 } 68 69 return null; 70 } 71 72 /** 73 * Method engineResolveX509Certificate 74 * @inheritDoc 75 * @param element 76 * @param BaseURI 77 * @param storage 78 * 79 * @throws KeyResolverException 80 */ 81 public X509Certificate engineLookupResolveX509Certificate( 82 Element element, String BaseURI, StorageResolver storage 83 ) throws KeyResolverException { 84 85 try { 86 Element[] els = 87 XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509CERTIFICATE); 88 if ((els == null) || (els.length == 0)) { 89 Element el = 90 XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_X509DATA, 0); 91 if (el != null) { 92 return engineLookupResolveX509Certificate(el, BaseURI, storage); 93 } 94 return null; 95 } 96 97 // populate Object array 98 for (int i = 0; i < els.length; i++) { 99 XMLX509Certificate xmlCert = new XMLX509Certificate(els[i], BaseURI); 100 X509Certificate cert = xmlCert.getX509Certificate(); 101 if (cert != null) { 102 return cert; 103 } 104 } 105 return null; 106 } catch (XMLSecurityException ex) { 107 if (log.isLoggable(java.util.logging.Level.FINE)) { 108 log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex); 109 } 110 throw new KeyResolverException("generic.EmptyMessage", ex); 111 } 112 } 113 114 /** 115 * Method engineResolveSecretKey 116 * @inheritDoc 117 * @param element 118 * @param BaseURI 119 * @param storage 120 */ 121 public javax.crypto.SecretKey engineLookupAndResolveSecretKey( 122 Element element, String BaseURI, StorageResolver storage 123 ) { 124 return null; 125 } 126 } |