Search in sources :

Example 1 with X509DataType

use of org.apache.cxf.xkms.model.xmldsig.X509DataType in project cxf by apache.

the class ValidatorCRLTest method prepareValidateXKMSRequest.

/*
     * Method is taken from {@link org.apache.cxf.xkms.client.XKMSInvoker}.
     */
private ValidateRequestType prepareValidateXKMSRequest(X509Certificate cert) {
    JAXBElement<byte[]> x509Cert;
    try {
        x509Cert = DSIG_OF.createX509DataTypeX509Certificate(cert.getEncoded());
    } catch (CertificateEncodingException e) {
        throw new IllegalArgumentException(e);
    }
    X509DataType x509DataType = DSIG_OF.createX509DataType();
    x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(x509Cert);
    JAXBElement<X509DataType> x509Data = DSIG_OF.createX509Data(x509DataType);
    KeyInfoType keyInfoType = DSIG_OF.createKeyInfoType();
    keyInfoType.getContent().add(x509Data);
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    queryKeyBindingType.setKeyInfo(keyInfoType);
    ValidateRequestType validateRequestType = XKMS_OF.createValidateRequestType();
    setGenericRequestParams(validateRequestType);
    validateRequestType.setQueryKeyBinding(queryKeyBindingType);
    // temporary
    validateRequestType.setId(cert.getSubjectDN().toString());
    return validateRequestType;
}
Also used : X509DataType(org.apache.cxf.xkms.model.xmldsig.X509DataType) QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) CertificateEncodingException(java.security.cert.CertificateEncodingException) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType) ValidateRequestType(org.apache.cxf.xkms.model.xkms.ValidateRequestType)

Example 2 with X509DataType

use of org.apache.cxf.xkms.model.xmldsig.X509DataType in project cxf by apache.

the class X509Locator method parse.

private List<UseKeyWithType> parse(KeyInfoType keyInfo) {
    List<UseKeyWithType> keyIDs = new ArrayList<>();
    if (keyInfo == null) {
        return keyIDs;
    }
    List<Object> content = keyInfo.getContent();
    for (Object obj1 : content) {
        if (obj1 instanceof JAXBElement) {
            JAXBElement<?> keyInfoChild = (JAXBElement<?>) obj1;
            if (X509Utils.X509_KEY_NAME.equals(keyInfoChild.getName())) {
                UseKeyWithType keyDN = new UseKeyWithType();
                keyDN.setApplication(Applications.PKIX.getUri());
                keyDN.setIdentifier((String) keyInfoChild.getValue());
                keyIDs.add(keyDN);
            } else if (X509Utils.X509_DATA.equals(keyInfoChild.getName())) {
                X509DataType x509Data = (X509DataType) keyInfoChild.getValue();
                List<Object> x509DataContent = x509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName();
                for (Object obj2 : x509DataContent) {
                    if (obj2 instanceof JAXBElement) {
                        JAXBElement<?> x509DataChild = (JAXBElement<?>) obj2;
                        if (X509Utils.X509_ISSUER_SERIAL.equals(x509DataChild.getName())) {
                            X509IssuerSerialType x509IssuerSerial = (X509IssuerSerialType) x509DataChild.getValue();
                            UseKeyWithType issuer = new UseKeyWithType();
                            issuer.setApplication(Applications.ISSUER.getUri());
                            issuer.setIdentifier(x509IssuerSerial.getX509IssuerName());
                            keyIDs.add(issuer);
                            UseKeyWithType serial = new UseKeyWithType();
                            serial.setApplication(Applications.SERIAL.getUri());
                            serial.setIdentifier(x509IssuerSerial.getX509SerialNumber().toString());
                            keyIDs.add(serial);
                        } else if (X509Utils.X509_SUBJECT_NAME.equals(x509DataChild.getName())) {
                            UseKeyWithType keyDN = new UseKeyWithType();
                            keyDN.setApplication(Applications.PKIX.getUri());
                            keyDN.setIdentifier((String) x509DataChild.getValue());
                            keyIDs.add(keyDN);
                        }
                    }
                }
            }
        }
    }
    return keyIDs;
}
Also used : X509DataType(org.apache.cxf.xkms.model.xmldsig.X509DataType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JAXBElement(javax.xml.bind.JAXBElement) X509IssuerSerialType(org.apache.cxf.xkms.model.xmldsig.X509IssuerSerialType)

Example 3 with X509DataType

use of org.apache.cxf.xkms.model.xmldsig.X509DataType in project cxf by apache.

the class X509Register method getCertsFromKeyInfo.

private List<X509Certificate> getCertsFromKeyInfo(KeyInfoType keyInfo) throws CertificateException {
    List<X509Certificate> certList = new ArrayList<>();
    for (Object key : keyInfo.getContent()) {
        if (key instanceof JAXBElement) {
            Object value = ((JAXBElement<?>) key).getValue();
            if (value instanceof X509DataType) {
                X509DataType x509Data = (X509DataType) value;
                List<Object> data = x509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName();
                for (Object certO : data) {
                    JAXBElement<?> certO2 = (JAXBElement<?>) certO;
                    if (certO2.getDeclaredType() == byte[].class) {
                        byte[] certContent = (byte[]) certO2.getValue();
                        X509Certificate cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(certContent));
                        certList.add(cert);
                    }
                }
            }
        }
    }
    return certList;
}
Also used : X509DataType(org.apache.cxf.xkms.model.xmldsig.X509DataType) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) X509Certificate(java.security.cert.X509Certificate)

