]> git.proxmox.com Git - swtpm.git/commitdiff
samples: automatically create signing key and issuer cert
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Mon, 4 May 2015 06:48:43 +0000 (02:48 -0400)
committerStefan Berger <stefanb@linux.vnet.ibm.com>
Mon, 4 May 2015 06:52:08 +0000 (02:52 -0400)
Automatically create the signing key and a self-signed issuer
certificate if the state dir has to be created.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
samples/swtpm-localca

index 75e489432436c2537f6f431f8035ea023cf56c62..882b1d0ef69bf91545033a158084748355b30058 100644 (file)
@@ -259,6 +259,7 @@ main() {
        fi
        STATEDIR="$tmp"
        if [ ! -d "$STATEDIR" ]; then
+               logit "Creating swtpm-local state dir."
                mkdir -p "$STATEDIR"
                if [ $? -ne 0 ]; then
                        logerr "Could not create directory '${STATEDIR}."
@@ -279,16 +280,23 @@ main() {
                logerr "Missing signingkey variable in config file $LOCALCA_CONFIG."
                exit 1
        fi
-       if [ ! -r "$SIGNKEY" ]; then
-               logerr "Cannot access signing key ${SIGNKEY}."
-               exit 1
-       fi
-
        ISSUERCERT=$(get_config_value "$LOCALCA_CONFIG" "issuercert")
        if [ -z "$ISSUERCERT" ]; then
                logerr "Missing issuercert variable in config file $LOCALCA_CONFIG."
                exit 1
        fi
+
+       if [ ! -r "$SIGNKEY" ]; then
+               # Create the signing key and issuer cert since it will be missing
+               logit "Creating local CA's signing key and self signed issuer cert."
+               create_localca_cert
+       fi
+
+       if [ ! -r "$SIGNKEY" ]; then
+               logerr "Cannot access signing key ${SIGNKEY}."
+               exit 1
+       fi
+
        if [ ! -r "$ISSUERCERT" ]; then
                logerr "Cannot access issuer certificate ${ISSUERCERT}."
                exit 1
@@ -297,8 +305,6 @@ main() {
        CERTSERIAL=$(get_config_value "$LOCALCA_CONFIG" "certserial" \
            "${STATEDIR}/certserial")
 
-       create_localca_cert
-
        create_cert "$typ" "$dir" "$ek" "$vmid"
 }