]> git.scottworley.com Git - overonion/blob - overonion
a33351a7ece4153b72b765c204c01ac66c37f975
[overonion] / overonion
1 #!/bin/bash
2
3 function die() {
4 echo "$*" >&2
5 exit 1
6 }
7
8 if (( $# != 2));then
9 die "usage: overonion e|d keyfile"
10 fi
11 mode=$1
12 if [[ "$mode" != e && "$mode" != d ]];then
13 die "Use 'e' for encrypt or 'd' for decrypt"
14 fi
15 keyfile=$2
16 if [[ ! -e "$keyfile" ]];then
17 die "Keyfile not found"
18 fi
19 if [[ ! -r "$keyfile" ]];then
20 die "Cannot read keyfile"
21 fi
22
23 num_layers=$(wc -l < "$keyfile")
24 if (( num_layers < 20 ));then
25 die "Keyfile doesn't have enough layers to be an onion"
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"