Search in sources :

Example 86 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class EncryptionAlgorithmTest method testRSAOAEPKW.

@Test
public void testRSAOAEPKW() throws Exception {
    final XMLSecurityDataFormat sendingDataFormat = new XMLSecurityDataFormat();
    sendingDataFormat.setSecureTagContents(true);
    sendingDataFormat.setSecureTag("//cheesesites/italy/cheese");
    sendingDataFormat.setXmlCipherAlgorithm(XMLCipher.AES_128);
    sendingDataFormat.setKeyCipherAlgorithm(XMLCipher.RSA_OAEP);
    sendingDataFormat.setRecipientKeyAlias("recipient");
    KeyStoreParameters tsParameters = new KeyStoreParameters();
    tsParameters.setPassword("password");
    tsParameters.setResource("sender.ts");
    sendingDataFormat.setKeyOrTrustStoreParameters(tsParameters);
    final XMLSecurityDataFormat receivingDataFormat = new XMLSecurityDataFormat();
    receivingDataFormat.setKeyCipherAlgorithm(XMLCipher.RSA_OAEP);
    receivingDataFormat.setRecipientKeyAlias("recipient");
    receivingDataFormat.setSecureTag("//cheesesites/italy/cheese");
    KeyStoreParameters ksParameters = new KeyStoreParameters();
    ksParameters.setPassword("password");
    ksParameters.setResource("recipient.ks");
    receivingDataFormat.setKeyOrTrustStoreParameters(ksParameters);
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").marshal(sendingDataFormat).to("mock:encrypted").log("Body: + ${body}").unmarshal(receivingDataFormat).to("mock:decrypted");
        }
    });
    xmlsecTestHelper.testDecryption(context);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Test(org.junit.Test)

Example 87 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class EncryptionAlgorithmTest method testAES256.

@Test
public void testAES256() throws Exception {
    if (!TestHelper.UNRESTRICTED_POLICIES_INSTALLED) {
        return;
    }
    // Set up the Key
    KeyGenerator keygen = KeyGenerator.getInstance("AES");
    keygen.init(256);
    SecretKey key = keygen.generateKey();
    final XMLSecurityDataFormat xmlEncDataFormat = new XMLSecurityDataFormat();
    xmlEncDataFormat.setPassPhrase(key.getEncoded());
    xmlEncDataFormat.setSecureTagContents(true);
    xmlEncDataFormat.setSecureTag("//cheesesites/italy/cheese");
    xmlEncDataFormat.setXmlCipherAlgorithm(XMLCipher.AES_256);
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").marshal(xmlEncDataFormat).to("mock:encrypted").log("Body: + ${body}").unmarshal(xmlEncDataFormat).to("mock:decrypted");
        }
    });
    xmlsecTestHelper.testDecryption(context);
}
Also used : SecretKey(javax.crypto.SecretKey) RouteBuilder(org.apache.camel.builder.RouteBuilder) KeyGenerator(javax.crypto.KeyGenerator) Test(org.junit.Test)

Example 88 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class EncryptionAlgorithmTest method testTRIPLEDES.

@Test
public void testTRIPLEDES() throws Exception {
    // Set up the Key
    KeyGenerator keygen = KeyGenerator.getInstance("DESede");
    keygen.init(192);
    SecretKey key = keygen.generateKey();
    final XMLSecurityDataFormat xmlEncDataFormat = new XMLSecurityDataFormat();
    xmlEncDataFormat.setPassPhrase(key.getEncoded());
    xmlEncDataFormat.setSecureTagContents(true);
    xmlEncDataFormat.setSecureTag("//cheesesites/italy/cheese");
    xmlEncDataFormat.setXmlCipherAlgorithm(XMLCipher.TRIPLEDES);
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").marshal(xmlEncDataFormat).to("mock:encrypted").log("Body: + ${body}").unmarshal(xmlEncDataFormat).to("mock:decrypted");
        }
    });
    xmlsecTestHelper.testDecryption(context);
}
Also used : SecretKey(javax.crypto.SecretKey) RouteBuilder(org.apache.camel.builder.RouteBuilder) KeyGenerator(javax.crypto.KeyGenerator) Test(org.junit.Test)

Example 89 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class XMLEncryption11Test method testFullPayloadAsymmetricKeyDecryptionSHA256.

@Test
public void testFullPayloadAsymmetricKeyDecryptionSHA256() throws Exception {
    final KeyStoreParameters tsParameters = new KeyStoreParameters();
    tsParameters.setPassword("password");
    tsParameters.setResource("sender.ts");
    final KeyStoreParameters ksParameters = new KeyStoreParameters();
    ksParameters.setPassword("password");
    ksParameters.setResource("recipient.ks");
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").marshal().secureXML("", new HashMap<String, String>(), true, "recipient", XMLCipher.AES_128, XMLCipher.RSA_OAEP, tsParameters, null, XMLCipher.SHA256).to("mock:encrypted").unmarshal().secureXML("", new HashMap<String, String>(), true, "recipient", XMLCipher.AES_128, XMLCipher.RSA_OAEP, ksParameters, null, XMLCipher.SHA256).to("mock:decrypted");
        }
    });
    xmlsecTestHelper.testDecryption(context);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Test(org.junit.Test)

Example 90 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class XMLEncryption11Test method testFullPayloadAsymmetricKeyDecryptionGCM.

/*
     * Decryption Tests
     */
@Test
public void testFullPayloadAsymmetricKeyDecryptionGCM() throws Exception {
    final KeyStoreParameters tsParameters = new KeyStoreParameters();
    tsParameters.setPassword("password");
    tsParameters.setResource("sender.ts");
    final KeyStoreParameters ksParameters = new KeyStoreParameters();
    ksParameters.setPassword("password");
    ksParameters.setResource("recipient.ks");
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").marshal().secureXML("", true, "recipient", XMLCipher.AES_128_GCM, XMLCipher.RSA_OAEP, tsParameters).to("mock:encrypted").unmarshal().secureXML("", true, "recipient", XMLCipher.AES_128_GCM, XMLCipher.RSA_OAEP, ksParameters).to("mock:decrypted");
        }
    });
    xmlsecTestHelper.testDecryption(context);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Test(org.junit.Test)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1759 Exchange (org.apache.camel.Exchange)628 Processor (org.apache.camel.Processor)545 Test (org.junit.Test)476 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)341 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)104 File (java.io.File)68 CamelContext (org.apache.camel.CamelContext)64 IOException (java.io.IOException)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)35 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 Endpoint (org.apache.camel.Endpoint)30 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26