Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions components/camel-as2/camel-as2-component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@
<version>${commons-io-version}</version>
<scope>test</scope>
</dependency>

<!-- test infra -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ public class AS2ServerManagerIT extends AbstractAS2ITSupport {
+ "UNT+23+00000000000117'\n"
+ "UNZ+1+00000000000778'";

private static AS2SignedDataGenerator gen;

private static KeyPair issueKP;
private static X509Certificate issueCert;

private static KeyPair signingKP;
private static X509Certificate signingCert;
private static List<X509Certificate> certList;

private static KeyPair decryptingKP;

private static SSLContext clientSslContext;
private static SSLContext serverSslContext;

@BeforeAll
public static void setup() throws Exception {
Expand Down Expand Up @@ -400,6 +406,8 @@ public void receiveMultipartInvalidSignedMessageTest() throws Exception {
kpg.initialize(1024, new SecureRandom());
String hackerIssueDN = "O=Hackers Unlimited Ltd., C=US";
var hackerIssueKP = kpg.generateKeyPair();
var hackerissueCert = Utils.makeCertificate(
hackerIssueKP, hackerIssueDN, hackerIssueKP, hackerIssueDN);
String hackerSigningDN = "CN=John Doe, E=j.doe@sharklasers.com, O=Self Signed, C=US";
var hackerSigningKP = kpg.generateKeyPair();
var hackerSigningCert = Utils.makeCertificate(
Expand Down Expand Up @@ -627,8 +635,7 @@ private static void setupSigningGenerator() throws Exception {
new IssuerAndSerialNumber(new X500Name(signingCert.getIssuerDN().getName()), signingCert.getSerialNumber())));
attributes.add(new SMIMECapabilitiesAttribute(capabilities));

AS2SignedDataGenerator gen = SigningUtils.createSigningGenerator(AS2SignatureAlgorithm.SHA256WITHRSA,
certList.toArray(new X509Certificate[0]),
gen = SigningUtils.createSigningGenerator(AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new X509Certificate[0]),
signingKP.getPrivate());
gen.addCertificates(certs);

Expand All @@ -643,8 +650,8 @@ private static void setupKeysAndCertificates() throws Exception {
kpg.initialize(1024, new SecureRandom());

String issueDN = "O=Punkhorn Software, C=US";
KeyPair issueKP = kpg.generateKeyPair();
X509Certificate issueCert = Utils.makeCertificate(
issueKP = kpg.generateKeyPair();
issueCert = Utils.makeCertificate(
issueKP, issueDN, issueKP, issueDN);

//
Expand Down Expand Up @@ -680,7 +687,8 @@ public SSLContext setupClientContext(CamelContext context) throws Exception {
sslContextParameters.setKeyManagers(kmp);
sslContextParameters.setTrustManagers(clientSSLTrustManagers);

return sslContextParameters.createSSLContext(context);
SSLContext sslContext = sslContextParameters.createSSLContext(context);
return sslContext;
}

public SSLContext setupServerContext(CamelContext context) throws Exception {
Expand All @@ -702,17 +710,20 @@ public SSLContext setupServerContext(CamelContext context) throws Exception {
sslContextParameters.setTrustManagers(tmp);
sslContextParameters.setServerParameters(scsp);

return sslContextParameters.createSSLContext(context);
SSLContext sslContext = sslContextParameters.createSSLContext(context);
return sslContext;
}

@Override
public void configureContext(CamelContext context) throws Exception {
clientSslContext = setupClientContext(context);
SSLContext serverSslContext = setupClientContext(context);
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
this.clientSslContext = setupClientContext(context);
this.serverSslContext = setupClientContext(context);
AS2Component as2Component = (AS2Component) context.getComponent("as2");
AS2Configuration configuration = as2Component.getConfiguration();
configuration.setSslContext(serverSslContext);
configuration.setDecryptingPrivateKey(decryptingKP.getPrivate());
return context;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,24 @@

import org.apache.camel.CamelContext;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.support.PropertyBindingSupport;
import org.apache.camel.test.infra.core.CamelContextExtension;
import org.apache.camel.test.infra.core.TransientCamelContextExtension;
import org.apache.camel.test.infra.core.annotations.RouteFixture;
import org.apache.camel.test.infra.core.api.CamelTestSupportHelper;
import org.apache.camel.test.infra.core.api.ConfigurableContext;
import org.apache.camel.test.infra.core.api.ConfigurableRoute;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* Abstract base class for AS2 Integration tests generated by Camel API component maven plugin.
*/
@TestInstance(Lifecycle.PER_CLASS)
public abstract class AbstractAS2ITSupport implements CamelTestSupportHelper, ConfigurableContext, ConfigurableRoute {
public class AbstractAS2ITSupport extends CamelTestSupport {

private static final String TEST_OPTIONS_PROPERTIES = "/test-options.properties";

@RegisterExtension
public static final CamelContextExtension camelContextExtension = new TransientCamelContextExtension();

@Override
public void configureContext(CamelContext context) throws Exception {
protected CamelContext createCamelContext() throws Exception {

final CamelContext context = super.createCamelContext();

// read AS2 component configuration from TEST_OPTIONS_PROPERTIES
final Properties properties = new Properties();
try {
Expand All @@ -70,28 +63,18 @@ public void configureContext(CamelContext context) throws Exception {
final AS2Component component = new AS2Component(context);
component.setConfiguration(configuration);
context.addComponent("as2", component);
}

@Override
public CamelContextExtension getCamelContextExtension() {
return camelContextExtension;
}

@Override
@RouteFixture
public void createRouteBuilder(CamelContext context) throws Exception {
final RouteBuilder routeBuilder = createRouteBuilder();

if (routeBuilder != null) {
context.addRoutes(routeBuilder);
}
return context;
}

protected abstract RouteBuilder createRouteBuilder() throws Exception;

@SuppressWarnings("unchecked")
protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers)
throws CamelExecutionException {
return (T) getCamelContextExtension().getProducerTemplate().requestBodyAndHeaders(endpointUri, body, headers);
return (T) template().requestBodyAndHeaders(endpointUri, body, headers);
}

@SuppressWarnings("unchecked")
protected <T> T requestBody(String endpoint, Object body) throws CamelExecutionException {
return (T) template().requestBody(endpoint, body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
Expand All @@ -29,10 +30,12 @@
import java.security.cert.CertificateFactory;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

import javax.net.ssl.SSLContext;

import org.apache.commons.io.IOUtils;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.ssl.SSLContexts;
import org.slf4j.Logger;
Expand Down Expand Up @@ -142,6 +145,11 @@ public PrivateKey getPrivateKey() {
return privateKey;
}

private List<Certificate> getCertificatesFromStream(InputStream inputStream) throws CertificateException {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
return (List<Certificate>) certificateFactory.generateCertificates(inputStream);
}

private Certificate getCertificateFromStream(InputStream inputStream) throws IOException, CertificateException {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
return certificateFactory.generateCertificate(inputStream);
Expand All @@ -165,10 +173,23 @@ private PrivateKey getPrivateKeyFromPKCSStream(InputStream inputStream, String k
return (PrivateKey) ks.getKey(
ks.aliases().nextElement(),
keyStorePassword.toCharArray());
} catch (KeyStoreException | UnrecoverableKeyException e) {
} catch (KeyStoreException e) {
LOG.error("Error while retrieving private key" + e);
} catch (UnrecoverableKeyException e) {
LOG.error("Error while retrieving private key" + e);
}
throw new IllegalStateException("Failed to construct a PrivateKey from provided InputStream");
}

private byte[] getBytesFromPem(InputStream inputStream) throws IOException {
String privateKeyPEM
= IOUtils.toString(inputStream, StandardCharsets.UTF_8).replaceAll("-{5}.+-{5}", "").replaceAll("\\s", "");
return Base64.getDecoder().decode(privateKeyPEM);
}

private byte[] getBytesFromPKCS12(InputStream inputStream) throws IOException {
String privateKeyPKCS12 = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
return privateKeyPKCS12.getBytes(StandardCharsets.UTF_8);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.as2.api.AS2EncryptionAlgorithm;
import org.apache.camel.component.as2.api.AS2MessageStructure;
import org.apache.camel.component.as2.api.AS2SignatureAlgorithm;
Expand Down Expand Up @@ -126,9 +125,4 @@ public void testCreateEndpointAndSendViaHTTPS() throws Exception {
"you can check your message in http://testas2.mendelson-e-c.com:8080/webas2/ " +
"Login guest, password guest");
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return null;
}
}