Java Code Examples for javax.xml.crypto.dsig.keyinfo.X509Data#getContent()

The following examples show how to use javax.xml.crypto.dsig.keyinfo.X509Data#getContent() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: DOMX509Data.java    From openjdk-jdk9 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;

    List<?> 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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 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;
}