Search in sources :

Example 6 with ConfiguredUrl

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

the class TestConfiguredUrl method setUp.

@Before
public void setUp() throws Exception {
    Config config = Config.getInstance();
    cfg = config.getProperties();
    if (cfg == null) {
        fail("No Configuration(!) available");
    }
    url = new ConfiguredUrl();
    url.setUrl(cfg.getProperty(Config.KEYSTORE_TEST_URL) + "&" + Constants.KEYSTORE_PASSWORD + "=" + cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW));
    copy = new ConfiguredUrl(cfg.getProperty(Config.KEYSTORE_TEST_URL) + "&" + Constants.KEYSTORE_PASSWORD + "=" + cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW));
    config.buildKeystore(cfg.getProperty(Config.KEYSTORE_TEST_URL), null, true);
}
Also used : ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) Before(org.junit.Before)

Example 7 with ConfiguredUrl

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

the class TestDefaultSecurityService method testDefaultEncryptionWithMultipleKeystores.

@Test
public void testDefaultEncryptionWithMultipleKeystores() throws Exception {
    ConfiguredUrl keystore = new ConfiguredUrl();
    String filename = "" + Math.abs(new Random().nextInt()) + ".ks";
    String newUrl = "file:///" + config.getProperty(Config.CFG_ROOT) + "/" + filename + "?keystoreType=JKS";
    keystore.setUrl(newUrl + "&" + Constants.KEYSTORE_PASSWORD + "=" + config.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW));
    String cn = "OtherUniqueAlias";
    Config.getInstance().buildKeystore(newUrl, cn, false);
    them = new Alias(cn, config.getProperty(Config.KEYSTORE_COMMON_PRIVKEY_PW));
    service.registerKeystore(keystore);
    Output output = service.encrypt(RAW_DATA, us, them);
    output = service.sign(RAW_DATA, us, output);
    String encrypted = output.getAsString();
    output = service.verify(encrypted, them, us);
    String payload = output.getAsString();
    assertEquals("Data Verification", payload, RAW_DATA);
}
Also used : ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) Random(java.util.Random) Alias(com.adaptris.security.keystore.Alias) Test(org.junit.Test)

Example 8 with ConfiguredUrl

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

the class EncryptionServiceCase method applyConfigForSamples.

protected static void applyConfigForSamples(CoreSecurityService service) {
    try {
        service.setLocalPartner("local partner alias in keystore");
        service.setRemotePartner("remote partner alias in keystore");
        service.addKeystoreUrl(new ConfiguredUrl("http://localhost/path/to/JKS/keystore?keystoreType=" + "JKS&keystorePassword=somePlainTextPassword"));
        service.addKeystoreUrl(new ConfiguredUrl("file://localhost/path/to/a/X509/Certificate?keystoreType=" + "X509?keystoreAlias=CertificateAlias"));
        service.addKeystoreUrl(new ConfiguredUrl("file://localhost/path/to/another/X509/Certificate?keystoreType=" + "X509?keystoreAlias=AnotherAlias"));
        service.addKeystoreUrl(new ConfiguredUrl("http://host/path/to/a/PKCS12/Keystore?keystoreType=" + "PKCS12&keystoreAlias=PKCS12Alias", "PW:AAAAEF+zZCbvHeIXDx8HUslqiYwAAAAQ3wi4/BVycX+uzc5zF4F6EQAAABD0hhpr46IrKSu7XxFhEAYN"));
        // service.addKeystoreUrl(new ConfiguredUrl("http://host/path/to/keystore?keystoreType=" + "PKCS12&keystoreAlias=myalias",
        // PROPERTIES.getProperty(SECURITY_PASSWORD)));
        service.addKeystoreUrl(new ConfiguredUrl("http://host/path/to/a/JCE/keystore?keystoreType=JCEKS", "ALTPW:AAAAEF+zZCbvHeIXDx8HUslqiYwAAAAQ3wi4/BVycX+uzc5zF4F6EQAAABD0hhpr46IrKSu7XxFhEAYN"));
        // service.addKeystoreUrl(new ConfiguredUrl("http://host/path/to/keystore?keystoreType=" + "JCEKS&keystoreAlias=myalias",
        // Password.encode(PROPERTIES.getProperty(SECURITY_PASSWORD), Password.NON_PORTABLE_PASSWORD)));
        service.addKeystoreUrl(new ConfiguredUrl("file://local/path/to/anoter/JKS/keystore?keystoreType=" + "JKS&keystoreAlias=myalias", "somePlainTextPassword"));
        InlineKeystore inline = new InlineKeystore();
        inline.setCertificate(EXAMPLE_KEYINFO);
        inline.setType(Constants.KEYSTORE_XMLKEYINFO);
        inline.setAlias("myAlias");
        service.addKeystoreUrl(inline);
        addEncryptionAlgsForFactoryType(service);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InlineKeystore(com.adaptris.security.keystore.InlineKeystore) ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) ServiceException(com.adaptris.core.ServiceException) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException)

Example 9 with ConfiguredUrl

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

the class SecurityServiceCase method testInit_InvalidUrl.

@Test
public void testInit_InvalidUrl() throws Exception {
    CoreSecurityService input = create();
    input.addKeystoreUrl(new ConfiguredUrl(createDummyKeystoreUrl(), PROPERTIES.getProperty(SECURITY_PASSWORD)));
    input.setPrivateKeyPasswordProvider(new ConfiguredPrivateKeyPasswordProvider(PROPERTIES.getProperty(SECURITY_PASSWORD)));
    input.setLocalPartner(PROPERTIES.getProperty(SECURITY_ALIAS));
    input.setRemotePartner(PROPERTIES.getProperty(SECURITY_ALIAS));
    try {
        LifecycleHelper.init(input);
        fail();
    } catch (CoreException expected) {
    } finally {
        LifecycleHelper.close(input);
    }
}
Also used : ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 10 with ConfiguredUrl

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

the class SecurityServiceCase method testInit_FailedToGetPrivateKey.

@Test
public void testInit_FailedToGetPrivateKey() throws Exception {
    CoreSecurityService input = create();
    input.setPrivateKeyPasswordProvider(new FailingPrivateKeyPasswordProvider());
    input.addKeystoreUrl(new ConfiguredUrl(PROPERTIES.getProperty(KEYSTORE_URL), PROPERTIES.getProperty(SECURITY_PASSWORD)));
    input.setLocalPartner(PROPERTIES.getProperty(SECURITY_ALIAS));
    input.setRemotePartner(PROPERTIES.getProperty(SECURITY_ALIAS));
    try {
        LifecycleHelper.init(input);
        fail();
    } catch (CoreException expected) {
    }
}
Also used : ConfiguredUrl(com.adaptris.security.keystore.ConfiguredUrl) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Aggregations

ConfiguredUrl (com.adaptris.security.keystore.ConfiguredUrl)11 Test (org.junit.Test)7 CoreException (com.adaptris.core.CoreException)2 Alias (com.adaptris.security.keystore.Alias)2 Before (org.junit.Before)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 ServiceException (com.adaptris.core.ServiceException)1 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)1 ConfiguredKeystore (com.adaptris.security.keystore.ConfiguredKeystore)1 InlineKeystore (com.adaptris.security.keystore.InlineKeystore)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1