Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] move creation of required unit test resources into separate shell script #35

Closed
wants to merge 4 commits into from
Closed
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
30 changes: 0 additions & 30 deletions docker/joynr-android/scripts/build/java-android-clean-build
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,6 @@ while [ "$1" != "" ]; do
shift
done

echo '####################################################'
echo '# create keystore and truststore'
echo '####################################################'

CERT_PATH='/data/ssl-data/certs'
PRIVATE_KEY_PATH='/data/ssl-data/private'
KEYSTORE_PASSWORD='password'

mkdir -p /data/src/java/messaging/mqtt/joynr-mqtt-client/src/test/resources

cd /data/src/java/messaging/mqtt/joynr-mqtt-client/src/test/resources/

# create JKS truststore
keytool -keystore catruststore.jks -importcert -file $CERT_PATH/ca.cert.pem -storepass $KEYSTORE_PASSWORD -trustcacerts -noprompt

# list the truststore contents
keytool -list -keystore catruststore.jks -storepass $KEYSTORE_PASSWORD

# create PKCS12 truststore
keytool -importkeystore -srckeystore catruststore.jks -srcstorepass $KEYSTORE_PASSWORD -destkeystore catruststore.p12 -deststorepass $KEYSTORE_PASSWORD -srcstoretype JKS -deststoretype PKCS12

# merge and import client certificate and private key into pkcs12 keystore
openssl pkcs12 -export -in $CERT_PATH/client.cert.pem -inkey $PRIVATE_KEY_PATH/client.key.pem -out clientkeystore.p12 -password pass:$KEYSTORE_PASSWORD

# convert pkcs12 keystore into java keystore
keytool -importkeystore -deststorepass $KEYSTORE_PASSWORD -destkeypass $KEYSTORE_PASSWORD -destkeystore clientkeystore.jks -srckeystore clientkeystore.p12 -srcstoretype PKCS12 -srcstorepass $KEYSTORE_PASSWORD -alias 1 -storepass $KEYSTORE_PASSWORD

# list the keystore contents
keytool -list -keystore clientkeystore.jks -storepass $KEYSTORE_PASSWORD

echo '####################################################'
echo '# start tests'
echo '####################################################'
Expand Down
5 changes: 5 additions & 0 deletions docker/joynr-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ ENV BUILD_DIR /data/build
ENV SRC_DIR /data/src
ENV INSTALL_DIR /data/install

###################################################
# set joynr-docker-environment
###################################################
ENV JOYNR_DOCKER_ENVIRONMENT true

###################################################
# copy scripts and set start command
###################################################
Expand Down
35 changes: 35 additions & 0 deletions java/messaging/mqtt/joynr-mqtt-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,39 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>joynr-docker-environment</id>
<activation>
<property>
<name>env.JOYNR_DOCKER_ENVIRONMENT</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>generate required sources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/gen-java-keystore-truststore.sh</executable>
<arguments>
<argument>--destdir</argument>
<argument>${basedir}/src/test/resources</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

DEST_DIR='.'
KEYSTORE_PASSWORD='password'

# these files are located inside the docker image
CERT_PATH='/data/ssl-data/certs'
PRIVATE_KEY_PATH='/data/ssl-data/private'

function usage
{
echo "usage: gen-java-keystore-truststore.sh
[--keystorepassword <non empty password for the keystore, default: 'password'>]
[--destdir <existing dir, default: '.'>]"
}

while [ "$1" != "" ]; do
case $1 in

--keystorepassword ) shift
KEYSTORE_PASSWORD=$1
;;

--destdir ) shift
DEST_DIR=${1%/}/
;;

* ) usage
exit 1
esac
shift
done

if [ -z "$KEYSTORE_PASSWORD" ]; then
echo "Empty password for the keystore specified ..."
echo " "
usage
exit -1
fi


if [ -z "$DEST_DIR" ]; then
echo "No destination directory specified. Using current directory"
fi


cd "$DEST_DIR"


# create JKS truststore
keytool -keystore catruststore.jks -importcert -file $CERT_PATH/ca.cert.pem -storepass $KEYSTORE_PASSWORD -trustcacerts -noprompt

# list the truststore contents
keytool -list -keystore catruststore.jks -storepass $KEYSTORE_PASSWORD

# create PKCS12 truststore
keytool -importkeystore -srckeystore catruststore.jks -srcstorepass $KEYSTORE_PASSWORD -destkeystore catruststore.p12 -deststorepass $KEYSTORE_PASSWORD -srcstoretype JKS -deststoretype PKCS12 -noprompt

# merge and import client certificate and private key into pkcs12 keystore
openssl pkcs12 -export -in $CERT_PATH/client.cert.pem -inkey $PRIVATE_KEY_PATH/client.key.pem -out clientkeystore.p12 -password pass:$KEYSTORE_PASSWORD

# convert pkcs12 keystore into java keystore
keytool -delete -importkeystore -deststorepass $KEYSTORE_PASSWORD -destkeypass $KEYSTORE_PASSWORD -destkeystore clientkeystore.jks -srckeystore clientkeystore.p12 -srcstoretype PKCS12 -srcstorepass $KEYSTORE_PASSWORD -alias 1 -storepass $KEYSTORE_PASSWORD -noprompt

# list the keystore contents
keytool -list -keystore clientkeystore.jks -storepass $KEYSTORE_PASSWORD

# always return success (don't break the maven build in case of something went wrong)
exit 0