#!/bin/bash

# Build Diffie-Hellman parameters for the server side
# of an SSL/TLS connection.

if [ -d $KEY_DIR ] && [ $KEY_SIZE ]; then
    $OPENSSL dhparam -out ${KEY_DIR}/dh-${KEY_SIZE}.pem ${KEY_SIZE}
    
    # Copy the file so that we don't get an error during the build
    f1024=${KEY_DIR}/dh-1024.pem
    f2048=${KEY_DIR}/dh-2048.pem
    [ -f $f1024 ] && mv $f1024 ${KEY_DIR}/dh-$1.pem
    [ -f $f2048 ] && cp $f2048 ${KEY_DIR}/dh-$1.pem
    
else
    echo 'Please source the vars script first (i.e. "source ./vars")'
    echo 'Make sure you have edited it to reflect your configuration.'
fi
