use of javax.xml.crypto.KeySelectorException in project camel by apache.
the class DefaultKeySelector method select.
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
if (keyStoreAndAlias.getKeyStore() == null) {
return getNullKeyResult();
}
if (keyStoreAndAlias.getAlias() == null) {
return getNullKeyResult();
}
if (KeySelector.Purpose.VERIFY.equals(purpose)) {
Certificate cert;
try {
cert = keyStoreAndAlias.getKeyStore().getCertificate(keyStoreAndAlias.getAlias());
} catch (KeyStoreException e) {
throw new KeySelectorException(e);
}
if (cert == null) {
return getNullKeyResult();
}
final Key key = cert.getPublicKey();
return getKeySelectorResult(key);
} else if (KeySelector.Purpose.SIGN.equals(purpose)) {
if (keyStoreAndAlias.getPassword() == null) {
return getNullKeyResult();
}
Key key;
try {
if (this.getCamelContext() != null && keyStoreAndAlias.getPassword() != null) {
try {
String passwordProperty = this.getCamelContext().resolvePropertyPlaceholders(new String(keyStoreAndAlias.getPassword()));
key = keyStoreAndAlias.getKeyStore().getKey(keyStoreAndAlias.getAlias(), passwordProperty.toCharArray());
} catch (Exception e) {
throw new RuntimeCamelException("Error parsing property value: " + new String(keyStoreAndAlias.getPassword()), e);
}
} else {
key = keyStoreAndAlias.getKeyStore().getKey(keyStoreAndAlias.getAlias(), keyStoreAndAlias.getPassword());
}
} catch (UnrecoverableKeyException e) {
throw new KeySelectorException(e);
} catch (KeyStoreException e) {
throw new KeySelectorException(e);
} catch (NoSuchAlgorithmException e) {
throw new KeySelectorException(e);
}
return getKeySelectorResult(key);
} else {
throw new IllegalStateException("Purpose " + purpose + " not supported");
}
}
use of javax.xml.crypto.KeySelectorException in project poi by apache.
the class KeyInfoKeySelector method select.
@SuppressWarnings("unchecked")
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
LOG.log(POILogger.DEBUG, "select key");
if (null == keyInfo) {
throw new KeySelectorException("no ds:KeyInfo present");
}
List<XMLStructure> keyInfoContent = keyInfo.getContent();
certChain.clear();
for (XMLStructure keyInfoStructure : keyInfoContent) {
if (!(keyInfoStructure instanceof X509Data)) {
continue;
}
X509Data x509Data = (X509Data) keyInfoStructure;
List<?> x509DataList = x509Data.getContent();
for (Object x509DataObject : x509DataList) {
if (!(x509DataObject instanceof X509Certificate)) {
continue;
}
X509Certificate certificate = (X509Certificate) x509DataObject;
LOG.log(POILogger.DEBUG, "certificate", certificate.getSubjectX500Principal());
certChain.add(certificate);
}
}
if (certChain.isEmpty()) {
throw new KeySelectorException("No key found!");
}
return this;
}
Aggregations