-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencrypt-decrypt.sh
executable file
·74 lines (58 loc) · 2.1 KB
/
encrypt-decrypt.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
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -exuo pipefail
APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
: "${DEMO_KAS_ALLOWLIST:=http://localhost:65432}"
: "${DEMO_OIDC_ENDPOINT:=http://localhost:65432/auth/realms/tdf}"
: "${DEMO_KAS_URI:=http://localhost:65432/api/kas}"
: "${DEMO_WEB_APP_URI:=http://localhost:65432/}"
cd "$APP_DIR"
counter=0
_nano_test() {
counter=$((counter + 1))
plain="./sample-${counter}.txt"
echo "Hello World ${counter}" >"./${plain}"
npx "$1" --log-level DEBUG \
--kasEndpoint "${DEMO_KAS_URI}" \
--allowList "${DEMO_KAS_ALLOWLIST}" \
--oidcEndpoint "${DEMO_OIDC_ENDPOINT}" \
--auth tdf-client:123-456 \
--output sample.txt.ntdf \
encrypt "${plain}" \
--attributes https://example.com/attr/Classification/value/S,https://example.com/attr/COI/value/PRX
[ -f sample.txt.ntdf ]
npx "$2" --log-level DEBUG \
--kasEndpoint "${DEMO_KAS_URI}" \
--oidcEndpoint "${DEMO_OIDC_ENDPOINT}" \
--auth tdf-client:123-456 \
--output sample_out.txt \
decrypt sample.txt.ntdf
[ -f sample_out.txt ] && diff "${plain}" sample_out.txt
echo "Roundtrip nanotdf $1 -> $2 successful!"
rm -f "${plain}" sample.txt.ntdf sample_out.txt
}
_nano_test @opentdf/ctl @opentdf/ctl
_tdf3_test() {
counter=$((counter + 1))
plain="./sample-${counter}.txt"
echo "Hello World ${counter}" >"${plain}"
npx "$1" --log-level DEBUG \
--kasEndpoint "${DEMO_KAS_URI}" \
--oidcEndpoint "${DEMO_OIDC_ENDPOINT}" \
--auth tdf-client:123-456 \
--output sample.txt.tdf \
encrypt "${plain}" \
--containerType tdf3 \
--attributes https://example.com/attr/Classification/value/S,https://example.com/attr/COI/value/PRX
[ -f sample.txt.tdf ]
npx "$2" --log-level DEBUG \
--kasEndpoint "${DEMO_KAS_URI}" \
--oidcEndpoint "${DEMO_OIDC_ENDPOINT}" \
--auth tdf-client:123-456 \
--output sample_out.txt \
--containerType tdf3 \
decrypt sample.txt.tdf
[ -f sample_out.txt ] && diff "${plain}" sample_out.txt
echo "Roundtrip tdf3 $1 -> $2 successful!"
rm -f "${plain}" sample.txt.tdf sample_out.txt
}
_tdf3_test @opentdf/ctl @opentdf/ctl