src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/DSAKeyValueResolver.java

Print this page


   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: mullan $
  41  */
  42 public class DSAKeyValueResolver extends KeyResolverSpi {
  43 





  44    /**
  45     * Method engineResolvePublicKey
  46     *
  47     * @param element
  48     * @param BaseURI
  49     * @param storage
  50     * @return null if no {@link PublicKey} could be obtained
  51     */
  52    public PublicKey engineLookupAndResolvePublicKey(
  53            Element element, String BaseURI, StorageResolver storage) {

  54             if (element == null) {
  55                  return null;
  56             }
  57             Element dsaKeyElement=null;
  58             boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element,
  59                                       Constants._TAG_KEYVALUE);
  60             if (isKeyValue) {
  61                 dsaKeyElement =
  62                         XMLUtils.selectDsNode(element.getFirstChild(),Constants._TAG_DSAKEYVALUE,0);
  63        } else if (XMLUtils.elementIsInSignatureSpace(element,
  64                Constants._TAG_DSAKEYVALUE)) {
  65                  // this trick is needed to allow the RetrievalMethodResolver to eat a
  66                  // ds:DSAKeyValue directly (without KeyValue)
  67                  dsaKeyElement = element;
  68             }
  69 
  70       if (dsaKeyElement == null) {
  71                     return null;
  72       }
  73 
  74       try {
  75          DSAKeyValue dsaKeyValue = new DSAKeyValue(dsaKeyElement,
  76                                                    BaseURI);
  77          PublicKey pk = dsaKeyValue.getPublicKey();
  78 
  79          return pk;
  80       } catch (XMLSecurityException ex) {



  81                 //do nothing
  82       }
  83 
  84       return null;
  85    }
  86 
  87 
  88    /** @inheritDoc */
  89    public X509Certificate engineLookupResolveX509Certificate(
  90            Element element, String BaseURI, StorageResolver storage) {

  91       return null;
  92    }
  93 
  94    /** @inheritDoc */
  95    public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
  96            Element element, String BaseURI, StorageResolver storage){

  97       return null;
  98    }
  99 }
   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.keyvalues.DSAKeyValue;
  30 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
  31 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
  32 import com.sun.org.apache.xml.internal.security.utils.Constants;
  33 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
  34 import org.w3c.dom.Element;
  35 





  36 public class DSAKeyValueResolver extends KeyResolverSpi {
  37     
  38     /** {@link org.apache.commons.logging} logging facility */
  39     private static java.util.logging.Logger log = 
  40         java.util.logging.Logger.getLogger(DSAKeyValueResolver.class.getName());
  41 
  42 
  43     /**
  44      * Method engineResolvePublicKey
  45      *
  46      * @param element
  47      * @param BaseURI
  48      * @param storage
  49      * @return null if no {@link PublicKey} could be obtained
  50      */
  51     public PublicKey engineLookupAndResolvePublicKey(
  52         Element element, String BaseURI, StorageResolver storage
  53     ) {
  54         if (element == null) {
  55             return null;
  56         }
  57         Element dsaKeyElement = null;
  58         boolean isKeyValue = 
  59             XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
  60         if (isKeyValue) {                    
  61             dsaKeyElement =
  62                 XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);                    
  63         } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_DSAKEYVALUE)) {

  64             // this trick is needed to allow the RetrievalMethodResolver to eat a
  65             // ds:DSAKeyValue directly (without KeyValue)
  66             dsaKeyElement = element;
  67         }             
  68 
  69         if (dsaKeyElement == null) {
  70             return null;
  71         }
  72 
  73         try {
  74             DSAKeyValue dsaKeyValue = new DSAKeyValue(dsaKeyElement, BaseURI);

  75             PublicKey pk = dsaKeyValue.getPublicKey();
  76 
  77             return pk;
  78         } catch (XMLSecurityException ex) {
  79             if (log.isLoggable(java.util.logging.Level.FINE)) {
  80                 log.log(java.util.logging.Level.FINE, ex.getMessage(), ex);
  81             }
  82             //do nothing
  83         }
  84 
  85         return null;
  86     }
  87 
  88 
  89     /** @inheritDoc */
  90     public X509Certificate engineLookupResolveX509Certificate(
  91         Element element, String BaseURI, StorageResolver storage
  92     ) {
  93         return null;
  94     }
  95 
  96     /** @inheritDoc */
  97     public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
  98         Element element, String BaseURI, StorageResolver storage
  99     ) {
 100         return null;
 101     }
 102 }