Search in sources :

Example 11 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(LocateRequestType request) {
    List<UseKeyWithType> keyIDs = new ArrayList<>();
    if (request == null) {
        return keyIDs;
    }
    QueryKeyBindingType query = request.getQueryKeyBinding();
    if (query == null) {
        return keyIDs;
    }
    // http://www.w3.org/TR/xkms2/ [213]
    if (query.getTimeInstant() != null) {
        throw new XKMSException(ResultMajorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_RECEIVER, ResultMinorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_TIME_INSTANT_NOT_SUPPORTED);
    }
    keyIDs.addAll(parse(query.getKeyInfo()));
    List<UseKeyWithType> useKeyList = query.getUseKeyWith();
    keyIDs.addAll(useKeyList);
    return keyIDs;
}
Also used : XKMSException(org.apache.cxf.xkms.exception.XKMSException) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) ArrayList(java.util.ArrayList) QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)

Example 12 with UseKeyWithType

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

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

the class TrustedAuthorityValidatorCRLTest method setUpCertificateRepo.

@Before
public void setUpCertificateRepo() throws CertificateException {
    File storageDir = new File("target/teststore_trusted_authority_validator");
    FileUtils.removeDir(storageDir);
    storageDir.mkdirs();
    certificateRepo = new FileCertificateRepo("target/teststore_trusted_authority_validator");
    UseKeyWithType rootKey = new UseKeyWithType();
    rootKey.setApplication(Applications.PKIX.getUri());
    String subjectDN = certificateRoot.getSubjectX500Principal().getName();
    rootKey.setIdentifier(subjectDN);
    certificateRepo.saveTrustedCACertificate(certificateRoot, rootKey);
    UseKeyWithType aliceKey = new UseKeyWithType();
    aliceKey.setApplication(Applications.PKIX.getUri());
    subjectDN = certificateWss40Rev.getSubjectX500Principal().getName();
    aliceKey.setIdentifier(subjectDN);
    certificateRepo.saveCACertificate(certificateWss40Rev, aliceKey);
    UseKeyWithType bobKey = new UseKeyWithType();
    bobKey.setApplication(Applications.PKIX.getUri());
    subjectDN = certificateWss40.getSubjectX500Principal().getName();
    bobKey.setIdentifier(subjectDN);
    certificateRepo.saveCACertificate(certificateWss40, bobKey);
    UseKeyWithType crlKey = new UseKeyWithType();
    crlKey.setApplication(Applications.PKIX.getUri());
    crlKey.setIdentifier(crl.getIssuerX500Principal().getName());
    certificateRepo.saveCRL(crl, crlKey);
}
Also used : UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) File(java.io.File) FileCertificateRepo(org.apache.cxf.xkms.x509.repo.file.FileCertificateRepo) Before(org.junit.Before)

Example 14 with UseKeyWithType

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

the class TrustedAuthorityValidatorTest method setUpCertificateRepo.

@Before
public void setUpCertificateRepo() throws CertificateException {
    File storageDir = new File("target/teststore_trusted_authority_validator");
    FileUtils.removeDir(storageDir);
    storageDir.mkdirs();
    certificateRepo = new FileCertificateRepo("target/teststore_trusted_authority_validator");
    UseKeyWithType rootKey = new UseKeyWithType();
    rootKey.setApplication(Applications.PKIX.getUri());
    String subjectDN = certificateRoot.getSubjectX500Principal().getName();
    rootKey.setIdentifier(subjectDN);
    certificateRepo.saveTrustedCACertificate(certificateRoot, rootKey);
    UseKeyWithType aliceKey = new UseKeyWithType();
    aliceKey.setApplication(Applications.PKIX.getUri());
    subjectDN = certificateAlice.getSubjectX500Principal().getName();
    aliceKey.setIdentifier(subjectDN);
    certificateRepo.saveCACertificate(certificateAlice, aliceKey);
}
Also used : UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) File(java.io.File) FileCertificateRepo(org.apache.cxf.xkms.x509.repo.file.FileCertificateRepo) Before(org.junit.Before)

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