-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload-ct-cert.sh
42 lines (31 loc) · 994 Bytes
/
upload-ct-cert.sh
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
#!/usr/bin/env bash
#This script is used to upload a pre certificate to a certificate log and receive the
#Signed Certificate Timestamp (SCT) for integration into the final certificate
#Because the return is a JSON structure, it has to be converted into the needed
#SCTList form that is needed by OpenSSL
if [ $# -ne 2 ]; then
echo "pass PEM cert and host to upload to"
echo "example: $0 example.com.pem http://localhost.com:6962/"
exit 1
fi
certs=$(cat $1 | sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p' | tr -d '\n')
eol=$'\n'
certs="${certs//'-----END CERTIFICATE-----'/$eol}"
certs="${certs//'-----BEGIN CERTIFICATE-----'/}"
#echo "$certs"
chain='{"chain":['
#chain="{\"chain\":$eol["
add=""
while read -r line; do
if [ -z "$line" ]; then
continue
fi
#echo "> $line"
chain="${chain}${add}\"${line}\""
add=","
done <<< "$certs"
chain="$chain]}"
#echo "$chain"
echo "$2/ct/v1/add-chain"
curl -d "$chain" $2/ct/v1/add-chain
echo ""