aboutsummaryrefslogtreecommitdiff
path: root/server/testdata/cmd/add-entry
blob: d7346bbfb98f698521c84cf5e5c4057d8dd838c9 (plain)
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
#!/bin/bash

set -eo pipefail

algo=ecdsa
key_path="../chain/rgdd-$algo.key"
cert_path="../chain/rgdd-$algo.pem"
name="foobar-0.0.1"

if [[ ! -z $1 ]]; then
	name=$1
fi
echo "[Info] package name: $name" >&2


echo "[Info] generating StItem and signature..." >&2
pushd ../entry >/dev/null
	go run . --dir stitem --name $name
	openssl dgst -sha256 -sign $key_path -out stitem/$name.sig stitem/$name
	openssl base64 -A -in stitem/$name -out stitem/$name.b64
	openssl base64 -A -in stitem/$name.sig -out stitem/$name.sig.b64
	json=$(printf '{"item":"%s","signature":"%s","certificate":"%s"}'\
		$(cat stitem/$name.b64)\
		$(cat stitem/$name.sig.b64)\
		$(cat $cert_path |\
			sed '1,1d;$ d' |\
			xargs |\
			sed 's/ //g'))
	rm -f stitem/$name{,.sig,.b64,.sig.b64}
popd >/dev/null

echo "[Info] doing add-entry request"
curl --header "application/json" --request POST --data $json\
	localhost:6965/st/v1/add-entry