use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class JwsJsonConsumerTest method testVerifyDualSignedDocument.
@Test
public void testVerifyDualSignedDocument() throws Exception {
JwsJsonConsumer consumer = new JwsJsonConsumer(DUAL_SIGNED_DOCUMENT);
JsonWebKeys jwks = readKeySet("jwkPublicJsonConsumerSet.txt");
List<JwsJsonSignatureEntry> sigEntries = consumer.getSignatureEntries();
assertEquals(2, sigEntries.size());
// 1st signature
String firstKid = sigEntries.get(0).getKeyId();
assertEquals(KID_OF_THE_FIRST_SIGNER, firstKid);
JsonWebKey rsaKey = jwks.getKey(firstKid);
assertNotNull(rsaKey);
assertTrue(sigEntries.get(0).verifySignatureWith(rsaKey));
// 2nd signature
String secondKid = sigEntries.get(1).getKeyId();
assertEquals(KID_OF_THE_SECOND_SIGNER, secondKid);
JsonWebKey ecKey = jwks.getKey(secondKid);
assertNotNull(ecKey);
assertTrue(sigEntries.get(1).verifySignatureWith(ecKey));
}
use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class JwsUtilsTest method testLoadVerificationKeyWithCert.
@Test
public void testLoadVerificationKeyWithCert() throws Exception {
Properties p = new Properties();
p.put(JoseConstants.RSSEC_KEY_STORE_FILE, "org/apache/cxf/rs/security/jose/jws/alice.jks");
p.put(JoseConstants.RSSEC_KEY_STORE_PSWD, "password");
p.put(JoseConstants.RSSEC_KEY_STORE_ALIAS, "alice");
p.put(JoseConstants.RSSEC_SIGNATURE_INCLUDE_CERT, true);
JsonWebKeys keySet = JwsUtils.loadPublicVerificationKeys(createMessage(), p);
assertEquals(1, keySet.asMap().size());
List<JsonWebKey> keys = keySet.getRsaKeys();
assertEquals(1, keys.size());
JsonWebKey key = keys.get(0);
assertEquals(KeyType.RSA, key.getKeyType());
assertEquals("alice", key.getKeyId());
assertNotNull(key.getKeyProperty(JsonWebKey.RSA_PUBLIC_EXP));
assertNotNull(key.getKeyProperty(JsonWebKey.RSA_MODULUS));
assertNull(key.getKeyProperty(JsonWebKey.RSA_PRIVATE_EXP));
List<String> chain = key.getX509Chain();
assertNotNull(chain);
assertEquals(2, chain.size());
}
use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class JweUtils method loadPublicKeyEncryptionKeys.
public static JsonWebKeys loadPublicKeyEncryptionKeys(Message m, Properties props) {
String storeType = props.getProperty(JoseConstants.RSSEC_KEY_STORE_TYPE);
if ("jwk".equals(storeType)) {
return JwkUtils.loadPublicJwkSet(m, props);
}
// TODO: consider loading all the public keys in the store
PublicKey key = KeyManagementUtils.loadPublicKey(m, props);
JsonWebKey jwk = JwkUtils.fromPublicKey(key, props, JoseConstants.RSSEC_ENCRYPTION_KEY_ALGORITHM);
return new JsonWebKeys(jwk);
}
use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class JwkJoseCookBookTest method testPublicSetAsList.
@Test
public void testPublicSetAsList() throws Exception {
JsonWebKeys jwks = readKeySet("cookbookPublicSet.txt");
List<JsonWebKey> keys = jwks.getKeys();
assertEquals(2, keys.size());
JsonWebKey ecKey = keys.get(0);
assertEquals(6, ecKey.asMap().size());
validatePublicEcKey(ecKey);
JsonWebKey rsaKey = keys.get(1);
assertEquals(5, rsaKey.asMap().size());
validatePublicRsaKey(rsaKey);
}
use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class JwkJoseCookBookTest method testSecretSetAsList.
@Test
public void testSecretSetAsList() throws Exception {
JsonWebKeys jwks = readKeySet("cookbookSecretSet.txt");
List<JsonWebKey> keys = jwks.getKeys();
assertEquals(2, keys.size());
JsonWebKey signKey = keys.get(0);
assertEquals(5, signKey.asMap().size());
validateSecretSignKey(signKey);
JsonWebKey encKey = keys.get(1);
assertEquals(5, encKey.asMap().size());
validateSecretEncKey(encKey);
}
Aggregations