summary refs log tree commit diff stats
path: root/system/services/taskserver/certs/generate.ca
blob: eb0dd5caf7df7d16d3bbcd93a8d83848a6a18e9e (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
#!/bin/sh

# Take the correct binary to create the certificates
CERTTOOL=$(command -v gnutls-certtool 2>/dev/null || command -v certtool 2>/dev/null)
if [ -z "$CERTTOOL" ]; then
    echo "ERROR: No certtool found" >&2
    exit 1
fi

. ./vars

if ! [ -f ca.key.pem ]; then
    # Create a CA key.
    $CERTTOOL \
        --generate-privkey \
        --sec-param $SEC_PARAM \
        --outfile ca.key.pem
fi

chmod 600 ca.key.pem

if ! [ -f ca.template ]; then
    # Sign a CA cert.
    cat <<EOF >ca.template
organization = $ORGANIZATION
cn = $CN CA
country = $COUNTRY
expiration_days = $EXPIRATION_DAYS
ca
EOF
#state = $STATE
#locality = $LOCALITY
fi

if ! [ -f ca.cert.pem ]; then
    $CERTTOOL \
        --generate-self-signed \
        --load-privkey ca.key.pem \
        --template ca.template \
        --outfile ca.cert.pem
fi

chmod 600 ca.cert.pem