use of org.apache.cxf.xkms.model.xkms.QueryKeyBindingType 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);
}
use of org.apache.cxf.xkms.model.xkms.QueryKeyBindingType 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;
}
use of org.apache.cxf.xkms.model.xkms.QueryKeyBindingType 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;
}
use of org.apache.cxf.xkms.model.xkms.QueryKeyBindingType 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;
}
use of org.apache.cxf.xkms.model.xkms.QueryKeyBindingType 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;
}
Aggregations