summary refs log tree commit diff stats
path: root/system/services/taskserver/certs/generate
blob: c3b58ae6937e56aa502954dd9c5767af2a712fd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env nix-shell
#! nix-shell -i dash --packages openssl gnutls dash
#! nix-shell --impure

# For a public or production server, purchase a cert from a known CA, and skip
# the next step.

# For development, testing and personal server management, create a CA key and
# cert, and use that to generate a server key and cert.  Creates:
#   ca.key.pem
#   ca.cert.pem
#   server.key.pem
#   server.cert.pem

GENERATION_LOCATION="/run/user/$(id -u)/taskserver/certs"
BASEDIR="$(dirname "$0")"
cd "$BASEDIR" || {
    echo "(BUG?) No basedir ('$BASEDIR')" 1>&2
    exit 1
}

ca=false
crl=false
clients=false

for arg in "$@"; do
    case "$arg" in
    "--ca")
        ca=true
        ;;
    "--crl")
        crl=true
        ;;
    "--clients")
        clients=true
        ;;
    esac
done

# `ca.cert.pem` is not on this list, as it would otherwise get deleted in the `rm` on the
# second-to last line
set -- ./vars ./generate.ca ./generate.crl ./generate.client ./ca.key.pem.gpg ./isrgrootx1.pem

mkdir --parents "$GENERATION_LOCATION"
cp "$@" ./ca.cert.pem "$GENERATION_LOCATION"
cd "$GENERATION_LOCATION" || echo "(BUG?) No possible location fould!" 1>&2

gpg --decrypt ca.key.pem.gpg >ca.key.pem

[ "$ca" = true ] && ./generate.ca
cat ./isrgrootx1.pem >>./ca.cert.pem

# Generate a certificate revocation list (CRL).  The initial CRL is empty, but
# can grow over time.  Creates:
#   server.crl.pem

[ "$crl" = true ] && ./generate.crl

# The above is sufficient to operate a server. You now need to run a client cert creation
# process per client; Add the required client names and uncomment
# ./generate.client <client_name>
#
#
# Creates:
#   <client_name>.key.pem
#   <client_name>.cert.pem
#
[ "$clients" = true ] && ./generate.client soispha
[ "$clients" = true ] && ./generate.client android-mobile
[ "$clients" = true ] && ./generate.client android-tab

rm "$@" "./ca.key.pem"
echo "(INFO) Look for the keys at: $GENERATION_LOCATION"

# vim: ft=sh