summaryrefslogtreecommitdiff
path: root/signcsr.sh
diff options
context:
space:
mode:
authorU-Z690-A\user <jrayhawk@omgwallhack.org>2022-06-28 18:44:57 -0700
committerU-Z690-A\user <jrayhawk@omgwallhack.org>2022-06-28 18:44:57 -0700
commit537cb1c3cf10ba3552b03c43fb053bde9cca2440 (patch)
tree098778a7f6ed8ce8a4f62302725ecfe58fe75a2a /signcsr.sh
parent49fe6c0218d58f4c62e8b7adfe278b52d7975eab (diff)
downloadcash-537cb1c3cf10ba3552b03c43fb053bde9cca2440.tar.gz
cash-537cb1c3cf10ba3552b03c43fb053bde9cca2440.zip
Add automatic extended key usage detection
extendedKeyUsage is needed for some automatic certificate selection on Windows. We attempt to detect either clientAuth or serverAuth based on subjAltName and commonName.
Diffstat (limited to 'signcsr.sh')
-rwxr-xr-xsigncsr.sh20
1 files changed, 17 insertions, 3 deletions
diff --git a/signcsr.sh b/signcsr.sh
index 4c095f5..910d8d9 100755
--- a/signcsr.sh
+++ b/signcsr.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# requires bash regexes
+# requires bash 3.0 regexes
SUPPLEMENTARY_CONFIG="$2"
@@ -30,11 +30,25 @@ mkdir -pv "$CA"/signed "$CA"/temp "$CA"/certs
SERIAL=$(cat "$CA"/ca/"$CA".serial)
if grep ^SPKAC "$1"; then # SPKAC HTML5 <keygen> standard
+ [ -n $EKU ] || EKU="clientAuth" # I don't think servers do SPKACs
openssl spkac -in "$1" # print key size
- openssl ca -config "$OPENSSL_CONFIG" -spkac "$1" -notext
+ openssl ca -config <( ./ekusub.sh "$EKU" < $OPENSSL_CONFIG ) -spkac "$1" -notext
else # x509 CSR
+ if ! [ -n "$EKU" ]; then
+ [[ "$( openssl req -in $1 -subject -nameopt multiline | grep -E '^ +commonName += ' | head -n 1 )" =~ ^\ +commonName\ +=\ (.+)$ ]]
+ CN=${BASH_REMATCH[1]}
+ if openssl req -in "$1" -text | grep -EA1 '^ +X509v3 Subject Alternative Name:' | tail -n 1 | grep -qE '^ +DNS:'; then
+ EKU="serverAuth"
+ elif [[ "$CN" =~ \. ]] && ! [[ "$CN" =~ ' ' ]]; then
+ EKU="serverAuth"
+ elif [[ "$CN" =~ ' ' ]]; then
+ EKU="clientAuth"
+ else
+ echo Unable to determine if client or server for EKU.
+ fi
+ fi
openssl req -in "$1" -text # print key size
- openssl ca -config "$OPENSSL_CONFIG" -in "$1" -notext
+ openssl ca -config <( ./ekusub.sh "$EKU" < "$OPENSSL_CONFIG" ) -in "$1" -notext
fi
if [ -e "$CA"/certs/"$SERIAL".pem ]; then # openssl lacks useful exit status codes, so we check to see if it actually did anything instead.