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/Aimport com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.content.X509Data;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509IssuerSerial;
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.signature.XMLSignatureException;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.Constants;
0N/Aimport org.w3c.dom.Element;
0N/A
0N/A
0N/A/**
0N/A *
661N/A * @author $Author: mullan $
0N/A */
0N/Apublic class X509IssuerSerialResolver 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(
0N/A X509IssuerSerialResolver.class.getName());
0N/A
0N/A
0N/A /** @inheritDoc */
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 /** @inheritDoc */
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() + "?");
0N/A
661N/A X509Data x509data = null;
661N/A try {
661N/A x509data = new X509Data(element, BaseURI);
661N/A } catch (XMLSignatureException ex) {
661N/A log.log(java.util.logging.Level.FINE, "I can't");
661N/A return null;
661N/A } catch (XMLSecurityException ex) {
661N/A log.log(java.util.logging.Level.FINE, "I can't");
661N/A return null;
661N/A }
661N/A
661N/A if (x509data == null) {
661N/A log.log(java.util.logging.Level.FINE, "I can't");
661N/A return null;
661N/A }
661N/A
661N/A if (!x509data.containsIssuerSerial()) {
661N/A return null;
661N/A }
0N/A try {
0N/A if (storage == null) {
0N/A Object exArgs[] = { Constants._TAG_X509ISSUERSERIAL };
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 throw ex;
0N/A }
0N/A
0N/A int noOfISS = x509data.lengthIssuerSerial();
0N/A
0N/A while (storage.hasNext()) {
0N/A X509Certificate cert = storage.next();
0N/A XMLX509IssuerSerial certSerial = new XMLX509IssuerSerial(element.getOwnerDocument(), cert);
0N/A
661N/A if (log.isLoggable(java.util.logging.Level.FINE)) {
661N/A log.log(java.util.logging.Level.FINE, "Found Certificate Issuer: "
0N/A + certSerial.getIssuerName());
661N/A log.log(java.util.logging.Level.FINE, "Found Certificate Serial: "
0N/A + certSerial.getSerialNumber().toString());
0N/A }
0N/A
0N/A for (int i=0; i<noOfISS; i++) {
0N/A XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i);
0N/A
661N/A if (log.isLoggable(java.util.logging.Level.FINE)) {
661N/A log.log(java.util.logging.Level.FINE, "Found Element Issuer: "
0N/A + xmliss.getIssuerName());
661N/A log.log(java.util.logging.Level.FINE, "Found Element Serial: "
0N/A + xmliss.getSerialNumber().toString());
0N/A }
0N/A
0N/A if (certSerial.equals(xmliss)) {
661N/A log.log(java.util.logging.Level.FINE, "match !!! ");
0N/A
0N/A return cert;
0N/A }
661N/A log.log(java.util.logging.Level.FINE, "no match...");
0N/A }
0N/A }
0N/A
0N/A return null;
0N/A } catch (XMLSecurityException ex) {
661N/A log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
0N/A
0N/A throw new KeyResolverException("generic.EmptyMessage", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
661N/A public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
0N/A Element element, String BaseURI, StorageResolver storage) {
0N/A return null;
0N/A }
0N/A}