javax.xml.crypto.dsig.keyinfo.X509Data Java Examples

The following examples show how to use javax.xml.crypto.dsig.keyinfo.X509Data. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlSignature.java    From cstc with GNU General Public License v3.0 6 votes vote down vote up
protected KeyInfo getKeyInfo() throws Exception {
  PrivateKeyEntry keyEntry = this.selectedEntry;
  String keyInfoChoice = (String) includeKeyInfo.getSelectedItem();
  if( Boolean.parseBoolean(keyInfoChoice) ) {
    X509Certificate cert = (X509Certificate)keyEntry.getCertificate();
    KeyInfoFactory keyInfoFac = signatureFac.getKeyInfoFactory();
    List<Object> x509Content = new ArrayList<Object>();
    if( this.subject.isSelected() ) {
      x509Content.add(cert.getSubjectX500Principal().getName());
    } 
    if( this.serialIssuer.isSelected() ) {
      x509Content.add(keyInfoFac.newX509IssuerSerial(cert.getIssuerX500Principal().getName(),cert.getSerialNumber()));
    }
    if( this.issuer.isSelected() ) {
      x509Content.add(cert.getIssuerX500Principal().getName());
    }
    if( this.certificate.isSelected() ) {
      x509Content.add(cert);
    }
    X509Data xd = keyInfoFac.newX509Data(x509Content);
    return keyInfoFac.newKeyInfo(Collections.singletonList(xd));
  }
  return (KeyInfo)null;
}
 
Example #2
Source File: DefaultSAML2Validator.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isSignatureTrusted(XMLSignature signature, String issuer) throws KeyStoreException,
        InvalidAlgorithmParameterException, CertificateException, NoSuchAlgorithmException {
    X509Certificate certificate = null;

    @SuppressWarnings("unchecked")
    List<XMLStructure> keyInfoContext = signature.getKeyInfo().getContent();

    for (XMLStructure xmlStructure : keyInfoContext) {
        if (xmlStructure instanceof X509Data) {
            X509Data xd = (X509Data) xmlStructure;
            @SuppressWarnings("unchecked")
            Iterator<Object> data = xd.getContent().iterator();
            while (data.hasNext()) {
                Object nextElement = data.next();
                if (nextElement instanceof X509Certificate) {
                    certificate = (X509Certificate) nextElement;
                    break;
                }
            }
        }
    }

    return isCertificateTrusted(issuer, certificate);
}
 
Example #3
Source File: SignatureVerifier.java    From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
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");
}
 
Example #4
Source File: X509KeySelectorTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test()
public void select_publicKey_exception() throws Exception {
    // given
    selector = spy(new X509KeySelector(keystore));
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    X509Data x509Data = mock(X509Data.class);
    list.add(x509Data);
    doReturn(list).when(keyinfo).getContent();
    ArrayList<Object> x509DataContent = new ArrayList<Object>();
    x509DataContent.add(mock(X509Certificate.class));
    doReturn(x509DataContent).when(x509Data).getContent();
    doThrow(new KeyStoreException("key exception")).when(selector)
            .getPublicKeyFromKeystore(any(X509Certificate.class),
                    any(SignatureMethod.class));

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getCause().getMessage().contains("key exception"));
    }
}
 
Example #5
Source File: X509KeySelectorTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test()
public void select_x509Data_noCertificate() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    X509Data x509Data = mock(X509Data.class);
    list.add(x509Data);
    doReturn(list).when(keyinfo).getContent();
    ArrayList<Object> x509DataContent = new ArrayList<Object>();
    x509DataContent.add(new String());
    doReturn(x509DataContent).when(x509Data).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("No X509Data element found."));
    }
}
 
Example #6
Source File: X509KeySelectorTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test()
public void select_x509Data_empty() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    X509Data x509Data = mock(X509Data.class);
    list.add(x509Data);
    doReturn(list).when(keyinfo).getContent();
    doReturn(new ArrayList<Object>()).when(x509Data).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("No X509Data element found."));
    }
}
 
