Search in sources :

Example 6 with KeystoreLocation

use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.

the class TestKeystoreLocation method testKeystoreEquality.

@Test
public void testKeystoreEquality() {
    try {
        KeystoreLocation ksi = KeystoreFactory.getDefault().create("JKS:///c:/fred.ks", "abcde".toCharArray());
        KeystoreLocation ksi2 = KeystoreFactory.getDefault().create("file:///c:/fred.ks?keystoreType=JKS", "abcde".toCharArray());
        assertEquals("Keystore Equality", ksi, ksi2);
    } catch (Exception e) {
        logR.error("testKeystoreFactory failed", e);
        fail(e.getMessage());
    }
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) Test(org.junit.Test)

Example 7 with KeystoreLocation

use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.

the class TestKeystoreLocation method testKeystoreFactory.

@Test
public void testKeystoreFactory() {
    try {
        KeystoreLocation ksi = KeystoreFactory.getDefault().create("jks:///c:/fred.ks", "abcde".toCharArray());
        KeystoreLocation ksi2 = KeystoreFactory.getDefault().create("file:///c:/fred.ks?keystoreType=JKS&keystorePassword=abcde");
        assertEquals("Keystore Equality", ksi, ksi2);
    } catch (Exception e) {
        logR.error("testKeystoreFactory failed", e);
        fail(e.getMessage());
    }
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) Test(org.junit.Test)

Example 8 with KeystoreLocation

use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.

the class TestKeystoreLocation method testRemoteKeystore.

@Test
public void testRemoteKeystore() throws Exception {
    Assume.assumeTrue(Boolean.parseBoolean(cfg.getProperty(Config.REMOTE_TESTS_ENABLED, "false")));
    String ks = cfg.getProperty(Config.KEYSTORE_TEST_URL);
    ks = ks.replaceAll("\\\\", "/");
    URI uri = new URI(ks);
    File keystore = new File(uri.getPath());
    String filename = keystore.getName();
    File newFile = new File(cfg.getProperty(Config.KEYSTORE_REMOTE_REALPATH) + "/" + filename);
    FileUtils.copyFile(keystore, newFile);
    // Thread.sleep(10000);
    logR.debug("newFile " + newFile.getCanonicalPath());
    String keystoreType = uri.getQuery();
    String url = cfg.getProperty(Config.KEYSTORE_REMOTE_ROOT) + filename + "?" + keystoreType;
    KeystoreLocation k = KeystoreFactory.getDefault().create(url, cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray());
    assertTrue("Remote Keystore exists", k.exists());
    InputStream in = k.openInput();
    in.close();
    assertTrue(!k.isWriteable());
    boolean openOutputSuccess = false;
    try {
        OutputStream o = k.openOutput();
        openOutputSuccess = true;
        o.close();
    } catch (Exception e) {
    // Expected as it's non-writeable
    }
    newFile.delete();
    if (openOutputSuccess) {
        fail("Successfully opened output to a remote keystore!");
    }
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Example 9 with KeystoreLocation

use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.

the class VersionedHttpsProduceConnection method initialiseClient.

/**
 * @see HttpClientConnection#initialiseClient(java.lang.String)
 */
@Override
public HttpClientTransport initialiseClient(String url) throws HttpException {
    HttpsClient client = new HttpsClient(new URLString(url), protocolVersion);
    try {
        if (getKeystore() != null) {
            KeystoreFactory ksf = KeystoreFactory.getDefault();
            KeystoreLocation ksl = null;
            if (getKeystorePassword() != null) {
                ksl = ksf.create(getKeystore(), Password.decode(getKeystorePassword()).toCharArray());
            } else {
                ksl = ksf.create(getKeystore());
            }
            char[] pkpw = PasswordOverride.discoverPrivateKeyPassword(ksl, getPrivateKeyPasswordProvider());
            if (pkpw != null) {
                client.registerPrivateKeyPassword(pkpw);
            }
            client.registerKeystore(ksf.create(ksl));
        }
    } catch (AdaptrisSecurityException e) {
        throw new HttpException(e);
    }
    client.setAlwaysTrust(getAlwaysTrust());
    return client;
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) HttpsClient(com.adaptris.http.HttpsClient) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) KeystoreFactory(com.adaptris.security.keystore.KeystoreFactory) HttpException(com.adaptris.http.HttpException) URLString(com.adaptris.util.URLString)

Example 10 with KeystoreLocation

use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.

the class Https method getKeystoreProxy.

static KeystoreProxy getKeystoreProxy(KeystoreProxy ksp) throws Exception {
    if (ksp != null) {
        return ksp;
    }
    initialise();
    String url = httpsProperties.getProperty(CONFIG_KEYSTORE_URL);
    if (url == null) {
        throw new IOException("Could not a keystore url to use in " + CONFIG_PROPERTY_FILE);
    }
    String pw = httpsProperties.getProperty(CONFIG_KEYSTORE_PW);
    KeystoreLocation ksl = null;
    if (pw != null) {
        ksl = KeystoreFactory.getDefault().create(url, Password.decode(pw).toCharArray());
    } else {
        ksl = KeystoreFactory.getDefault().create(url);
    }
    return KeystoreFactory.getDefault().create(ksl);
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) IOException(java.io.IOException)

Aggregations

KeystoreLocation (com.adaptris.security.keystore.KeystoreLocation)12 Test (org.junit.Test)6 KeystoreProxy (com.adaptris.security.keystore.KeystoreProxy)3 HttpException (com.adaptris.http.HttpException)2 HttpsClient (com.adaptris.http.HttpsClient)2 CertificateBuilder (com.adaptris.security.certificate.CertificateBuilder)2 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)2 KeystoreFactory (com.adaptris.security.keystore.KeystoreFactory)2 InputStream (java.io.InputStream)2 PrivateKey (java.security.PrivateKey)2 Certificate (java.security.cert.Certificate)2 URLString (com.adaptris.util.URLString)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1