]> git.scottworley.com Git - overonion/blob - overonion
Automate overonion test
[overonion] / overonion
1 #!/bin/bash
2
3 if (( $# != 2));then
4 echo "usage: overonion e|d keyfile"
5 exit 1
6 fi
7 mode=$1
8 if [[ "$mode" != e && "$mode" != d ]];then
9 echo "Use 'e' for encrypt or 'd' for decrypt"
10 exit 1
11 fi
12 keyfile=$2
13 if [[ ! -e "$keyfile" ]];then
14 echo "Keyfile not found"
15 exit 1
16 fi
17 if [[ ! -r "$keyfile" ]];then
18 echo "Cannot read keyfile"
19 exit 1
20 fi
21
22 num_layers=$(wc -l < "$keyfile")
23 if (( num_layers < 20 ));then
24 echo "Keyfile doesn't have enough layers to be an onion"
25 exit 1
26 fi
27
28 if [[ "$mode" == e ]];then
29 first_layer=$num_layers
30 next_layer=-1
31 openssl_decrypt=""
32 else
33 first_layer=1
34 next_layer=1
35 openssl_decrypt="-d"
36 fi
37
38 function go() {
39 layer=$1
40 if (( layer == 0 || layer > num_layers ));then
41 cat
42 else
43 openssl enc $openssl_decrypt "-$(sed -n "${layer}s/ .*//p" "$keyfile")" \
44 -pass fd:37 37< <(sed -n "${layer}s/^[^ ]* //p" "$keyfile") |
45 go $(( layer + next_layer ))
46 fi
47 }
48
49 go "$first_layer"