Example #7
Source File: Assinar.java    From Java_NFe with MIT License 6 votes vote down vote up
private static void loadCertificates(ConfiguracoesNfe config, XMLSignatureFactory signatureFactory)
        throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException, CertificadoException {

    Certificado certificado = config.getCertificado();
    KeyStore keyStore = CertificadoService.getKeyStore(certificado);

    KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(certificado.getNome(),
            new KeyStore.PasswordProtection(certificado.getSenha().toCharArray()));
    privateKey = pkEntry.getPrivateKey();

    KeyInfoFactory keyInfoFactory = signatureFactory.getKeyInfoFactory();
    List<X509Certificate> x509Content = new ArrayList<X509Certificate>();

    x509Content.add(CertificadoService.getCertificate(certificado, keyStore));
    X509Data x509Data = keyInfoFactory.newX509Data(x509Content);
    keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(x509Data));
}
 
Example #8
Source File: Assinar.java    From Java_CTe with MIT License 6 votes vote down vote up
private static void loadCertificates(ConfiguracoesCte config, XMLSignatureFactory signatureFactory)
        throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException, CertificadoException {

    Certificado certificado = config.getCertificado();
    KeyStore keyStore = CertificadoService.getKeyStore(certificado);

    KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(certificado.getNome(),
            new KeyStore.PasswordProtection(certificado.getSenha().toCharArray()));
    privateKey = pkEntry.getPrivateKey();

    KeyInfoFactory keyInfoFactory = signatureFactory.getKeyInfoFactory();
    List<X509Certificate> x509Content = new ArrayList<X509Certificate>();

    x509Content.add(CertificadoService.getCertificate(certificado, keyStore));
    X509Data x509Data = keyInfoFactory.newX509Data(x509Content);
    keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(x509Data));
}
 
Example #9
Source File: SoapMultiSignature.java    From cstc with GNU General Public License v3.0 6 votes vote down vote up
private KeyInfo getKeyInfo(XMLSignatureFactory fac, PrivateKeyEntry keyEntry) throws Exception {
  String keyInfoChoice = (String) includeKeyInfo.getSelectedItem();
  if( Boolean.parseBoolean(keyInfoChoice) ) {
    KeyInfo keyInfo;
    X509Certificate cert = (X509Certificate)keyEntry.getCertificate();
    KeyInfoFactory keyInfoFac = fac.getKeyInfoFactory();
    List<Object> x509Content = new ArrayList<Object>();
    if( this.subject.isSelected() ) {
      x509Content.add(cert.getSubjectX500Principal().getName());
    } 
    if( this.serialIssuer.isSelected() ) {
      x509Content.add(keyInfoFac.newX509IssuerSerial(cert.getIssuerX500Principal().getName(),cert.getSerialNumber()));
    }
    if( this.issuer.isSelected() ) {
      x509Content.add(cert.getIssuerX500Principal().getName());
    }
    if( this.certificate.isSelected() ) {
      x509Content.add(cert);
    }
    X509Data xd = keyInfoFac.newX509Data(x509Content);
    keyInfo = keyInfoFac.newKeyInfo(Collections.singletonList(xd));
    return keyInfo;
  }
  return (KeyInfo)null;
}
 
Example #10
Source File: SignatureVerifier.java    From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
protected void setSigPublicKeyFromXml(String xml, DocumentBuilder docBuilderNSTrue) throws Exception {
	xml = sigStartElemToWrapXml + xml + sigEndElemToWrapXml;
       Document doc = docBuilderNSTrue.parse(new InputSource(new StringReader(xml)));
       DOMStructure ds = new DOMStructure(doc.getDocumentElement().getFirstChild());
       KeyInfo keyInfo = KeyInfoFactory.getInstance().unmarshalKeyInfo(ds);
	List<?> list = keyInfo.getContent();
	for (int i = 0; i < list.size(); i++) {
		XMLStructure xmlStructure = (XMLStructure) list.get(i);
		if (xmlStructure instanceof KeyValue) {
			try {
				sigPublicKey = ((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);
					sigPublicKey = cert.getPublicKey();
					break;
				}
			}
		}
	}
}
 
