use of java.security.KeyStore in project camel by apache.
the class SignatureTests method testProvideCertificateInHeader.
@Test
public void testProvideCertificateInHeader() throws Exception {
setupMock();
Exchange unsigned = getMandatoryEndpoint("direct:signature-property").createExchange();
unsigned.getIn().setBody(payload);
// create a keypair
KeyStore keystore = loadKeystore();
Certificate certificate = keystore.getCertificate("bob");
PrivateKey pk = (PrivateKey) keystore.getKey("bob", "letmein".toCharArray());
// sign with the private key
unsigned.getIn().setHeader(SIGNATURE_PRIVATE_KEY, pk);
template.send("direct:headerkey-sign", unsigned);
// verify with the public key
Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange();
signed.getIn().copyFrom(unsigned.getOut());
signed.getIn().setHeader(SIGNATURE_PUBLIC_KEY_OR_CERT, certificate);
template.send("direct:headerkey-verify", signed);
assertMockEndpointsSatisfied();
}
use of java.security.KeyStore in project camel by apache.
the class SigningProcessor method getKeyPassword.
protected char[] getKeyPassword(Exchange exchange) throws Exception {
KeyStore keystore = config.getKeystore();
char[] password = null;
if (keystore != null) {
password = exchange.getIn().getHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, char[].class);
if (password == null) {
password = config.getPassword();
}
}
return password;
}
use of java.security.KeyStore in project httpclient by pixmob.
the class HttpRequestBuilder method loadCertificates.
private static KeyStore loadCertificates(Context context) throws IOException {
try {
final KeyStore localTrustStore = KeyStore.getInstance("BKS");
final InputStream in = context.getResources().openRawResource(R.raw.hc_keystore);
try {
localTrustStore.load(in, null);
} finally {
in.close();
}
return localTrustStore;
} catch (Exception e) {
final IOException ioe = new IOException("Failed to load SSL certificates");
ioe.initCause(e);
throw ioe;
}
}
use of java.security.KeyStore in project platformlayer by platformlayer.
the class KeystoneCliContext method getCertificateChain.
public Certificate[] getCertificateChain(String keystore, String keystoreSecret, String keyAlias) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
if (getOptions().isServerMode()) {
throw new IllegalArgumentException("Files not supported in server mode");
}
if (keystoreSecret == null) {
keystoreSecret = KeyStoreUtils.DEFAULT_KEYSTORE_SECRET;
}
KeyStore keyStore = KeyStoreUtils.load(new File(keystore), keystoreSecret);
if (keyAlias == null) {
List<String> keyAliases = KeyStoreUtils.getKeyAliases(keyStore);
if (keyAliases.size() == 0) {
throw new CliException("No keys found in keystore");
}
if (keyAliases.size() != 1) {
System.out.println("Found keys:\n\t" + Joiner.on("\n\t").join(keyAliases));
throw new CliException("Multiple keys found in keystore; specify --alias");
}
keyAlias = keyAliases.get(0);
}
Certificate[] certificateChain = keyStore.getCertificateChain(keyAlias);
return certificateChain;
}
use of java.security.KeyStore in project robovm by robovm.
the class DefaultSSLContextImpl method getTrustManagers.
// TODO javax.net.ssl.trustStoreProvider system property
TrustManager[] getTrustManagers() throws GeneralSecurityException, IOException {
if (TRUST_MANAGERS != null) {
return TRUST_MANAGERS;
}
// find TrustStore, TrustManagers
String keystore = System.getProperty("javax.net.ssl.trustStore");
if (keystore == null) {
return null;
}
String keystorepwd = System.getProperty("javax.net.ssl.trustStorePassword");
char[] pwd = (keystorepwd == null) ? null : keystorepwd.toCharArray();
// TODO Defaults: jssecacerts; cacerts
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(keystore));
ks.load(is, pwd);
} finally {
if (is != null) {
is.close();
}
}
String tmfAlg = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlg);
tmf.init(ks);
TRUST_MANAGERS = tmf.getTrustManagers();
return TRUST_MANAGERS;
}
Aggregations