aboutsummaryrefslogtreecommitdiff
path: root/server/testdata/cmd/add-entry
blob: 09356140a2966180b04b59fcedee1ed2c12cffd2 (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
35
36
37
#!/bin/bash

set -eo pipefail
source config

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

if [[ ! -z $1 ]]; then
	name=$1
fi
info "package name: $name"

pushd ../entry >/dev/null
	info "generating base64-encoded StItem and signature"
	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","signature_scheme":%s,"chain":["%s"]}'\
		$(cat stitem/$name.b64)\
		$(cat stitem/$name.sig.b64)\
		$signature_scheme\
		$(cat $cert_path |\
			sed '1,1d;$ d' |\
			xargs |\
			sed 's/ //g'))
	rm -f stitem/$name{,.sig,.b64,.sig.b64}
popd >/dev/null

info "sending add-entry request"
curl --header "application/json" --request POST --data $json $base_url/add-entry
newline
# TODO: try decoding and verifying signature