Search in sources :

Example 1 with KeyInfoType

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

the class XKMSTest method testRegisterUnitTest.

@org.junit.Test
public void testRegisterUnitTest() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = XKMSTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    // XKMSTest.class.getResource("xkms.wsdl");
    URL wsdl = new URL("https://localhost:" + PORT2 + "/XKMS?wsdl");
    String ns = "http://www.w3.org/2002/03/xkms#wsdl";
    QName serviceQName = new QName(ns, "XKMSService");
    Service service = Service.create(wsdl, serviceQName);
    QName portQName = new QName(NAMESPACE, "XKMSPort");
    XKMSPortType port = service.getPort(portQName, XKMSPortType.class);
    // updateAddressPort(port, PORT2);
    // First try to locate - which should fail
    LocateRequestType locateRequest = new LocateRequestType();
    locateRequest.setId("_xyz");
    locateRequest.setService("http://cxf.apache.org/services/XKMS/");
    QueryKeyBindingType queryKeyBinding = new QueryKeyBindingType();
    UseKeyWithType useKeyWithType = new UseKeyWithType();
    useKeyWithType.setApplication("urn:ietf:rfc:2459");
    useKeyWithType.setIdentifier("CN=client");
    queryKeyBinding.getUseKeyWith().add(useKeyWithType);
    locateRequest.setQueryKeyBinding(queryKeyBinding);
    LocateResultType locateResultType = port.locate(locateRequest);
    assertTrue(locateResultType.getResultMajor().endsWith("Success"));
    assertTrue(locateResultType.getResultMinor().endsWith("NoMatch"));
    // Now register
    RegisterRequestType registerRequest = new RegisterRequestType();
    registerRequest.setId("_xyz");
    registerRequest.setService("http://cxf.apache.org/services/XKMS/");
    PrototypeKeyBindingType prototypeKeyBinding = new PrototypeKeyBindingType();
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    InputStream certInputStream = ClassLoaderUtils.getResourceAsStream("xkmstest.cer", this.getClass());
    Certificate certificate = certificateFactory.generateCertificate(certInputStream);
    KeyInfoType keyInfo = X509Utils.getKeyInfo((X509Certificate) certificate);
    prototypeKeyBinding.setKeyInfo(keyInfo);
    prototypeKeyBinding.getUseKeyWith().add(useKeyWithType);
    registerRequest.setPrototypeKeyBinding(prototypeKeyBinding);
    RegisterResultType registerResult = port.register(registerRequest);
    assertTrue(registerResult.getResultMajor().endsWith("Success"));
    assertFalse(registerResult.getKeyBinding().isEmpty());
    // Now locate again - which should work
    locateResultType = port.locate(locateRequest);
    assertTrue(locateResultType.getResultMajor().endsWith("Success"));
    assertFalse(locateResultType.getUnverifiedKeyBinding().isEmpty());
    // Delete the certificate so that the test works when run again
    Path path = FileSystems.getDefault().getPath("target/test-classes/certs/xkms/CN-client.cer");
    Files.delete(path);
}
Also used : Path(java.nio.file.Path) Bus(org.apache.cxf.Bus) RegisterResultType(org.apache.cxf.xkms.model.xkms.RegisterResultType) PrototypeKeyBindingType(org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) RegisterRequestType(org.apache.cxf.xkms.model.xkms.RegisterRequestType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) Service(javax.xml.ws.Service) XKMSPortType(org.w3._2002._03.xkms_wsdl.XKMSPortType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType) CertificateFactory(java.security.cert.CertificateFactory) URL(java.net.URL) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) LocateResultType(org.apache.cxf.xkms.model.xkms.LocateResultType) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 2 with KeyInfoType

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

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

the class X509Register method register.

@Override
public RegisterResultType register(RegisterRequestType request, RegisterResultType response) {
    try {
        PrototypeKeyBindingType binding = request.getPrototypeKeyBinding();
        X509Utils.assertElementNotNull(binding, PrototypeKeyBindingType.class);
        KeyInfoType keyInfo = binding.getKeyInfo();
        X509Utils.assertElementNotNull(binding, KeyInfoType.class);
        List<UseKeyWithType> useKeyWithList = binding.getUseKeyWith();
        if (useKeyWithList == null || useKeyWithList.size() != 1) {
            throw new IllegalArgumentException("Exactly one useKeyWith element is supported");
        // TODO standard requires support for multiple useKeyWith attributes
        }
        UseKeyWithType useKeyWith = useKeyWithList.get(0);
        List<X509Certificate> certList = getCertsFromKeyInfo(keyInfo);
        if (certList.size() != 1) {
            throw new IllegalArgumentException("Must provide one X509Certificate");
        }
        X509Certificate cert = certList.get(0);
        certRepo.saveCertificate(cert, useKeyWith);
        KeyBindingType responseBinding = prepareResponseBinding(binding);
        response.getKeyBinding().add(responseBinding);
        return response;
    } catch (CertificateException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : PrototypeKeyBindingType(org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) CertificateException(java.security.cert.CertificateException) PrototypeKeyBindingType(org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType) KeyBindingType(org.apache.cxf.xkms.model.xkms.KeyBindingType) X509Certificate(java.security.cert.X509Certificate) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType)

Example 4 with KeyInfoType

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

the class X509Utils method getKeyInfo.

public static KeyInfoType getKeyInfo(X509Certificate cert) throws CertificateEncodingException {
    KeyInfoType keyInfo = new KeyInfoType();
    JAXBElement<byte[]> certificate = new ObjectFactory().createX509DataTypeX509Certificate(cert.getEncoded());
    X509DataType x509DataType = new X509DataType();
    List<Object> x509DataContent = x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName();
    x509DataContent.add(certificate);
    JAXBElement<X509DataType> x509Data = new ObjectFactory().createX509Data(x509DataType);
    List<Object> keyInfoContent = keyInfo.getContent();
    keyInfoContent.add(x509Data);
    return keyInfo;
}
Also used : X509DataType(org.apache.cxf.xkms.model.xmldsig.X509DataType) ObjectFactory(org.apache.cxf.xkms.model.xmldsig.ObjectFactory) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType)

Example 5 with KeyInfoType

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

the class ValidatorTest method prepareValidateXKMSRequest.

/*
     * Method is taken from {@link org.apache.cxf.xkms.client.XKMSInvokder}.
     */
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)

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