useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_TLS);
useKeyWithType.setIdentifier("http://www.test.com/" + username2);
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
QueryKeyBindingType queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
LocateResultType locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
assertEquals("Wrong number of UnverifiedKeyBinding.", 1, locateResultType.getUnverifiedKeyBinding().size());
// Locate by DNS Name
locateRequestType = xKMSObjectFactory.createLocateRequestType();
locateRequestType.setId("127");
useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_TLSSMTP);
useKeyWithType.setIdentifier(username2 + ".test.com");
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
assertTrue(locateResultType.getUnverifiedKeyBinding().size() == 1);
// Locate by IP Name
locateRequestType = xKMSObjectFactory.createLocateRequestType();
locateRequestType.setId("128");
useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_IPSEC);
useKeyWithType.setIdentifier("10.0.0.1");
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
assertTrue(locateResultType.getUnverifiedKeyBinding().size() > 0);
// Locate by Subject DN
locateRequestType = xKMSObjectFactory.createLocateRequestType();
locateRequestType.setId("129");
useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
useKeyWithType.setIdentifier(dn1);
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
assertEquals("locateResultType.getUnverifiedKeyBinding: ", 1, locateResultType.getUnverifiedKeyBinding().size());
// Locate by With a more complicated query
locateRequestType = xKMSObjectFactory.createLocateRequestType();
locateRequestType.setId("129");
useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
useKeyWithType.setIdentifier(dn1);
UseKeyWithType useKeyWithType2 = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType2.setApplication(XKMSConstants.USEKEYWITH_TLSSMTP);
useKeyWithType2.setIdentifier(username2 + ".test.com");
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
queryKeyBindingType.getUseKeyWith().add(useKeyWithType2);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
// Should return the cert of username1 and username2
assertTrue(locateResultType.getUnverifiedKeyBinding().size() == 2);
// Locate by With a more complicated query but results in only one cert
locateRequestType = xKMSObjectFactory.createLocateRequestType();
locateRequestType.setId("129");
useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
useKeyWithType.setIdentifier(dn2);
useKeyWithType2 = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType2.setApplication(XKMSConstants.USEKEYWITH_TLSSMTP);
useKeyWithType2.setIdentifier(username2 + ".test.com");
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
queryKeyBindingType.getUseKeyWith().add(useKeyWithType2);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
assertTrue(locateResultType.getUnverifiedKeyBinding().size() == 1);
// Locate by With a more complicated query with one subquery doesn't
// match
locateRequestType = xKMSObjectFactory.createLocateRequestType();
locateRequestType.setId("129");
useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
useKeyWithType.setIdentifier("CN=nomatch");
useKeyWithType2 = xKMSObjectFactory.createUseKeyWithType();
useKeyWithType2.setApplication(XKMSConstants.USEKEYWITH_TLSSMTP);
useKeyWithType2.setIdentifier(username2 + ".test.com");
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
queryKeyBindingType.getUseKeyWith().add(useKeyWithType2);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
assertTrue(locateResultType.getUnverifiedKeyBinding().size() == 1);
// Test with certificate
locateRequestType = xKMSObjectFactory.createLocateRequestType();
locateRequestType.setId("130");
queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
X509DataType x509DataType = sigFactory.createX509DataType();
x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(sigFactory.createX509DataTypeX509Certificate(cert1.getEncoded()));
KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
keyInfoType.getContent().add(sigFactory.createX509Data(x509DataType));
queryKeyBindingType.setKeyInfo(keyInfoType);
locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
locateRequestType.setQueryKeyBinding(queryKeyBindingType);
locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
assertTrue(locateResultType.getUnverifiedKeyBinding().size() == 1);