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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations