forked from bcoin-org/bcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcerts.sh
executable file
·62 lines (56 loc) · 1.34 KB
/
certs.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
dir=$(dirname "$(which "$0")")
url='https://raw.githubusercontent.com/nodejs/node/master/src/node_root_certs.h'
json=$(curl -s "$url")
sha256() {
cat | openssl dgst -sha256 -hex | sed 's/^(stdin)= //'
}
getcerts() {
local buf=''
echo "$json" | sed 's/\\/\\\\/g' | while read line; do
if echo "$line" | grep 'BEGIN CERT' > /dev/null; then
buf="$line"
continue
fi
if echo "$line" | grep 'END CERT' > /dev/null; then
buf="$buf$line"
echo "$buf" | sed 's/"//g' | sed 's/,//g'
continue
fi
buf="$buf$line"
done
}
gethashes() {
local buf=''
echo "$json" | sed 's/\\n/:/g' | while read line; do
if echo "$line" | grep 'BEGIN CERT' > /dev/null; then
buf="$line"
continue
fi
if echo "$line" | grep 'END CERT' > /dev/null; then
buf="$buf$line"
echo "$buf" \
| sed 's/"//g' \
| sed 's/,//g' \
| tr ':' '\n' \
| openssl x509 -outform DER \
| sha256
continue
fi
buf="$buf$line"
done
}
tojs() {
local data=$(cat)
local body=$(echo "$data" | head -n -1)
local last=$(echo "$data" | tail -n 1)
echo "'use strict';"
echo ''
echo 'module.exports = ['
echo "$body" | while read line; do
echo " '${line}',"
done
echo " '${last}'"
echo '];'
}
gethashes | tojs > "${dir}/../lib/bip70/certs.js"