0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * Copyright 1999-2004 The Apache Software Foundation.
0N/A *
0N/A * Licensed under the Apache License, Version 2.0 (the "License");
0N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A *
0N/A */
0N/Apackage com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
0N/A
0N/A
0N/A
0N/Aimport java.security.PublicKey;
0N/Aimport java.security.cert.X509Certificate;
0N/A
0N/A
0N/Aimport com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.Constants;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.XMLUtils;
0N/Aimport org.w3c.dom.Element;
0N/A
0N/A
0N/A/**
0N/A *
0N/A *
661N/A * @author $Author: mullan $
0N/A */
0N/Apublic class X509SKIResolver extends KeyResolverSpi {
0N/A
0N/A /** {@link java.util.logging} logging facility */
0N/A static java.util.logging.Logger log =
0N/A java.util.logging.Logger.getLogger(X509SKIResolver.class.getName());
0N/A
0N/A
0N/A /**
0N/A * Method engineResolvePublicKey
0N/A *
0N/A * @param element
0N/A * @param BaseURI
0N/A * @param storage
0N/A * @return null if no {@link PublicKey} could be obtained
0N/A * @throws KeyResolverException
0N/A */
661N/A public PublicKey engineLookupAndResolvePublicKey(
0N/A Element element, String BaseURI, StorageResolver storage)
0N/A throws KeyResolverException {
0N/A
661N/A X509Certificate cert = this.engineLookupResolveX509Certificate(element,
0N/A BaseURI, storage);
0N/A
0N/A if (cert != null) {
0N/A return cert.getPublicKey();
0N/A }
0N/A
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Method engineResolveX509Certificate
0N/A * @inheritDoc
0N/A * @param element
0N/A * @param BaseURI
0N/A * @param storage
0N/A *
0N/A * @throws KeyResolverException
0N/A */
661N/A public X509Certificate engineLookupResolveX509Certificate(
0N/A Element element, String BaseURI, StorageResolver storage)
0N/A throws KeyResolverException {
661N/A if (log.isLoggable(java.util.logging.Level.FINE)) {
661N/A log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
661N/A }
661N/A if (!XMLUtils.elementIsInSignatureSpace(element,
661N/A Constants._TAG_X509DATA)) {
661N/A log.log(java.util.logging.Level.FINE, "I can't");
661N/A return null;
661N/A }
661N/A /** Field _x509childObject[] */
661N/A XMLX509SKI x509childObject[] = null;
0N/A
661N/A Element x509childNodes[] = null;
661N/A x509childNodes = XMLUtils.selectDsNodes(element.getFirstChild(),
661N/A Constants._TAG_X509SKI);
0N/A
661N/A if (!((x509childNodes != null)
661N/A && (x509childNodes.length > 0))) {
661N/A log.log(java.util.logging.Level.FINE, "I can't");
661N/A return null;
661N/A }
661N/A try {
0N/A if (storage == null) {
0N/A Object exArgs[] = { Constants._TAG_X509SKI };
0N/A KeyResolverException ex =
0N/A new KeyResolverException("KeyResolver.needStorageResolver",
0N/A exArgs);
0N/A
661N/A log.log(java.util.logging.Level.INFO, "", ex);
0N/A
0N/A throw ex;
0N/A }
0N/A
661N/A x509childObject = new XMLX509SKI[x509childNodes.length];
0N/A
661N/A for (int i = 0; i < x509childNodes.length; i++) {
661N/A x509childObject[i] =
661N/A new XMLX509SKI(x509childNodes[i], BaseURI);
0N/A }
0N/A
0N/A while (storage.hasNext()) {
0N/A X509Certificate cert = storage.next();
0N/A XMLX509SKI certSKI = new XMLX509SKI(element.getOwnerDocument(), cert);
0N/A
661N/A for (int i = 0; i < x509childObject.length; i++) {
661N/A if (certSKI.equals(x509childObject[i])) {
661N/A log.log(java.util.logging.Level.FINE, "Return PublicKey from "
0N/A + cert.getSubjectDN().getName());
0N/A
0N/A return cert;
0N/A }
0N/A }
0N/A }
0N/A } catch (XMLSecurityException ex) {
0N/A throw new KeyResolverException("empty", ex);
0N/A }
0N/A
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Method engineResolveSecretKey
0N/A * @inheritDoc
0N/A * @param element
0N/A * @param BaseURI
0N/A * @param storage
0N/A *
0N/A */
661N/A public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
0N/A Element element, String BaseURI, StorageResolver storage)
0N/A {
0N/A return null;
0N/A }
0N/A}