Search in sources :

Example 1 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class XKMSInvoker method prepareLocateXKMSRequest.

protected LocateRequestType prepareLocateXKMSRequest(List<X509AppId> ids) {
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    for (X509AppId id : ids) {
        UseKeyWithType useKeyWithType = XKMS_OF.createUseKeyWithType();
        useKeyWithType.setIdentifier(id.getId());
        useKeyWithType.setApplication(id.getApplication().getUri());
        queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
    }
    LocateRequestType locateRequestType = XKMS_OF.createLocateRequestType();
    locateRequestType.setQueryKeyBinding(queryKeyBindingType);
    setGenericRequestParams(locateRequestType);
    return locateRequestType;
}
Also used : QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType)

Example 2 with UseKeyWithType

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

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class X509LocatorTest method prepareLocateXKMSRequest.

private LocateRequestType prepareLocateXKMSRequest() {
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    UseKeyWithType useKeyWithType = XKMS_OF.createUseKeyWithType();
    useKeyWithType.setIdentifier("alice");
    useKeyWithType.setApplication(Applications.PKIX.getUri());
    queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
    LocateRequestType locateRequestType = XKMS_OF.createLocateRequestType();
    locateRequestType.setQueryKeyBinding(queryKeyBindingType);
    setGenericRequestParams(locateRequestType);
    return locateRequestType;
}
Also used : QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType)

Example 4 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class FileCertificateRepoTest method testSaveAndFind.

@Test
public void testSaveAndFind() throws CertificateException, IOException, URISyntaxException {
    File storageDir = new File("target/teststore1");
    storageDir.mkdirs();
    FileCertificateRepo fileRegisterHandler = new FileCertificateRepo("target/teststore1");
    InputStream is = this.getClass().getResourceAsStream("/store1/" + EXPECTED_CERT_FILE_NAME);
    if (is == null) {
        throw new RuntimeException("Can not find path " + is + " in classpath");
    }
    X509Certificate cert = loadTestCert(is);
    UseKeyWithType key = new UseKeyWithType();
    key.setApplication(Applications.PKIX.getUri());
    key.setIdentifier(EXAMPLE_SUBJECT_DN);
    fileRegisterHandler.saveCertificate(cert, key);
    File certFile = new File(storageDir, fileRegisterHandler.getCertPath(cert, key));
    Assert.assertTrue("Cert file " + certFile + " should exist", certFile.exists());
    try (FileInputStream fis = new FileInputStream(certFile)) {
        X509Certificate outCert = loadTestCert(fis);
        Assert.assertEquals(cert, outCert);
    }
    X509Certificate resultCert = fileRegisterHandler.findBySubjectDn(EXAMPLE_SUBJECT_DN);
    Assert.assertNotNull(resultCert);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class LDAPCertificateRepoTest method testSaveServiceCert.

@Test
public void testSaveServiceCert() throws Exception {
    IMocksControl c = EasyMock.createControl();
    LdapSearch ldapSearch = c.createMock(LdapSearch.class);
    ldapSearch.bind(EasyMock.eq(EXPECTED_DN_FOR_SERVICE + "," + ROOT_DN), EasyMock.anyObject(Attributes.class));
    EasyMock.expectLastCall().once();
    LdapCertificateRepo ldapCertRepo = new LdapCertificateRepo(ldapSearch, LDAP_CERT_CONFIG, ROOT_DN);
    X509Certificate cert = getTestCert();
    c.replay();
    UseKeyWithType key = new UseKeyWithType();
    key.setApplication(Applications.SERVICE_NAME.getUri());
    key.setIdentifier(EXPECTED_SERVICE_URI);
    ldapCertRepo.saveCertificate(cert, key);
    c.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Attributes(javax.naming.directory.Attributes) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Aggregations

UseKeyWithType (org.apache.cxf.xkms.model.xkms.UseKeyWithType)14 X509Certificate (java.security.cert.X509Certificate)6 Test (org.junit.Test)6 QueryKeyBindingType (org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)5 File (java.io.File)4 LocateRequestType (org.apache.cxf.xkms.model.xkms.LocateRequestType)4 FileInputStream (java.io.FileInputStream)2 CertificateException (java.security.cert.CertificateException)2 ArrayList (java.util.ArrayList)2 Attributes (javax.naming.directory.Attributes)2 BasicIntegrationTest (org.apache.cxf.xkms.itests.BasicIntegrationTest)2 FileCertificateRepo (org.apache.cxf.xkms.x509.repo.file.FileCertificateRepo)2 IMocksControl (org.easymock.IMocksControl)2 Before (org.junit.Before)2 InputStream (java.io.InputStream)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 CertificateFactory (java.security.cert.CertificateFactory)1 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 XKMSCertificateException (org.apache.cxf.xkms.exception.XKMSCertificateException)1