| 
 | 
 | 
 | 
 | 
 | 
 | 
 */  | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 */  | 
 | 
package com.sun.org.apache.xml.internal.security.keys;  | 
 | 
 | 
 | 
import java.security.PrivateKey;  | 
 | 
import java.security.PublicKey;  | 
 | 
import java.security.cert.X509Certificate;  | 
 | 
import java.util.ArrayList;  | 
 | 
import java.util.Iterator;  | 
 | 
import java.util.List;  | 
 | 
 | 
 | 
import javax.crypto.SecretKey;  | 
 | 
 | 
 | 
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.DEREncodedKeyValue;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.KeyInfoReference;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.KeyName;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.KeyValue;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.MgmtData;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.PGPData;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.SPKIData;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.X509Data;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;  | 
 | 
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;  | 
 | 
import com.sun.org.apache.xml.internal.security.transforms.Transforms;  | 
 | 
import com.sun.org.apache.xml.internal.security.utils.Constants;  | 
 | 
import com.sun.org.apache.xml.internal.security.utils.ElementProxy;  | 
 | 
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;  | 
 | 
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;  | 
 | 
import org.w3c.dom.Attr;  | 
 | 
import org.w3c.dom.Document;  | 
 | 
import org.w3c.dom.Element;  | 
 | 
import org.w3c.dom.Node;  | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 */  | 
 | 
