Java 类javax.xml.crypto.KeySelectorResult 实例源码

项目:jetfuel    文件:X509CertificateKeySelector.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
        throws KeySelectorException {

    for (Object o : keyInfo.getContent()) {
        if (o instanceof X509Data) {
            for (Object o2 : ((X509Data) o).getContent()) {
                if (o2 instanceof X509Certificate) {
                    final X509Certificate cert = (X509Certificate) o2;
                    return new KeySelectorResult() {
                        public Key getKey() {
                            return cert.getPublicKey();
                        }
                    };
                }
            }
        }
    }

    return null;
}
项目:nfce    文件:X509KeySelector.java   
@Override
public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException {
    for (final Object object : keyInfo.getContent()) {
        final XMLStructure info = (XMLStructure) object;
        if (info instanceof X509Data) {
            final X509Data x509Data = (X509Data) info;
            for (final Object certificado : x509Data.getContent()) {
                if (certificado instanceof X509Certificate) {
                    final X509Certificate x509Certificate = (X509Certificate) certificado;
                    if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) {
                        return new KeySelectorResult() {
                            @Override
                            public Key getKey() {
                                return x509Certificate.getPublicKey();
                            }
                        };
                    }
                }
            }
        }
    }
    throw new KeySelectorException("N\u00e3o foi localizada a chave do certificado.");
}
项目:secure-data-service    文件:X509KeySelector.java   
/**
 * Searches the specified keystore for a certificate that matches the
 * specified X509Certificate and contains a public key that is compatible
 * with the specified SignatureMethod.
 *
 * @return a KeySelectorResult containing the cert's public key if there
 *         is a match; otherwise null
 */
