Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Update SSL cert management
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin Schnabel authored and ebullient committed Oct 23, 2020
1 parent 40d3489 commit 2571a84
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 41 deletions.
16 changes: 0 additions & 16 deletions room-app/src/main/java/net/wasdev/gameon/room/Kafka.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,6 @@ public void init(){
producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");

//this is a cheat, we need to enable ssl when talking to message hub, and not to kafka locally
//the easiest way to know which we are running on, is to check how many hosts are in kafkaUrl
//locally for kafka there'll only ever be one, and messagehub gives us a whole bunch..
boolean multipleHosts = kafkaUrl.indexOf(",") != -1;
if(multipleHosts){
Log.log(Level.INFO, this, "Initializing SSL Config for MessageHub");
producerProps.put("security.protocol","SASL_SSL");
producerProps.put("ssl.protocol","TLSv1.2");
producerProps.put("ssl.enabled.protocols","TLSv1.2");
Path p = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts");
producerProps.put("ssl.truststore.location", p.toString());
producerProps.put("ssl.truststore.password","changeit");
producerProps.put("ssl.truststore.type","JKS");
producerProps.put("ssl.endpoint.identification.algorithm","HTTPS");
}

producer = new KafkaProducer<String, String>(producerProps);
}catch(Exception e){
System.out.println("KAFKA INIT FAILED");
Expand Down
4 changes: 4 additions & 0 deletions room-wlpcfg/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ FROM gameontext/docker-liberty-custom:master-29

ENV SERVERDIRNAME room

ADD https://raw.githubusercontent.com/gameontext/gameon/master/bin/gen-keystore.sh /opt/gen-keystore.sh
USER 0
RUN chmod g+rwx /opt/gen-keystore.sh
USER 1001
COPY ./startup.sh /opt/startup.sh
ADD ./servers/gameon-room /opt/ol/wlp/usr/servers/defaultServer/
RUN mkdir -p /opt/ol/wlp/usr/servers/defaultServer/resources/security
Expand Down
4 changes: 3 additions & 1 deletion room-wlpcfg/servers/gameon-room/jvm.options
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-Djava.security.Security.setProperty("networkaddress.cache.ttl" , "30");
-Djava.security.Security.setProperty("networkaddress.cache.ttl" , "30")
-Djavax.net.ssl.trustStore=/opt/ol/wlp/usr/servers/defaultServer/resources/security/truststore.jks
-Djavax.net.ssl.trustStorePassword=gameontext-trust
4 changes: 2 additions & 2 deletions room-wlpcfg/servers/gameon-room/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

<keyStore id="defaultKeyStore" location="key.jks" password="testOnlyKeystore"/>
<keyStore id="defaultTrustStore" location="truststore.jks" password="truststore"/>
<keyStore id="defaultKeyStore" location="key.pkcs12" password="gameontext-keys"/>
<keyStore id="defaultTrustStore" location="truststore.jks" password="gameontext-trust"/>

<sslDefault sslRef="DefaultSSLSettings" />
<ssl id="DefaultSSLSettings" keyStoreRef="defaultKeyStore" trustStoreRef="defaultTrustStore" />
Expand Down
24 changes: 2 additions & 22 deletions room-wlpcfg/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,7 @@ if [ -f /etc/cert/cert.pem ]; then
cp /etc/cert/cert.pem ${ssl_path}/cert.pem
fi


if [ -f ${ssl_path}/cert.pem ] ; then
echo "Building keystore/truststore from cert.pem"
echo "-creating dir"
echo "-cd dir"
cd ${ssl_path}
echo "-converting pem to pkcs12"
openssl pkcs12 -passin pass:keystore -passout pass:keystore -export -out cert.pkcs12 -in cert.pem
echo "-importing pem to truststore.jks"
keytool -import -v -trustcacerts -alias default -file cert.pem -storepass truststore -keypass keystore -noprompt -keystore truststore.jks
echo "-creating dummy key.jks"
keytool -genkey -storepass testOnlyKeystore -keypass wefwef -keyalg RSA -alias endeca \
-keystore key.jks -dname CN=rsssl,OU=unknown,O=unknown,L=unknown,ST=unknown,C=CA
echo "-emptying key.jks"
keytool -delete -storepass testOnlyKeystore -alias endeca -keystore key.jks
echo "-importing pkcs12 to key.jks"
keytool -v -importkeystore -srcalias 1 -alias 1 -destalias default -noprompt \
-srcstorepass keystore -deststorepass testOnlyKeystore -srckeypass keystore -destkeypass testOnlyKeystore \
-srckeystore cert.pkcs12 -srcstoretype PKCS12 -destkeystore key.jks -deststoretype JKS
echo "done"
cd ${SERVER_PATH}
fi
# Make sure keystores are present or are generated
/opt/gen-keystore.sh ${ssl_path} ${ssl_path}

exec /opt/ol/wlp/bin/server run defaultServer

0 comments on commit 2571a84

Please sign in to comment.