Example 4 with X509DataType

use of org.apache.cxf.xkms.model.xmldsig.X509DataType in project cxf by apache.

the class XKMSInvoker method parseLocateXKMSResponse.

@SuppressWarnings("unchecked")
protected X509Certificate parseLocateXKMSResponse(LocateResultType locateResultType, List<X509AppId> ids) {
    XKMSException exception = ExceptionMapper.fromResponse(locateResultType);
    if (exception != null) {
        throw exception;
    }
    if (!locateResultType.getUnverifiedKeyBinding().iterator().hasNext()) {
        LOG.warn("X509Certificate is not found in XKMS for id: " + ids);
        return null;
    }
    KeyInfoType keyInfo = locateResultType.getUnverifiedKeyBinding().iterator().next().getKeyInfo();
    if (!keyInfo.getContent().iterator().hasNext()) {
        LOG.warn("X509Certificate is not found in XKMS for id: " + ids);
        return null;
    }
    JAXBElement<X509DataType> x509Data = (JAXBElement<X509DataType>) keyInfo.getContent().iterator().next();
    JAXBElement<byte[]> certificate = (JAXBElement<byte[]>) x509Data.getValue().getX509IssuerSerialOrX509SKIOrX509SubjectName().iterator().next();
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        return (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certificate.getValue()));
    } catch (CertificateException e) {
        throw new XKMSLocateException(XKMS_LOCATE_INVALID_CERTIFICATE, e);
    }
}
Also used : X509DataType(org.apache.cxf.xkms.model.xmldsig.X509DataType) XKMSLocateException(org.apache.cxf.xkms.exception.XKMSLocateException) ByteArrayInputStream(java.io.ByteArrayInputStream) XKMSException(org.apache.cxf.xkms.exception.XKMSException) CertificateException(java.security.cert.CertificateException) JAXBElement(javax.xml.bind.JAXBElement) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType)

Example 5 with X509DataType

use of org.apache.cxf.xkms.model.xmldsig.X509DataType in project cxf by apache.

the class XKMSInvoker method prepareValidateXKMSRequest.

protected ValidateRequestType prepareValidateXKMSRequest(X509Certificate cert) {
    JAXBElement<byte[]> x509Cert;
    try {
        x509Cert = DSIG_OF.createX509DataTypeX509Certificate(cert.getEncoded());
    } catch (CertificateEncodingException e) {
        throw new IllegalArgumentException(e);
    }
    X509DataType x509DataType = DSIG_OF.createX509DataType();
    x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(x509Cert);
    JAXBElement<X509DataType> x509Data = DSIG_OF.createX509Data(x509DataType);
    KeyInfoType keyInfoType = DSIG_OF.createKeyInfoType();
    keyInfoType.getContent().add(x509Data);
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    queryKeyBindingType.setKeyInfo(keyInfoType);
    ValidateRequestType validateRequestType = XKMS_OF.createValidateRequestType();
    setGenericRequestParams(validateRequestType);
    validateRequestType.setQueryKeyBinding(queryKeyBindingType);
    // temporary
    validateRequestType.setId(cert.getSubjectDN().toString());
    return validateRequestType;
}
Also used : X509DataType(org.apache.cxf.xkms.model.xmldsig.X509DataType) QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) CertificateEncodingException(java.security.cert.CertificateEncodingException) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType) ValidateRequestType(org.apache.cxf.xkms.model.xkms.ValidateRequestType)

Aggregations

X509DataType (org.apache.cxf.xkms.model.xmldsig.X509DataType)7 KeyInfoType (org.apache.cxf.xkms.model.xmldsig.KeyInfoType)5 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 JAXBElement (javax.xml.bind.JAXBElement)3 QueryKeyBindingType (org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)3 ValidateRequestType (org.apache.cxf.xkms.model.xkms.ValidateRequestType)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 CertificateException (java.security.cert.CertificateException)1 CertificateFactory (java.security.cert.CertificateFactory)1 List (java.util.List)1 XKMSException (org.apache.cxf.xkms.exception.XKMSException)1 XKMSLocateException (org.apache.cxf.xkms.exception.XKMSLocateException)1 UseKeyWithType (org.apache.cxf.xkms.model.xkms.UseKeyWithType)1 ObjectFactory (org.apache.cxf.xkms.model.xmldsig.ObjectFactory)1 X509IssuerSerialType (org.apache.cxf.xkms.model.xmldsig.X509IssuerSerialType)1