public class KeyInfo extends SignatureElementProxy { | 
 | 
 | 
 | 
    private static final com.sun.org.slf4j.internal.Logger LOG =  | 
 | 
        com.sun.org.slf4j.internal.LoggerFactory.getLogger(KeyInfo.class);  | 
 | 
 | 
 | 
    // We need at least one StorageResolver otherwise  | 
 | 
    // the KeyResolvers would not be called.  | 
 | 
    // The default StorageResolver is null.  | 
 | 
 | 
 | 
    private List<X509Data> x509Datas;  | 
 | 
 | 
 | 
    private static final List<StorageResolver> nullList;  | 
 | 
    static { | 
 | 
        List<StorageResolver> list = new ArrayList<>(1);  | 
 | 
        list.add(null);  | 
 | 
        nullList = java.util.Collections.unmodifiableList(list);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
    private List<StorageResolver> storageResolvers = nullList;  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
     */  | 
 | 
    private List<KeyResolverSpi> internalKeyResolvers = new ArrayList<>();  | 
 | 
 | 
 | 
    private boolean secureValidation;  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public KeyInfo(Document doc) { | 
 | 
        super(doc);  | 
 | 
        addReturnToSelf();  | 
 | 
 | 
 | 
        String prefix = ElementProxy.getDefaultPrefix(this.getBaseNamespace());  | 
 | 
        if (prefix != null && prefix.length() > 0) { | 
 | 
            getElement().setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix,  | 
 | 
                                        this.getBaseNamespace());  | 
 | 
        }  | 
 | 
 | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public KeyInfo(Element element, String baseURI) throws XMLSecurityException { | 
 | 
        super(element, baseURI);  | 
 | 
 | 
 | 
        Attr attr = element.getAttributeNodeNS(null, "Id");  | 
 | 
        if (attr != null) { | 
 | 
            element.setIdAttributeNode(attr, true);  | 
 | 
        }  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
     */  | 
 | 
    public void setSecureValidation(boolean secureValidation) { | 
 | 
        this.secureValidation = secureValidation;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void setId(String id) { | 
 | 
        if (id != null) { | 
 | 
            setLocalIdAttribute(Constants._ATT_ID, id);  | 
 | 
        }  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public String getId() { | 
 | 
        return getLocalAttribute(Constants._ATT_ID);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addKeyName(String keynameString) { | 
 | 
        this.add(new KeyName(getDocument(), keynameString));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(KeyName keyname) { | 
 | 
        appendSelf(keyname);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addKeyValue(PublicKey pk) { | 
 | 
        this.add(new KeyValue(getDocument(), pk));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addKeyValue(Element unknownKeyValueElement) { | 
 | 
        this.add(new KeyValue(getDocument(), unknownKeyValueElement));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(DSAKeyValue dsakeyvalue) { | 
 | 
        this.add(new KeyValue(getDocument(), dsakeyvalue));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(RSAKeyValue rsakeyvalue) { | 
 | 
        this.add(new KeyValue(getDocument(), rsakeyvalue));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(PublicKey pk) { | 
 | 
        this.add(new KeyValue(getDocument(), pk));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(KeyValue keyvalue) { | 
 | 
        appendSelf(keyvalue);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addMgmtData(String mgmtdata) { | 
 | 
        this.add(new MgmtData(getDocument(), mgmtdata));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(MgmtData mgmtdata) { | 
 | 
        appendSelf(mgmtdata);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(PGPData pgpdata) { | 
 | 
        appendSelf(pgpdata);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addRetrievalMethod(String uri, Transforms transforms, String Type) { | 
 | 
        this.add(new RetrievalMethod(getDocument(), uri, transforms, Type));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(RetrievalMethod retrievalmethod) { | 
 | 
        appendSelf(retrievalmethod);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(SPKIData spkidata) { | 
 | 
        appendSelf(spkidata);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(X509Data x509data) { | 
 | 
        if (x509Datas == null) { | 
 | 
            x509Datas = new ArrayList<>();  | 
 | 
        }  | 
 | 
        x509Datas.add(x509data);  | 
 | 
        appendSelf(x509data);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addDEREncodedKeyValue(PublicKey pk) throws XMLSecurityException { | 
 | 
        this.add(new DEREncodedKeyValue(getDocument(), pk));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(DEREncodedKeyValue derEncodedKeyValue) { | 
 | 
        appendSelf(derEncodedKeyValue);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addKeyInfoReference(String URI) throws XMLSecurityException { | 
 | 
        this.add(new KeyInfoReference(getDocument(), URI));  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void add(KeyInfoReference keyInfoReference) { | 
 | 
        appendSelf(keyInfoReference);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addUnknownElement(Element element) { | 
 | 
        appendSelf(element);  | 
 | 
        addReturnToSelf();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthKeyName() { | 
 | 
        return this.length(Constants.SignatureSpecNS, Constants._TAG_KEYNAME);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthKeyValue() { | 
 | 
        return this.length(Constants.SignatureSpecNS, Constants._TAG_KEYVALUE);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthMgmtData() { | 
 | 
        return this.length(Constants.SignatureSpecNS, Constants._TAG_MGMTDATA);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthPGPData() { | 
 | 
        return this.length(Constants.SignatureSpecNS, Constants._TAG_PGPDATA);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthRetrievalMethod() { | 
 | 
        return this.length(Constants.SignatureSpecNS, Constants._TAG_RETRIEVALMETHOD);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthSPKIData() { | 
 | 
        return this.length(Constants.SignatureSpecNS, Constants._TAG_SPKIDATA);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthX509Data() { | 
 | 
        if (x509Datas != null) { | 
 | 
            return x509Datas.size();  | 
 | 
        }  | 
 | 
        return this.length(Constants.SignatureSpecNS, Constants._TAG_X509DATA);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthDEREncodedKeyValue() { | 
 | 
        return this.length(Constants.SignatureSpec11NS, Constants._TAG_DERENCODEDKEYVALUE);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthKeyInfoReference() { | 
 | 
        return this.length(Constants.SignatureSpec11NS, Constants._TAG_KEYINFOREFERENCE);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public int lengthUnknownElement() { | 
 | 
        int res = 0;  | 
 | 
        Node childNode = getElement().getFirstChild();  | 
 | 
        while (childNode != null) { | 
 | 
              | 
 | 
 | 
 | 
 | 
 | 
             */  | 
 | 
            if (childNode.getNodeType() == Node.ELEMENT_NODE  | 
 | 
                && childNode.getNamespaceURI().equals(Constants.SignatureSpecNS)) { | 
 | 
                res++;  | 
 | 
            }  | 
 | 
            childNode = childNode.getNextSibling();  | 
 | 
        }  | 
 | 
 | 
 | 
        return res;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public KeyName itemKeyName(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDsNode(  | 
 | 
                getFirstChild(), Constants._TAG_KEYNAME, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new KeyName(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public KeyValue itemKeyValue(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDsNode(  | 
 | 
                getFirstChild(), Constants._TAG_KEYVALUE, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new KeyValue(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public MgmtData itemMgmtData(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDsNode(  | 
 | 
                getFirstChild(), Constants._TAG_MGMTDATA, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new MgmtData(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public PGPData itemPGPData(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDsNode(  | 
 | 
                getFirstChild(), Constants._TAG_PGPDATA, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new PGPData(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public RetrievalMethod itemRetrievalMethod(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDsNode(  | 
 | 
                getFirstChild(), Constants._TAG_RETRIEVALMETHOD, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new RetrievalMethod(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public SPKIData itemSPKIData(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDsNode(  | 
 | 
                getFirstChild(), Constants._TAG_SPKIDATA, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new SPKIData(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public X509Data itemX509Data(int i) throws XMLSecurityException { | 
 | 
        if (x509Datas != null) { | 
 | 
            return x509Datas.get(i);  | 
 | 
        }  | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDsNode(  | 
 | 
                getFirstChild(), Constants._TAG_X509DATA, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new X509Data(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public DEREncodedKeyValue itemDEREncodedKeyValue(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDs11Node(  | 
 | 
                getFirstChild(), Constants._TAG_DERENCODEDKEYVALUE, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new DEREncodedKeyValue(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public KeyInfoReference itemKeyInfoReference(int i) throws XMLSecurityException { | 
 | 
        Element e =  | 
 | 
            XMLUtils.selectDs11Node(  | 
 | 
                getFirstChild(), Constants._TAG_KEYINFOREFERENCE, i);  | 
 | 
 | 
 | 
        if (e != null) { | 
 | 
            return new KeyInfoReference(e, this.baseURI);  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public Element itemUnknownElement(int i) { | 
 | 
        int res = 0;  | 
 | 
        Node childNode = getElement().getFirstChild();  | 
 | 
        while (childNode != null) { | 
 | 
              | 
 | 
 | 
 | 
 | 
 | 
             */  | 
 | 
            if (childNode.getNodeType() == Node.ELEMENT_NODE  | 
 | 
                && childNode.getNamespaceURI().equals(Constants.SignatureSpecNS)) { | 
 | 
                res++;  | 
 | 
 | 
 | 
                if (res == i) { | 
 | 
                    return (Element) childNode;  | 
 | 
                }  | 
 | 
            }  | 
 | 
            childNode = childNode.getNextSibling();  | 
 | 
        }  | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean isEmpty() { | 
 | 
        return getFirstChild() == null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsKeyName() { | 
 | 
        return this.lengthKeyName() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsKeyValue() { | 
 | 
        return this.lengthKeyValue() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsMgmtData() { | 
 | 
        return this.lengthMgmtData() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsPGPData() { | 
 | 
        return this.lengthPGPData() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsRetrievalMethod() { | 
 | 
        return this.lengthRetrievalMethod() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsSPKIData() { | 
 | 
        return this.lengthSPKIData() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsUnknownElement() { | 
 | 
        return this.lengthUnknownElement() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsX509Data() { | 
 | 
        return this.lengthX509Data() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsDEREncodedKeyValue() { | 
 | 
        return this.lengthDEREncodedKeyValue() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public boolean containsKeyInfoReference() { | 
 | 
        return this.lengthKeyInfoReference() > 0;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public PublicKey getPublicKey() throws KeyResolverException { | 
 | 
        PublicKey pk = this.getPublicKeyFromInternalResolvers();  | 
 | 
 | 
 | 
        if (pk != null) { | 
 | 
            LOG.debug("I could find a key using the per-KeyInfo key resolvers"); | 
 | 
 | 
 | 
            return pk;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a key using the per-KeyInfo key resolvers"); | 
 | 
 | 
 | 
        pk = this.getPublicKeyFromStaticResolvers();  | 
 | 
 | 
 | 
        if (pk != null) { | 
 | 
            LOG.debug("I could find a key using the system-wide key resolvers"); | 
 | 
 | 
 | 
            return pk;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a key using the system-wide key resolvers"); | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    PublicKey getPublicKeyFromStaticResolvers() throws KeyResolverException { | 
 | 
        Iterator<KeyResolverSpi> it = KeyResolver.iterator();  | 
 | 
        while (it.hasNext()) { | 
 | 
            KeyResolverSpi keyResolver = it.next();  | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
            Node currentChild = getFirstChild();  | 
 | 
            String uri = this.getBaseURI();  | 
 | 
            while (currentChild != null) { | 
 | 
                if (currentChild.getNodeType() == Node.ELEMENT_NODE) { | 
 | 
                    for (StorageResolver storage : storageResolvers) { | 
 | 
                        PublicKey pk =  | 
 | 
                            keyResolver.engineLookupAndResolvePublicKey(  | 
 | 
                                (Element) currentChild, uri, storage  | 
 | 
                            );  | 
 | 
 | 
 | 
                        if (pk != null) { | 
 | 
                            return pk;  | 
 | 
                        }  | 
 | 
                    }  | 
 | 
                }  | 
 | 
                currentChild = currentChild.getNextSibling();  | 
 | 
            }  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    PublicKey getPublicKeyFromInternalResolvers() throws KeyResolverException { | 
 | 
        for (KeyResolverSpi keyResolver : internalKeyResolvers) { | 
 | 
            LOG.debug("Try {}", keyResolver.getClass().getName()); | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
            Node currentChild = getFirstChild();  | 
 | 
            String uri = this.getBaseURI();  | 
 | 
            while (currentChild != null)      { | 
 | 
                if (currentChild.getNodeType() == Node.ELEMENT_NODE) { | 
 | 
                    for (StorageResolver storage : storageResolvers) { | 
 | 
                        PublicKey pk =  | 
 | 
                            keyResolver.engineLookupAndResolvePublicKey(  | 
 | 
                                (Element) currentChild, uri, storage  | 
 | 
                            );  | 
 | 
 | 
 | 
                        if (pk != null) { | 
 | 
                            return pk;  | 
 | 
                        }  | 
 | 
                    }  | 
 | 
                }  | 
 | 
                currentChild = currentChild.getNextSibling();  | 
 | 
            }  | 
 | 
        }  | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public X509Certificate getX509Certificate() throws KeyResolverException { | 
 | 
          | 
 | 
        X509Certificate cert = this.getX509CertificateFromInternalResolvers();  | 
 | 
 | 
 | 
        if (cert != null) { | 
 | 
            LOG.debug("I could find a X509Certificate using the per-KeyInfo key resolvers"); | 
 | 
 | 
 | 
            return cert;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a X509Certificate using the per-KeyInfo key resolvers"); | 
 | 
 | 
 | 
          | 
 | 
        cert = this.getX509CertificateFromStaticResolvers();  | 
 | 
 | 
 | 
        if (cert != null) { | 
 | 
            LOG.debug("I could find a X509Certificate using the system-wide key resolvers"); | 
 | 
 | 
 | 
            return cert;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a X509Certificate using the system-wide key resolvers"); | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    X509Certificate getX509CertificateFromStaticResolvers()  | 
 | 
        throws KeyResolverException { | 
 | 
        LOG.debug(  | 
 | 
            "Start getX509CertificateFromStaticResolvers() with {} resolvers", KeyResolver.length() | 
 | 
        );  | 
 | 
        String uri = this.getBaseURI();  | 
 | 
        Iterator<KeyResolverSpi> it = KeyResolver.iterator();  | 
 | 
        while (it.hasNext()) { | 
 | 
            KeyResolverSpi keyResolver = it.next();  | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
            X509Certificate cert = applyCurrentResolver(uri, keyResolver);  | 
 | 
            if (cert != null) { | 
 | 
                return cert;  | 
 | 
            }  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
    private X509Certificate applyCurrentResolver(  | 
 | 
        String uri, KeyResolverSpi keyResolver  | 
 | 
    ) throws KeyResolverException { | 
 | 
        Node currentChild = getFirstChild();  | 
 | 
        while (currentChild != null)      { | 
 | 
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) { | 
 | 
                for (StorageResolver storage : storageResolvers) { | 
 | 
                    X509Certificate cert =  | 
 | 
                        keyResolver.engineLookupResolveX509Certificate(  | 
 | 
                            (Element) currentChild, uri, storage  | 
 | 
                        );  | 
 | 
 | 
 | 
                    if (cert != null) { | 
 | 
                        return cert;  | 
 | 
                    }  | 
 | 
                }  | 
 | 
            }  | 
 | 
            currentChild = currentChild.getNextSibling();  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    X509Certificate getX509CertificateFromInternalResolvers()  | 
 | 
        throws KeyResolverException { | 
 | 
        LOG.debug(  | 
 | 
            "Start getX509CertificateFromInternalResolvers() with {} resolvers", | 
 | 
            + this.lengthInternalKeyResolver()  | 
 | 
        );  | 
 | 
        String uri = this.getBaseURI();  | 
 | 
        for (KeyResolverSpi keyResolver : internalKeyResolvers) { | 
 | 
            LOG.debug("Try {}", keyResolver.getClass().getName()); | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
            X509Certificate cert = applyCurrentResolver(uri, keyResolver);  | 
 | 
            if (cert != null) { | 
 | 
                return cert;  | 
 | 
            }  | 
 | 
        }  | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public SecretKey getSecretKey() throws KeyResolverException { | 
 | 
        SecretKey sk = this.getSecretKeyFromInternalResolvers();  | 
 | 
 | 
 | 
        if (sk != null) { | 
 | 
            LOG.debug("I could find a secret key using the per-KeyInfo key resolvers"); | 
 | 
 | 
 | 
            return sk;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a secret key using the per-KeyInfo key resolvers"); | 
 | 
 | 
 | 
        sk = this.getSecretKeyFromStaticResolvers();  | 
 | 
 | 
 | 
        if (sk != null) { | 
 | 
            LOG.debug("I could find a secret key using the system-wide key resolvers"); | 
 | 
 | 
 | 
            return sk;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a secret key using the system-wide key resolvers"); | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    SecretKey getSecretKeyFromStaticResolvers() throws KeyResolverException { | 
 | 
        Iterator<KeyResolverSpi> it = KeyResolver.iterator();  | 
 | 
        while (it.hasNext()) { | 
 | 
            KeyResolverSpi keyResolver = it.next();  | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
 | 
 | 
            Node currentChild = getFirstChild();  | 
 | 
            String uri = this.getBaseURI();  | 
 | 
            while (currentChild != null)      { | 
 | 
                if (currentChild.getNodeType() == Node.ELEMENT_NODE) { | 
 | 
                    for (StorageResolver storage : storageResolvers) { | 
 | 
                        SecretKey sk =  | 
 | 
                            keyResolver.engineLookupAndResolveSecretKey(  | 
 | 
                                (Element) currentChild, uri, storage  | 
 | 
                            );  | 
 | 
 | 
 | 
                        if (sk != null) { | 
 | 
                            return sk;  | 
 | 
                        }  | 
 | 
                    }  | 
 | 
                }  | 
 | 
                currentChild = currentChild.getNextSibling();  | 
 | 
            }  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
    /**  | 
 | 
     * Searches the per-KeyInfo KeyResolvers for secret keys  | 
 | 
     *  | 
 | 
     * @return the secret key contained in this KeyInfo  | 
 | 
     * @throws KeyResolverException  | 
 | 
     */  | 
 | 
 | 
 | 
    SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException { | 
 | 
        for (KeyResolverSpi keyResolver : internalKeyResolvers) { | 
 | 
            LOG.debug("Try {}", keyResolver.getClass().getName()); | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
            Node currentChild = getFirstChild();  | 
 | 
            String uri = this.getBaseURI();  | 
 | 
            while (currentChild != null)      { | 
 | 
                if (currentChild.getNodeType() == Node.ELEMENT_NODE) { | 
 | 
                    for (StorageResolver storage : storageResolvers) { | 
 | 
                        SecretKey sk =  | 
 | 
                            keyResolver.engineLookupAndResolveSecretKey(  | 
 | 
                                (Element) currentChild, uri, storage  | 
 | 
                            );  | 
 | 
 | 
 | 
                        if (sk != null) { | 
 | 
                            return sk;  | 
 | 
                        }  | 
 | 
                    }  | 
 | 
                }  | 
 | 
                currentChild = currentChild.getNextSibling();  | 
 | 
            }  | 
 | 
        }  | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public PrivateKey getPrivateKey() throws KeyResolverException { | 
 | 
        PrivateKey pk = this.getPrivateKeyFromInternalResolvers();  | 
 | 
 | 
 | 
        if (pk != null) { | 
 | 
            LOG.debug("I could find a private key using the per-KeyInfo key resolvers"); | 
 | 
            return pk;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a secret key using the per-KeyInfo key resolvers"); | 
 | 
 | 
 | 
        pk = this.getPrivateKeyFromStaticResolvers();  | 
 | 
        if (pk != null) { | 
 | 
            LOG.debug("I could find a private key using the system-wide key resolvers"); | 
 | 
            return pk;  | 
 | 
        }  | 
 | 
        LOG.debug("I couldn't find a private key using the system-wide key resolvers"); | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    PrivateKey getPrivateKeyFromStaticResolvers() throws KeyResolverException { | 
 | 
        Iterator<KeyResolverSpi> it = KeyResolver.iterator();  | 
 | 
        while (it.hasNext()) { | 
 | 
            KeyResolverSpi keyResolver = it.next();  | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
 | 
 | 
            Node currentChild = getFirstChild();  | 
 | 
            String uri = this.getBaseURI();  | 
 | 
            while (currentChild != null)      { | 
 | 
                if (currentChild.getNodeType() == Node.ELEMENT_NODE) { | 
 | 
                    // not using StorageResolvers at the moment  | 
 | 
                      | 
 | 
                    PrivateKey pk =  | 
 | 
                        keyResolver.engineLookupAndResolvePrivateKey(  | 
 | 
                            (Element) currentChild, uri, null  | 
 | 
                        );  | 
 | 
 | 
 | 
                    if (pk != null) { | 
 | 
                        return pk;  | 
 | 
                    }  | 
 | 
                }  | 
 | 
                currentChild = currentChild.getNextSibling();  | 
 | 
            }  | 
 | 
        }  | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    PrivateKey getPrivateKeyFromInternalResolvers() throws KeyResolverException { | 
 | 
        for (KeyResolverSpi keyResolver : internalKeyResolvers) { | 
 | 
            LOG.debug("Try {}", keyResolver.getClass().getName()); | 
 | 
            keyResolver.setSecureValidation(secureValidation);  | 
 | 
            Node currentChild = getFirstChild();  | 
 | 
            String uri = this.getBaseURI();  | 
 | 
            while (currentChild != null) { | 
 | 
                if (currentChild.getNodeType() == Node.ELEMENT_NODE) { | 
 | 
                    // not using StorageResolvers at the moment  | 
 | 
                      | 
 | 
                    PrivateKey pk =  | 
 | 
                        keyResolver.engineLookupAndResolvePrivateKey(  | 
 | 
                            (Element) currentChild, uri, null  | 
 | 
                        );  | 
 | 
 | 
 | 
                    if (pk != null) { | 
 | 
                        return pk;  | 
 | 
                    }  | 
 | 
                }  | 
 | 
                currentChild = currentChild.getNextSibling();  | 
 | 
            }  | 
 | 
        }  | 
 | 
 | 
 | 
        return null;  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void registerInternalKeyResolver(KeyResolverSpi realKeyResolver) { | 
 | 
        this.internalKeyResolvers.add(realKeyResolver);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    int lengthInternalKeyResolver() { | 
 | 
        return this.internalKeyResolvers.size();  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    KeyResolverSpi itemInternalKeyResolver(int i) { | 
 | 
        return this.internalKeyResolvers.get(i);  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    public void addStorageResolver(StorageResolver storageResolver) { | 
 | 
        if (storageResolvers == nullList) { | 
 | 
              | 
 | 
            storageResolvers = new ArrayList<>();  | 
 | 
        }  | 
 | 
        this.storageResolvers.add(storageResolver);  | 
 | 
    }  | 
 | 
 | 
 | 
 | 
 | 
      | 
 | 
    public String getBaseLocalName() { | 
 | 
        return Constants._TAG_KEYINFO;  | 
 | 
    }  | 
 | 
}  |