Example #11
Source File: XmlSignatureHelper.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * Signs the SAML assertion using the specified public and private keys.
 * 
 * @param document
 *            SAML assertion be signed.
 * @param privateKey
 *            Private key used to sign SAML assertion.
 * @param publicKey
 *            Public key used to sign SAML asserion.
 * @return w3c element representation of specified document.
 * @throws NoSuchAlgorithmException
 * @throws InvalidAlgorithmParameterException
 * @throws KeyException
 * @throws MarshalException
 * @throws XMLSignatureException
 */
private Element signSamlAssertion(Document document, PrivateKey privateKey, X509Certificate certificate)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyException, MarshalException,
        XMLSignatureException {
    XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM");
    List<Transform> envelopedTransform = Collections.singletonList(signatureFactory.newTransform(
            Transform.ENVELOPED, (TransformParameterSpec) null));
    Reference ref = signatureFactory.newReference("", signatureFactory.newDigestMethod(DigestMethod.SHA1, null),
            envelopedTransform, null, null);
    
    SignatureMethod signatureMethod = null;
    if (certificate.getPublicKey() instanceof DSAPublicKey) {
        signatureMethod = signatureFactory.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
    } else if (certificate.getPublicKey() instanceof RSAPublicKey) {
        signatureMethod = signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
    }
    
    CanonicalizationMethod canonicalizationMethod = signatureFactory.newCanonicalizationMethod(
            CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, (C14NMethodParameterSpec) null);
    
    SignedInfo signedInfo = signatureFactory.newSignedInfo(canonicalizationMethod, signatureMethod,
            Collections.singletonList(ref));
    
    KeyInfoFactory keyInfoFactory = signatureFactory.getKeyInfoFactory();
    X509Data data = keyInfoFactory.newX509Data(Collections.singletonList(certificate));
    KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(data));
    
    Element w3cElement = document.getDocumentElement();
    Node xmlSigInsertionPoint = getXmlSignatureInsertionLocation(w3cElement);
    DOMSignContext dsc = new DOMSignContext(privateKey, w3cElement, xmlSigInsertionPoint);
    
    XMLSignature signature = signatureFactory.newXMLSignature(signedInfo, keyInfo);
    signature.sign(dsc);
    return w3cElement;
}
 
