Search in sources :

Example 6 with KeyInfoType

use of org.apache.cxf.xkms.model.xmldsig.KeyInfoType 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)

Example 7 with KeyInfoType

use of org.apache.cxf.xkms.model.xmldsig.KeyInfoType 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 8 with KeyInfoType

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

the class XKMSServiceTest method locateCertificate.

private void locateCertificate(LocateRequestType request, QueryKeyBindingType queryKeyBindingType, UseKeyWithType useKeyWithType) {
    queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
    request.setQueryKeyBinding(queryKeyBindingType);
    LocateResultType result = xkmsService.locate(request);
    assertSuccess(result);
    List<UnverifiedKeyBindingType> keyBinding = result.getUnverifiedKeyBinding();
    Assert.assertEquals(1, keyBinding.size());
    KeyInfoType keyInfo = keyBinding.get(0).getKeyInfo();
    Assert.assertNotNull(keyInfo);
}
Also used : LocateResultType(org.apache.cxf.xkms.model.xkms.LocateResultType) UnverifiedKeyBindingType(org.apache.cxf.xkms.model.xkms.UnverifiedKeyBindingType) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType)

Example 9 with KeyInfoType

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

the class XKMSServiceTest method testRegisterWithoutKey.

@Test
public void testRegisterWithoutKey() throws URISyntaxException, Exception {
    RegisterRequestType request = new RegisterRequestType();
    setGenericRequestParams(request);
    PrototypeKeyBindingType binding = new PrototypeKeyBindingType();
    KeyInfoType keyInfo = new KeyInfoType();
    binding.setKeyInfo(keyInfo);
    request.setPrototypeKeyBinding(binding);
    RegisterResultType result = xkmsService.register(request);
    Assert.assertEquals(ResultMajorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_SENDER.value(), result.getResultMajor());
    Assert.assertEquals(ResultMinorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_FAILURE.value(), result.getResultMinor());
}
Also used : RegisterResultType(org.apache.cxf.xkms.model.xkms.RegisterResultType) PrototypeKeyBindingType(org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType) RegisterRequestType(org.apache.cxf.xkms.model.xkms.RegisterRequestType) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType) BasicIntegrationTest(org.apache.cxf.xkms.itests.BasicIntegrationTest) Test(org.junit.Test)

Aggregations

KeyInfoType (org.apache.cxf.xkms.model.xmldsig.KeyInfoType)9 X509DataType (org.apache.cxf.xkms.model.xmldsig.X509DataType)5 QueryKeyBindingType (org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)4 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 X509Certificate (java.security.cert.X509Certificate)3 PrototypeKeyBindingType (org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType)3 ValidateRequestType (org.apache.cxf.xkms.model.xkms.ValidateRequestType)3 CertificateException (java.security.cert.CertificateException)2 CertificateFactory (java.security.cert.CertificateFactory)2 LocateResultType (org.apache.cxf.xkms.model.xkms.LocateResultType)2 RegisterRequestType (org.apache.cxf.xkms.model.xkms.RegisterRequestType)2 RegisterResultType (org.apache.cxf.xkms.model.xkms.RegisterResultType)2 UseKeyWithType (org.apache.cxf.xkms.model.xkms.UseKeyWithType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Certificate (java.security.cert.Certificate)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1