private KeySelectorResult certSelect(X509Certificate xcert,
                                     SignatureMethod sm) throws KeyStoreException {
    // skip non-signer certs
    boolean[] keyUsage = xcert.getKeyUsage();
    if (!keyUsage[0]) {
        return null;
    }
    String alias = ks.getCertificateAlias(xcert);
    if (alias != null) {
        PublicKey pk = ks.getCertificate(alias).getPublicKey();
        // make sure algorithm is compatible with method
        if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
            return new SimpleKeySelectorResult(pk);
        }
    }
    return null;
}
项目:nfe    文件:X509KeySelector.java   
@Override
public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException {
    for (final Object object : keyInfo.getContent()) {
        final XMLStructure info = (XMLStructure) object;
        if (info instanceof X509Data) {
            final X509Data x509Data = (X509Data) info;
            for (final Object certificado : x509Data.getContent()) {
                if (certificado instanceof X509Certificate) {
                    final X509Certificate x509Certificate = (X509Certificate) certificado;
                    if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) {
                        return new KeySelectorResult() {
                            @Override
                            public Key getKey() {
                                return x509Certificate.getPublicKey();
                            }
                        };
                    }
                }
            }
        }
    }
    throw new KeySelectorException("Nao foi localizada a chave do certificado.");
}
项目:neoscada    文件:KeyValueKeySelector.java   
@Override
public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException
{
    if ( keyInfo == null )
    {
        throw new KeySelectorException ( "Null KeyInfo object!" );
    }

    final SignatureMethod sm = (SignatureMethod)method;
    final List<?> list = keyInfo.getContent ();

    for ( int i = 0; i < list.size (); i++ )
    {
        final XMLStructure xmlStructure = (XMLStructure)list.get ( i );
        if ( xmlStructure instanceof KeyValue )
        {
            try
            {
                final PublicKey pk = ( (KeyValue)xmlStructure ).getPublicKey ();
                // make sure algorithm is compatible with method
                if ( algEquals ( sm.getAlgorithm (), pk.getAlgorithm () ) )
                {
                    return new SimpleKeySelectorResult ( pk );
                }
            }
            catch ( final KeyException ke )
            {
                throw new KeySelectorException ( ke );
            }

        }
    }
    throw new KeySelectorException ( "No KeyValue element found!" );
}
项目:neoscada    文件:X509KeySelector.java   
@Override
public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException
{
    if ( keyInfo == null )
    {
        throw new KeySelectorException ( "Null KeyInfo object!" );
    }

    final SignatureMethod sm = (SignatureMethod)method;
    final List<?> list = keyInfo.getContent ();

    for ( final Object l : list )
    {
        final XMLStructure xmlStructure = (XMLStructure)l;
        if ( xmlStructure instanceof X509Data )
        {
            for ( final Object o : ( (X509Data)xmlStructure ).getContent () )
            {
                KeySelectorResult result = null;
                if ( o instanceof X509Certificate )
                {
                    result = findPublicKey ( (X509Certificate)o, sm );
                }

                if ( result != null )
                {
                    return result;
                }
            }
        }
    }
    throw new KeySelectorException ( "No KeyValue element found!" );
}
项目:oscm    文件:X509KeySelector.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();
    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof X509Data) {
            X509Data x509Data = (X509Data) xmlStructure;
            @SuppressWarnings("rawtypes")
            List content = x509Data.getContent();
            for (int i = 0; i < content.size(); i++) {
                Object x509Content = content.get(i);
                if (x509Content instanceof X509Certificate) {
                    X509Certificate certificate = (X509Certificate) x509Content;
                    try {
                        return getPublicKeyFromKeystore(certificate,
                                (SignatureMethod) algorithmMethod);
                    } catch (KeyStoreException e) {
                        throw new KeySelectorException(e);
                    }
                }
            }
        }
    }

    throw new KeySelectorException("No X509Data element found.");
}
项目:oscm    文件:X509KeySelector.java   
KeySelectorResult getPublicKeyFromKeystore(X509Certificate certificate,
        SignatureMethod signatureMethod) throws KeyStoreException,
        KeySelectorException {

    isSigningCertificate(certificate);
    return searchInKeystore(certificate, signatureMethod);
}
项目:oscm    文件:X509KeySelector.java   
KeySelectorResult searchInKeystore(X509Certificate certificate,
        SignatureMethod signatureMethod) throws KeyStoreException,
        KeySelectorException {
    String alias = keystore.getCertificateAlias(certificate);
    if (alias != null) {
        PublicKey pk = keystore.getCertificate(alias).getPublicKey();
        if (algorithmCompatibleWithMethod(signatureMethod.getAlgorithm(),
                pk.getAlgorithm())) {
            return new SimpleKeySelectorResult(pk);
        }
    }
    throw new KeySelectorException(
            "X509 content is not a signing certificate");
}
项目:oscm    文件:KeyValueKeySelector.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();
    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof KeyValue) {
            PublicKey publicKey = null;
            try {
                publicKey = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            if (algorithmCompatibleWithMethod(
                    algorithmMethod.getAlgorithm(),
                    publicKey.getAlgorithm())) {
                return new SimpleKeySelectorResult(publicKey);
            }
        }
    }

    throw new KeySelectorException("No RSA/DSA KeyValue element found");
}
项目:Camel    文件:DefaultKeySelector.java   
private KeySelectorResult getKeySelectorResult(final Key key) {
    return new KeySelectorResult() {
        public Key getKey() {
            return key;
        }
    };
}
项目:Camel    文件:XmlSignatureTest.java   
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
    throws KeySelectorException {
    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    SignatureMethod sm = (SignatureMethod) method;
    @SuppressWarnings("rawtypes")
    List list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKeySelectorResult(pk);
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
项目:Camel    文件:SignatureDigestMethodTest.java   
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
    throws KeySelectorException {
    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    SignatureMethod sm = (SignatureMethod) method;
    @SuppressWarnings("rawtypes")
    List list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKeySelectorResult(pk);
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
项目:Camel    文件:SignatureAlgorithmTest.java   
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
    throws KeySelectorException {
    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    SignatureMethod sm = (SignatureMethod) method;
    @SuppressWarnings("rawtypes")
    List list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKeySelectorResult(pk);
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
项目:development    文件:X509KeySelector.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();
    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof X509Data) {
            X509Data x509Data = (X509Data) xmlStructure;
            @SuppressWarnings("rawtypes")
            List content = x509Data.getContent();
            for (int i = 0; i < content.size(); i++) {
                Object x509Content = content.get(i);
                if (x509Content instanceof X509Certificate) {
                    X509Certificate certificate = (X509Certificate) x509Content;
                    try {
                        return getPublicKeyFromKeystore(certificate,
                                (SignatureMethod) algorithmMethod);
                    } catch (KeyStoreException e) {
                        throw new KeySelectorException(e);
                    }
                }
            }
        }
    }

    throw new KeySelectorException("No X509Data element found.");
}
项目:development    文件:X509KeySelector.java   
KeySelectorResult getPublicKeyFromKeystore(X509Certificate certificate,
        SignatureMethod signatureMethod) throws KeyStoreException,
        KeySelectorException {

    isSigningCertificate(certificate);
    return searchInKeystore(certificate, signatureMethod);
}
项目:development    文件:X509KeySelector.java   
KeySelectorResult searchInKeystore(X509Certificate certificate,
        SignatureMethod signatureMethod) throws KeyStoreException,
        KeySelectorException {
    String alias = keystore.getCertificateAlias(certificate);
    if (alias != null) {
        PublicKey pk = keystore.getCertificate(alias).getPublicKey();
        if (algorithmCompatibleWithMethod(signatureMethod.getAlgorithm(),
                pk.getAlgorithm())) {
            return new SimpleKeySelectorResult(pk);
        }
    }
    throw new KeySelectorException(
            "X509 content is not a signing certificate");
}
项目:development    文件:KeyValueKeySelector.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();
    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof KeyValue) {
            PublicKey publicKey = null;
            try {
                publicKey = ((KeyValue) xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            if (algorithmCompatibleWithMethod(
                    algorithmMethod.getAlgorithm(),
                    publicKey.getAlgorithm())) {
                return new SimpleKeySelectorResult(publicKey);
            }
        }
    }

    throw new KeySelectorException("No RSA/DSA KeyValue element found");
}
项目:laverca    文件:XmlDsigUtil.java   
@Override
public KeySelectorResult select(final KeyInfo             keyInfo,
                                final KeySelector.Purpose purpose,
                                final AlgorithmMethod     method,
                                final XMLCryptoContext    context)
    throws KeySelectorException 
{
    if (keyInfo == null) {
        throw new KeySelectorException("null KeyInfo");
    }
    List<?> list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        PublicKey pk = null;
        if (xmlStructure instanceof KeyValue) {
            try {
                pk = ((KeyValue)xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
        } else if (xmlStructure instanceof X509Data) {
            List<sun.security.x509.X509CertImpl> certs = ((X509Data)xmlStructure).getContent();
            pk = certs.get(0).getPublicKey();
        } else  {
            log.error(xmlStructure + " not supported");
            continue;
        }
        return new SimpleKeySelectorResult(pk);
    }
    throw new KeySelectorException("No supported KeyValue element found");
}
项目:SAMLRaider    文件:X509KeySelector.java   
public KeySelectorResult select(KeyInfo keyInfo,
                                  KeySelector.Purpose purpose,
                                  AlgorithmMethod method,
                                  XMLCryptoContext context)
      throws KeySelectorException {
      @SuppressWarnings("rawtypes")
Iterator ki = keyInfo.getContent().iterator();
      while (ki.hasNext()) {
          XMLStructure info = (XMLStructure) ki.next();
          if (!(info instanceof X509Data))
              continue;
          X509Data x509Data = (X509Data) info;
          @SuppressWarnings("rawtypes")
    Iterator xi = x509Data.getContent().iterator();
          while (xi.hasNext()) {
              Object o = xi.next();
              if (!(o instanceof X509Certificate))
                  continue;
              final PublicKey key = ((X509Certificate)o).getPublicKey();
              // Make sure the algorithm is compatible
              // with the method.
              if (algEquals(method.getAlgorithm(), key.getAlgorithm())) {
                  return new KeySelectorResult() {
                      public Key getKey() { return key; }
                  };
              }
          }
      }
      throw new KeySelectorException("No key found!");
  }
项目:IDES-Data-Preparation-Java    文件:UtilShared.java   
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, 
        AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
    if (keyInfo == null)
        throw new KeySelectorException("Null KeyInfo");
    List<?> list = keyInfo.getContent();
    PublicKey pk = null;

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        if (xmlStructure instanceof KeyValue) {
            try {
                pk = ((KeyValue)xmlStructure).getPublicKey();
            } catch(KeyException ke) {
                throw new KeySelectorException(ke.getMessage());
            }
            break;
        } else if (xmlStructure instanceof X509Data) {
            X509Data x509data = (X509Data)xmlStructure;
            List<?> x509datalist = x509data.getContent();
            for (int j = 0; j < x509datalist.size(); j++) {
                if (x509datalist.get(j) instanceof X509Certificate) {
                    X509Certificate cert = (X509Certificate)x509datalist.get(j);
                    pk = cert.getPublicKey();
                    break;
                }
            }
        }
    }
    if (pk != null) {
        final PublicKey retpk = pk;
        logger.debug("PublicKey from XML=" + pk);
        return new KeySelectorResult() {public Key getKey(){return retpk;}};
    }
    throw new KeySelectorException("Missing KeyValue");
}
项目:registrar_toolkit    文件:X509KeySelector.java   
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod method,
        XMLCryptoContext context) throws KeySelectorException {
    Iterator ki = keyInfo.getContent().iterator();
    while (ki.hasNext()) {
        XMLStructure info = (XMLStructure) ki.next();
        if (!(info instanceof X509Data))
            continue;
        X509Data x509Data = (X509Data) info;
        Iterator xi = x509Data.getContent().iterator();
        while (xi.hasNext()) {
            Object o = xi.next();
            if (!(o instanceof X509Certificate))
                continue;
            final PublicKey key = ((X509Certificate) o).getPublicKey();
            // Make sure the algorithm is compatible
            // with the method.
            if (algEquals(method.getAlgorithm(), key.getAlgorithm())) {
                return new KeySelectorResult() {
                    public Key getKey() {
                        return key;
                    }
                };
            }
        }
    }
    throw new KeySelectorException("No key found!");
}
项目:opes    文件:CertificadoDigital.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method,
        XMLCryptoContext context) throws KeySelectorException {

    @SuppressWarnings("unchecked")
    Iterator<XMLStructure> ki = keyInfo.getContent().iterator();

    while (ki.hasNext()) {
        XMLStructure info = ki.next();
        if (info instanceof X509Data) {
            X509Data x509Data = (X509Data) info;
            @SuppressWarnings("unchecked")
            Iterator<Object> xi = x509Data.getContent().iterator();
            while (xi.hasNext()) {
                Object o = xi.next();
                if (!(o instanceof X509Certificate))
                    continue;
                final PublicKey key = ((X509Certificate) o).getPublicKey();
                if (algEquals(method.getAlgorithm(), key.getAlgorithm())) {
                    return new KeySelectorResult() {
                        @Override
                        public Key getKey() {
                            return key;
                        }
                    };
                }
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
项目:WS-Attacker    文件:XmlMessageSigner.java   
public KeySelectorResult select( KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method,
                                 XMLCryptoContext context )
    throws KeySelectorException
{
    Iterator ki = keyInfo.getContent().iterator();
    while ( ki.hasNext() )
    {
        XMLStructure info = (XMLStructure) ki.next();
        if ( !( info instanceof X509Data ) )
        {
            continue;
        }
        X509Data x509Data = (X509Data) info;
        Iterator xi = x509Data.getContent().iterator();
        while ( xi.hasNext() )
        {
            Object o = xi.next();
            if ( !( o instanceof X509Certificate ) )
            {
                continue;
            }
            final PublicKey key = ( (X509Certificate) o ).getPublicKey();
            // Make sure the algorithm is compatible
            // with the method.
            if ( algEquals( method.getAlgorithm(), key.getAlgorithm() ) )
            {
                return new KeySelectorResult()
                {
                    public Key getKey()
                    {
                        return key;
                    }
                };
            }
        }
    }
    throw new KeySelectorException( "No key found!" );
}
项目:ph-xmldsig    文件:X509KeySelector.java   
@Override
@Nonnull
public KeySelectorResult select (@Nonnull final KeyInfo aKeyInfo,
                                 final KeySelector.Purpose aPurpose,
                                 @Nonnull final AlgorithmMethod aMethod,
                                 final XMLCryptoContext aContext) throws KeySelectorException
{
  for (final Object aKeyInfoElement : aKeyInfo.getContent ())
  {
    final XMLStructure aXMLStructure = (XMLStructure) aKeyInfoElement;
    if (aXMLStructure instanceof X509Data)
    {
      // We found a certificate
      final X509Data x509Data = (X509Data) aXMLStructure;
      for (final Object aX509Element : x509Data.getContent ())
      {
        if (aX509Element instanceof X509Certificate)
        {
          final X509Certificate aCert = (X509Certificate) aX509Element;
          final PublicKey aPublicKey = aCert.getPublicKey ();
          // Make sure the algorithm is compatible
          // with the method.
          if (algorithmEquals (aMethod.getAlgorithm (), aPublicKey.getAlgorithm ()))
            return new ConstantKeySelectorResult (aPublicKey);
        }
      }
    }
  }
  throw new KeySelectorException ("No key found!");
}
项目:ExemplosDemoiselle    文件:X509KeySelector.java   
public KeySelectorResult select(KeyInfo keyInfo,
                                KeySelector.Purpose purpose,
                                AlgorithmMethod method,
                                XMLCryptoContext context)
    throws KeySelectorException {
    Iterator<?> ki = keyInfo.getContent().iterator();
    while (ki.hasNext()) {
        XMLStructure info = (XMLStructure) ki.next();
        if (!(info instanceof X509Data))
            continue;
        X509Data x509Data = (X509Data) info;
        Iterator<?> xi = x509Data.getContent().iterator();
        while (xi.hasNext()) {
            Object o = xi.next();
            if (!(o instanceof X509Certificate))
                continue;
            final PublicKey key = ((X509Certificate)o).getPublicKey();
            // Make sure the algorithm is compatible
            // with the method.
            if (algEquals(method.getAlgorithm(), key.getAlgorithm())) {
                return new KeySelectorResult() {
                    public Key getKey() { return key; }
                };
            }
        }
    }
    throw new KeySelectorException("No key found!");
}
项目:nsi-dds    文件:X509KeySelector.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo,KeySelector.Purpose purpose,
        AlgorithmMethod method, XMLCryptoContext context)
        throws KeySelectorException {

    Iterator ki = keyInfo.getContent().iterator();
    while (ki.hasNext()) {
        XMLStructure info = (XMLStructure) ki.next();
        if (!(info instanceof X509Data)) {
            continue;
        }

        X509Data x509Data = (X509Data) info;

        Iterator xi = x509Data.getContent().iterator();
        while (xi.hasNext()) {
            Object o = xi.next();
            if (!(o instanceof X509Certificate)) {
                continue;
            }

            final PublicKey key = ((X509Certificate)o).getPublicKey();

            // Make sure the algorithm is compatible with the method.
            if (algEquals(method.getAlgorithm(), key.getAlgorithm())) {
                return () -> key;
            }
        }
    }
    throw new KeySelectorException("No key found!");
}
项目:nsi-dds    文件:KeyValueKeySelector.java   
/**
 * KeySelector which retrieves the public key out of the
 * KeyValue element and returns it.
 * NOTE: If the key algorithm doesn't match signature algorithm,
 * then the public key will be ignored.
 */
@Override
public KeySelectorResult select(KeyInfo keyInfo,
                                KeySelector.Purpose purpose,
                                AlgorithmMethod method,
                                XMLCryptoContext context)
    throws KeySelectorException {
    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }
    SignatureMethod sm = (SignatureMethod) method;
    List list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
        XMLStructure xmlStructure = (XMLStructure) list.get(i);
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue)xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKeySelectorResult(pk);
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
项目:secure-data-service    文件:X509KeySelector.java   
/**
 * Searches the specified keystore for a certificate that matches the
 * criteria specified in the CertSelector.
 *
 * @return a KeySelectorResult containing the cert's public key if there
 *         is a match; otherwise null
 */
private KeySelectorResult keyStoreSelect(CertSelector cs)
        throws KeyStoreException {
    Enumeration aliases = ks.aliases();
    while (aliases.hasMoreElements()) {
        String alias = (String) aliases.nextElement();
        Certificate cert = ks.getCertificate(alias);
        if (cert != null && cs.match(cert)) {
            return new SimpleKeySelectorResult(cert.getPublicKey());
        }
    }
    return null;
}
项目:neoscada    文件:RequestValidator.java   
public KeySelectorResult getKeySelectorResult ()
{
    return this.keySelectorResult;
}
项目:muleebmsadapter    文件:XMLDSignatureInInterceptor.java   
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException
{
    if (keyInfo == null)
        throw new KeySelectorException("KeyInfo is null!");
    for (Object xmlStructure : keyInfo.getContent())
    {
        if (xmlStructure instanceof X509Data)
        {
            final Certificate certificate = (Certificate)((X509Data)xmlStructure).getContent().get(0);
            return 
                new KeySelectorResult()
                {
                    @Override
                    public Key getKey()
                    {
                        return certificate.getPublicKey();
                    }
                }
            ;
        }
        if (xmlStructure instanceof KeyValue)
        {
            try
            {
                final PublicKey publicKey = ((KeyValue)xmlStructure).getPublicKey();
                return 
                new KeySelectorResult()
                {
                    @Override
                    public Key getKey()
                    {
                        return publicKey;
                    }
                }
            ;
            }
            catch (KeyException e)
            {
            }
        }
    }
    throw new KeySelectorException("No Public Key found!");
    }
项目:WS-Attacker    文件:KeyValueKeySelector.java   
@Override
public KeySelectorResult select( KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method,
                                 XMLCryptoContext context )
    throws KeySelectorException
{

    if ( keyInfo == null )
    {
        throw new KeySelectorException( "Null KeyInfo object!" );
    }
    SignatureMethod sm = (SignatureMethod) method;
    List<?> list = keyInfo.getContent();

    for ( int i = 0; i < list.size(); i++ )
    {
        XMLStructure xmlStructure = (XMLStructure) list.get( i );
        PublicKey pk = null;
        if ( xmlStructure instanceof KeyValue )
        {
            try
            {
                pk = ( (KeyValue) xmlStructure ).getPublicKey();
            }
            catch ( KeyException ke )
            {
                throw new KeySelectorException( ke );
            }
            // make sure algorithm is compatible with method
            if ( algEquals( sm.getAlgorithm(), pk.getAlgorithm() ) )
            {
                return new SimpleKeySelectorResult( pk );
            }
        }
        else if ( xmlStructure instanceof X509Data )
        {
            for ( Object data : ( (X509Data) xmlStructure ).getContent() )
            {
                if ( data instanceof X509Certificate )
                {
                    pk = ( (X509Certificate) data ).getPublicKey();
                }
            }
            // make sure algorithm is compatible with method
            if ( algEquals( sm.getAlgorithm(), pk.getAlgorithm() ) )
            {
                return new SimpleKeySelectorResult( pk );
            }
        }
    }
    throw new KeySelectorException( "No KeyValue element found!" );
}
项目:dssp    文件:SecurityTokenKeySelector.java   
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
        throws KeySelectorException {
    LOGGER.debug("select");
    return this;
}
项目:OpenJSharp    文件:XMLSignature.java   
/**
 * Returns the result of the {@link KeySelector}, if specified, after
 * this <code>XMLSignature</code> has been signed or validated.
 *
 * @return the key selector result, or <code>null</code> if a key
 *    selector has not been specified or this <code>XMLSignature</code>
 *    has not been signed or validated
 */
KeySelectorResult getKeySelectorResult();
项目:jdk8u-jdk    文件:XMLSignature.java   
/**
 * Returns the result of the {@link KeySelector}, if specified, after
 * this <code>XMLSignature</code> has been signed or validated.
 *
 * @return the key selector result, or <code>null</code> if a key
 *    selector has not been specified or this <code>XMLSignature</code>
 *    has not been signed or validated
 */
KeySelectorResult getKeySelectorResult();
项目:openjdk-jdk10    文件:XMLSignature.java   
/**
 * Returns the result of the {@link KeySelector}, if specified, after
 * this <code>XMLSignature</code> has been signed or validated.
 *
 * @return the key selector result, or <code>null</code> if a key
 *    selector has not been specified or this <code>XMLSignature</code>
 *    has not been signed or validated
 */
KeySelectorResult getKeySelectorResult();
项目:openjdk9    文件:XMLSignature.java   
/**
 * Returns the result of the {@link KeySelector}, if specified, after
 * this <code>XMLSignature</code> has been signed or validated.
 *
 * @return the key selector result, or <code>null</code> if a key
 *    selector has not been specified or this <code>XMLSignature</code>
 *    has not been signed or validated
 */
KeySelectorResult getKeySelectorResult();
项目:Java8CN    文件:XMLSignature.java   
/**
 * Returns the result of the {@link KeySelector}, if specified, after
 * this <code>XMLSignature</code> has been signed or validated.
 *
 * @return the key selector result, or <code>null</code> if a key
 *    selector has not been specified or this <code>XMLSignature</code>
 *    has not been signed or validated
 */
KeySelectorResult getKeySelectorResult();
项目:jdk8u_jdk    文件:XMLSignature.java   
/**
 * Returns the result of the {@link KeySelector}, if specified, after
 * this <code>XMLSignature</code> has been signed or validated.
 *
 * @return the key selector result, or <code>null</code> if a key
 *    selector has not been specified or this <code>XMLSignature</code>
 *    has not been signed or validated
 */
KeySelectorResult getKeySelectorResult();
项目:lookaside_java-1.8.0-openjdk    文件:XMLSignature.java   
/**
 * Returns the result of the {@link KeySelector}, if specified, after
 * this <code>XMLSignature</code> has been signed or validated.
 *
 * @return the key selector result, or <code>null</code> if a key
 *    selector has not been specified or this <code>XMLSignature</code>
 *    has not been signed or validated
 */
KeySelectorResult getKeySelectorResult();