blob: 2cec945f592cc8b843d9d7a1f90350b0b66073d4 [file] [log] [blame]
Gilles Peskinef0fa4362018-07-16 17:08:43 +02001#!/bin/sh
2set -e -u
3
4program="${0%/*}"/key_ladder_demo
5files_to_clean=
6
7run () {
8 echo
9 echo "# $1"
10 shift
11 echo "+ $*"
12 "$@"
13}
14
15if [ -e master.key ]; then
16 echo "# Reusing the existing master.key file."
17else
18 files_to_clean="$files_to_clean master.key"
19 run "Generate a master key." \
20 "$program" generate master=master.key
21fi
22
23files_to_clean="$files_to_clean input.txt hello_world.wrap"
24echo "Here is some input. See it wrapped." >input.txt
25run "Derive a key and wrap some data with it." \
26 "$program" wrap master=master.key label=hello label=world \
27 input=input.txt output=hello_world.wrap
28
29files_to_clean="$files_to_clean hello_world.txt"
30run "Derive the same key again and unwrap the data." \
31 "$program" unwrap master=master.key label=hello label=world \
32 input=hello_world.wrap output=hello_world.txt
33run "Compare the unwrapped data with the original input." \
34 cmp input.txt hello_world.txt
35
36files_to_clean="$files_to_clean hellow_orld.txt"
37! run "Derive a different key and attempt to unwrap the data. This must fail." \
38 "$program" unwrap master=master.key input=hello_world.wrap output=hellow_orld.txt label=hellow label=orld
39
40files_to_clean="$files_to_clean hello.key"
41run "Save the first step of the key ladder, then load it as a master key and construct the rest of the ladder." \
42 "$program" save master=master.key label=hello \
43 input=hello_world.wrap output=hello.key
44run "Check that we get the same key by unwrapping data made by the other key." \
45 "$program" unwrap master=hello.key label=world \
46 input=hello_world.wrap output=hello_world.txt
47
48# Cleanup
49rm -f $files_to_clean