Example #12
Source File: DefaultSAML2Validator.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@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;
    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();

    for (XMLStructure xmlStructure : list) {
        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);
            }
        }
        if (xmlStructure instanceof X509Data) {
            X509Data xd = (X509Data) xmlStructure;
            @SuppressWarnings("unchecked")
            Iterator<Object> data = xd.getContent().iterator();
            for (; data.hasNext();) {
                Object o = data.next();
                if (o instanceof X509Certificate) {
                    X509Certificate cert = (X509Certificate) o;
                    return new SimpleKeySelectorResult(cert.getPublicKey());
                }
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
 
Example #13
Source File: XmlSignatureApplet.java    From juddi with Apache License 2.0 5 votes vote down vote up
private void signDOM(Node node, PrivateKey privateKey, Certificate origCert) {
    XMLSignatureFactory fac = initXMLSigFactory();
    X509Certificate cert = (X509Certificate) origCert;
    // Create the KeyInfo containing the X509Data.
    KeyInfoFactory kif = fac.getKeyInfoFactory();
    List<Object> x509Content = new ArrayList<Object>();
    //x509Content.add(cert.getSubjectX500Principal().getName());
    x509Content.add(cert);
    X509Data xd = kif.newX509Data(x509Content);
    KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));

    // Create a DOMSignContext and specify the RSA PrivateKey and
    // location of the resulting XMLSignature's parent element.
    DOMSignContext dsc = new DOMSignContext(privateKey, node);
    dsc.putNamespacePrefix(XML_DIGSIG_NS, "ns2");

    // Create the XMLSignature, but don't sign it yet.
    try {
        SignedInfo si = initSignedInfo(fac);
        XMLSignature signature = fac.newXMLSignature(si, ki);

        // Marshal, generate, and sign the enveloped signature.
        signature.sign(dsc);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #14
Source File: TckSigningUtil.java    From juddi with Apache License 2.0 5 votes vote down vote up
public static void signDOM(Node node, PrivateKey privateKey, Certificate origCert) {
    XMLSignatureFactory fac = initXMLSigFactory();
    X509Certificate cert = (X509Certificate) origCert;
    // Create the KeyInfo containing the X509Data.
    KeyInfoFactory kif = fac.getKeyInfoFactory();
    List<Object> x509Content = new ArrayList<Object>();
    x509Content.add(cert.getSubjectX500Principal().getName());
    x509Content.add(cert);
    X509Data xd = kif.newX509Data(x509Content);
    KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));

    // Create a DOMSignContext and specify the RSA PrivateKey and
    // location of the resulting XMLSignature's parent element.
    DOMSignContext dsc = new DOMSignContext(privateKey, node);
    dsc.putNamespacePrefix("http://www.w3.org/2000/09/xmldsig#", "ns2");

    // Create the XMLSignature, but don't sign it yet.
    try {
        SignedInfo si = initSignedInfo(fac);
        XMLSignature signature = fac.newXMLSignature(si, ki);

        // Marshal, generate, and sign the enveloped signature.
        signature.sign(dsc);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #15
Source File: X509KeySelector.java    From io with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public final KeySelectorResult select(
        final KeyInfo keyInfoToUse,
        final KeySelector.Purpose purpose,
        final AlgorithmMethod method,
        final XMLCryptoContext context) throws KeySelectorException {
    Iterator ki = keyInfoToUse.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;
            }
            X509Certificate x509Certificate = (X509Certificate) o;
            final PublicKey key = x509Certificate.getPublicKey();
            // Make sure the algorithm is compatible
            // with the method.
            if (algEquals(method.getAlgorithm(), key.getAlgorithm())) {
                // x509証明書検証
                cheakX509validate(x509Certificate);
                return new KeySelectorResult() {
                    @Override
                    public Key getKey() {
                        return key;
                    }
                };
            }
        }
    }
    throw new KeySelectorException("No key found!");
}
 
Example #16
Source File: DOMX509Data.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #17
Source File: DOMX509Data.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #18
Source File: DOMX509Data.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #19
Source File: DOMX509Data.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #20
Source File: X509KeySelector.java    From SAMLRaider with MIT License 5 votes vote down vote up
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!");
  }
 
Example #21
Source File: X509KeySelector.java    From development with Apache License 2.0 5 votes vote down vote up
@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.");
}
 
Example #22
Source File: DOMX509Data.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #23
Source File: DOMX509Data.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #24
Source File: XMLDSigVerifier.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private List getCertificateChainFromXML(List xmlElements) throws KeyStoreException {
    boolean found = false;
    List certs = null;
    for (int i = 0; i < xmlElements.size(); i++)
    {
        XMLStructure xmlStructure = (XMLStructure) xmlElements.get(i);
        if (xmlStructure instanceof X509Data)
        {
            if(found) throw new KeyStoreException("Duplicate X509Data element");
            found = true;
            certs = (List<X509Certificate>) ((X509Data) xmlStructure).getContent();
        }
    }
    return certs;
}
 
Example #25
Source File: DOMX509Data.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #26
Source File: DOMX509Data.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #27
Source File: DOMX509Data.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #28
Source File: DOMX509Data.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #29
Source File: DOMX509Data.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #30
Source File: DOMX509Data.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof X509Data)) {
        return false;
    }
    X509Data oxd = (X509Data)o;

    @SuppressWarnings("unchecked") List<Object> ocontent = oxd.getContent();
    int size = content.size();
    if (size != ocontent.size()) {
        return false;
    }

    for (int i = 0; i < size; i++) {
        Object x = content.get(i);
        Object ox = ocontent.get(i);
        if (x instanceof byte[]) {
            if (!(ox instanceof byte[]) ||
                !Arrays.equals((byte[])x, (byte[])ox)) {
                return false;
            }
        } else {
            if (!(x.equals(ox))) {
                return false;
            }
        }
    }

    return true;
}