From a8e726382b0472ad030d7a579fe8d6878a216bd4 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Thu, 27 Jun 2019 13:11:53 +0200 Subject: Fixes; SSL Client Auth Works! - Switch to java 12 for now. Reason: Bug [1] in JDK 11 (up to jdk-11+28) impairs SSLHandshake ("Unsupported Operation Exception"), but was fixed in Java 12. - Set HTTP policy to infinite. - Fix key/truststore path resolution - Fix NPE in ConfigUtil.merge - Rearrange application.yaml to include two config profiles (one with and one without SSL for the msg client). - Add key material for testcases (Note: expires: May 2 14:47:08 2020 GMT) - Update MsgClient Testcases [1] https://bugs.openjdk.java.net/browse/JDK-8214098 --- src/test/java/at/gv/egiz/moazs/MsgClientTest.java | 51 +++++++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'src/test/java/at/gv') diff --git a/src/test/java/at/gv/egiz/moazs/MsgClientTest.java b/src/test/java/at/gv/egiz/moazs/MsgClientTest.java index 62df52d..294b2b8 100644 --- a/src/test/java/at/gv/egiz/moazs/MsgClientTest.java +++ b/src/test/java/at/gv/egiz/moazs/MsgClientTest.java @@ -7,25 +7,28 @@ import at.gv.egiz.moazs.scheme.Marshaller; import at.gv.zustellung.app2mzs.xsd.ClientType; import at.gv.zustellung.msg.xsd.DeliveryRequestType; import at.gv.zustellung.msg.xsd.ObjectFactory; +import org.junit.Test; +import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import javax.xml.bind.JAXBElement; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; +import static at.gv.zustellung.app2mzs.xsd.KeyStoreType.keyStoreTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.SSLType.SSLTypeBuilder; // @RunWith(SpringRunner.class) // @SpringBootTest -public class MsgClientTest { - - private final static Logger logger = LoggerFactory.getLogger(MsgClient.class); - private String httpServiceUri = "http://localhost:8081/services/DeliveryRequest"; - private String sslServiceUri = "https://localhost/zusemsg/services/DeliveryRequest"; +public class MsgClientTest { + private final static Logger log = LoggerFactory.getLogger(MsgClient.class); private final String basePath = "src/test/resources/at/gv/egiz/moazs/MsgClientTest/"; @Autowired @@ -46,27 +49,57 @@ public class MsgClientTest { public void sendValidMessage() throws IOException { var request = loadFromFile("validDeliveryRequest.xml"); + var httpServiceUri = "http://localhost:8081/services/DeliveryRequest"; var clientParams = generateClientParams(httpServiceUri); var client = factory.create(clientParams); try{ var status = client.send(request); - logger.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryResponse(status))); + log.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryResponse(status))); } catch (Exception ex) { System.out.println(ex.getMessage()); } } //@Test - public void sendValidMessageToSSL() throws IOException { + public void sendValidMessageSSL() throws IOException { var request = loadFromFile("validDeliveryRequest.xml"); - var clientParams = generateClientParams(sslServiceUri); + var sslServiceUri = "https://localhost/zusemsg/services/DeliveryRequest"; + var clientParams = generateSSLClientParams(sslServiceUri); var client = factory.create(clientParams); var status = client.send(request); + log.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryRequestStatus(status))); + + } + + private ClientType generateSSLClientParams(String sslServiceUri) { + + var keystore = keyStoreTypeBuilder() + .withFileName("ssl/client.cert.key.p12") + .withFileType("PKCS12") + .withPassword("123456") + .build(); + + var truststore = keyStoreTypeBuilder() + .withFileName("ssl/truststore.jks") + .withPassword("123456") + .withFileType("JKS") + .build(); + + var sslParams = SSLTypeBuilder() + .withLaxHostNameVerification(false) + .withTrustAll(false) + .withKeyStore(keystore) + .withTrustStore(truststore) + .build(); + + return ClientType.clientTypeBuilder() + .withURL(sslServiceUri) + .withSSL(sslParams) + .build(); - logger.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryRequestStatus(status))); } private DeliveryRequestType loadFromFile(String fileName) throws IOException { -- cgit v1.2.3