use of org.apache.cxf.xkms.model.xkms.ValidateRequestType in project cxf by apache.
the class ValidatorTest method testDaveSignedByAliceSginedByRootIsValid.
@Test
public void testDaveSignedByAliceSginedByRootIsValid() throws JAXBException, CertificateException {
X509Certificate daveCertificate = readCertificate("dave.cer");
ValidateRequestType request = prepareValidateXKMSRequest(daveCertificate);
StatusType result = doValidate(request);
Assert.assertEquals(KeyBindingEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_VALID, result.getStatusValue());
Assert.assertFalse(result.getValidReason().isEmpty());
Assert.assertEquals(ReasonEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_VALIDITY_INTERVAL.value(), result.getValidReason().get(0));
Assert.assertEquals(ReasonEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_ISSUER_TRUST.value(), result.getValidReason().get(1));
}
use of org.apache.cxf.xkms.model.xkms.ValidateRequestType in project cxf by apache.
the class X509UtilsTest method extractValidatingCertsCorrupted.
@Test(expected = XKMSRequestException.class)
public void extractValidatingCertsCorrupted() throws JAXBException {
InputStream is = this.getClass().getResourceAsStream("/validateRequestCorrupted.xml");
@SuppressWarnings("unchecked") JAXBElement<ValidateRequestType> request = (JAXBElement<ValidateRequestType>) unmarshaller.unmarshal(is);
ValidateRequestParser.parse(request.getValue());
}
use of org.apache.cxf.xkms.model.xkms.ValidateRequestType in project cxf by apache.
the class DateValidatorTest method processRequest.
private StatusType processRequest(String path) throws JAXBException {
InputStream is = this.getClass().getResourceAsStream(path);
@SuppressWarnings("unchecked") JAXBElement<ValidateRequestType> request = (JAXBElement<ValidateRequestType>) unmarshaller.unmarshal(is);
DateValidator validator = new DateValidator();
return validator.validate(request.getValue());
}
use of org.apache.cxf.xkms.model.xkms.ValidateRequestType 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;
}
use of org.apache.cxf.xkms.model.xkms.ValidateRequestType in project cxf by apache.
the class XKMSInvoker method checkCertificateValidity.
protected boolean checkCertificateValidity(X509Certificate cert, boolean directTrust) {
try {
ValidateRequestType validateRequestType = prepareValidateXKMSRequest(cert);
if (directTrust) {
validateRequestType.getQueryKeyBinding().getKeyUsage().add(KeyUsageEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_SIGNATURE);
}
ValidateResultType validateResultType = xkmsConsumer.validate(validateRequestType);
String id = cert.getSubjectDN().getName();
CertificateValidationResult result = parseValidateXKMSResponse(validateResultType, id);
if (!result.isValid()) {
LOG.warn(String.format("Certificate %s is not valid: %s", cert.getSubjectDN(), result.getDescription()));
}
return result.isValid();
} catch (RuntimeException e) {
String msg = String.format("XKMS validate call fails for certificate: %s. Error: %s", cert.getSubjectDN(), e.getMessage());
LOG.warn(msg, e);
throw new XKMSValidateException(msg, e);
}
}
Aggregations