use of com.disney.http.auth.keychain.MapKeyChainImpl in project groovity by disney.
the class VerifierFactory method processSignature.
@SuppressWarnings({ "unchecked", "rawtypes" })
private SignatureVerifierImpl processSignature(Map signature, Class<Script> scriptClass) throws InstantiationException, IllegalAccessException, ClassNotFoundException, MalformedURLException, URISyntaxException, NoSuchAlgorithmException, InvalidKeySpecException, CertificateException {
SignatureVerifierImpl verifier = new SignatureVerifierImpl();
processCommon(verifier, signature, scriptClass);
List<KeyChain> keyChains = new ArrayList<KeyChain>();
List headers = (List) signature.get("headers");
if (headers != null) {
verifier.setRequiredHeaders(headers);
}
Number drift = (Number) signature.get("drift");
if (drift != null) {
verifier.setMaxDateDrift(drift.longValue());
}
Map<Object, Map> keys = (Map) signature.get("keys");
if (keys != null) {
// we need to convert to proper Key objects
Map<String, Key> realKeys = new HashMap<String, Key>();
for (Entry<Object, Map> entry : keys.entrySet()) {
String algorithm = (String) entry.getValue().get("algorithm");
Object secret = entry.getValue().get("key");
String signingAlg = Algorithms.getSecurityAlgorithm(algorithm);
Key key;
if (signingAlg.startsWith("Hmac")) {
// expect base 64 encoding
key = new SecretKeySpec(DatatypeConverter.parseBase64Binary(secret.toString()), signingAlg);
} else {
// expect x509 encoding
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(secret.toString())));
key = certificate.getPublicKey();
/*X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(DatatypeConverter.parseBase64Binary(secret.toString()));
KeyFactory factory = KeyFactory.getInstance("rsa");
key = factory.generatePublic(pubKeySpec);
*/
}
realKeys.put(entry.getKey().toString(), key);
}
keyChains.add(new MapKeyChainImpl(realKeys));
}
Map keystore = (Map) signature.get("keystore");
if (keystore != null) {
keyChains.add(makeKeyStoreLoader(keystore));
}
List<Map> keystores = (List<Map>) signature.get("keystores");
if (keystores != null) {
for (Map k : keystores) {
keyChains.add(makeKeyStoreLoader(k));
}
}
Object keychain = signature.get("keychain");
addKeychain(keychain, keyChains, scriptClass);
List kcs = (List) signature.get("keychains");
if (kcs != null) {
for (Object kc : kcs) {
addKeychain(kc, keyChains, scriptClass);
}
}
verifier.setKeyChains(keyChains);
return verifier;
}
use of com.disney.http.auth.keychain.MapKeyChainImpl in project groovity by disney.
the class XmlPolicyParser method processSignature.
private static SignatureVerifierImpl processSignature(Element sig, ServletContext context) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException, MalformedURLException, URISyntaxException {
SignatureVerifierImpl config = new SignatureVerifierImpl();
List<KeyChain> keyChains = new ArrayList<KeyChain>();
processCommon(config, sig);
NodeList bcnodes = sig.getChildNodes();
for (int j = 0; j < bcnodes.getLength(); j++) {
Node bcnode = bcnodes.item(j);
if (bcnode instanceof Element) {
Element bcel = (Element) bcnode;
if (bcel.getNodeName().equals("drift")) {
config.setMaxDateDrift(Long.parseLong(bcel.getTextContent().trim()));
} else if (bcel.getNodeName().equals("headers")) {
config.setRequiredHeaders(Arrays.asList(bcel.getTextContent().trim().split("(,\\s*|\\s+)")));
} else if (bcel.getNodeName().equals("keys")) {
keyChains.add(new MapKeyChainImpl(processKeys(bcel)));
} else if (bcel.getNodeName().equals("keystore")) {
keyChains.add(processKeystore(bcel, context));
}
}
}
config.setKeyChains(keyChains);
return config;
}
Aggregations