From 9b7ce63286fef0f2fd1ae7a729d266167e811de4 Mon Sep 17 00:00:00 2001 From: Ivar Derksen Date: Thu, 4 Nov 2021 10:48:56 +0100 Subject: [PATCH] Added parameters to keygen script --- README.markdown | 12 ------------ README.md | 16 ++++++++++++++++ utils/keygen.sh | 44 +++++++++++++++++++++++++++++--------------- 3 files changed, 45 insertions(+), 27 deletions(-) delete mode 100644 README.markdown create mode 100644 README.md diff --git a/README.markdown b/README.markdown deleted file mode 100644 index 633dd23..0000000 --- a/README.markdown +++ /dev/null @@ -1,12 +0,0 @@ - -# Email server - -Add an email address for use in your [IRMA app](https://github.com/privacybydesign/irma_mobile). - - -## Setting up the server - - 1. Copy the file `src/main/resources/config.sample.json` to - `build/resources/main/config.json` and modify it. - 2. Run `gradle appRun` in the root directory of this project. - 3. Navigate to `http://localhost:8080/irma_email_issuer/api/hello` diff --git a/README.md b/README.md new file mode 100644 index 0000000..b559b8a --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ + +# Email server + +Add an email address for use in your [IRMA app](https://github.com/privacybydesign/irma_mobile). + + +## Setting up the server + +1. Generate JWT keys for the issuer +```bash +./utils/keygen.sh ./src/main/resources/sk ./src/main/resources/pk +``` +2. Copy the file `src/main/resources/config.sample.json` to + `build/resources/main/config.json` and modify it. +3. Run `gradle appRun` in the root directory of this project. +4. Navigate to `http://localhost:8080/irma_email_issuer/api/hello` diff --git a/utils/keygen.sh b/utils/keygen.sh index b923552..70bfa53 100755 --- a/utils/keygen.sh +++ b/utils/keygen.sh @@ -1,20 +1,34 @@ #!/bin/bash -dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) +# Check if openssl exists +if ! type openssl >/dev/null 2>&1; then + >&2 echo "openssl not found, exiting" + exit 1 +fi -SK=$dir/../build/resources/main/sk -PK=$dir/../build/resources/main/pk +if [[ $# -eq 0 ]]; then + SK=sk + PK=pk +fi +if [[ $# -eq 1 ]]; then + >&2 echo "Either supply 0 or 2 arguments" + exit 1 +fi +if [[ $# -eq 2 ]]; then + SK=$1 + PK=$2 +fi -if [ ! -e "$SK" ]; then - # Generate a private key in PEM format - openssl genrsa -out ${SK}.pem 2048 - # Convert it to DER for Java - openssl pkcs8 -topk8 -inform PEM -outform DER -in ${SK}.pem -out ${SK}.der -nocrypt - # Calculate corresponding public key, saved in PEM format - openssl rsa -in ${SK}.pem -pubout -outform PEM -out ${PK}.pem - # Calculate corresponding public key, saved in DER format - openssl rsa -in ${SK}.pem -pubout -outform DER -out ${PK}.der - # Remove leftover files +if [ -e ${SK}.der ] || [ -e ${PK}.der ]; then + echo "Keys already exist, not generating new ones" + exit fi -rm -f ${SK}.pem -rm -f ${PK}.pem + +# Generate a private key in PEM format +openssl genrsa -out ${SK}.pem 2048 +# Convert it to DER for Java +openssl pkcs8 -topk8 -inform PEM -outform DER -in ${SK}.pem -out ${SK}.der -nocrypt +# Calculate corresponding public key, saved in PEM format +openssl rsa -in ${SK}.pem -pubout -outform PEM -out ${PK}.pem +# Calculate corresponding public key, saved in DER format +openssl rsa -in ${SK}.pem -pubout -outform DER -out ${PK}.der