]>
git.scottworley.com Git - overonion/blob - overonion
cb663fe62fe6424d76e4896990f9721e55d70e81
13 die
"usage: overonion e|d keyfile"
16 if [[ "$mode" != e
&& "$mode" != d
]];then
17 die
"Use 'e' for encrypt or 'd' for decrypt"
20 if [[ ! -e "$keyfile" ]];then
21 die
"Keyfile not found"
23 if [[ ! -r "$keyfile" ]];then
24 die
"Cannot read keyfile"
27 num_layers
=$(wc -l < "$keyfile")
28 if (( num_layers
< 20 ));then
29 die
"Keyfile doesn't have enough layers to be an onion"
32 if [[ "$mode" == e
]];then
33 first_layer
=$num_layers
44 if (( layer
== 0 || layer
> num_layers
));then
47 operation
=$(sed -n "${layer}{;s/ .*//;p;}" "$keyfile")
48 if [[ "$operation" == openssl
-enc ]];then
49 openssl enc
$openssl_decrypt "-$(sed -rn "${layer}s/[^ ]+ ([^ ]+) .*/\\1/p" "$keyfile")" \
50 -pass fd:37 37< <(sed -rn "${layer}s
/^
[^
]+ [^
]+ //p
" "$keyfile")
51 elif [[ "$operation" == reverse ]];then
53 elif [[ "$operation" == openssl-dgst ]];then
54 tee >(echo "$(sed -n "${layer}p" "$keyfile") $
(
56 awk -vlayer="$layer" 'NR == layer { print $3 }' "$keyfile" | base64
-d
58 awk -vlayer="$layer" 'NR == layer { print $4 }' "$keyfile" | base64
-d
60 openssl dgst
-binary "-$(sed -rn "${layer}s/^[^ ]+ ([^ ]+).*/\\1/p" "$keyfile")" |
61 base64 --wrap=0)" > "$hash_dir/$layer")
63 die
"Unknown operation"
65 go
$(( layer + next_layer ))
71 for hash_result
in "$hash_dir"/*;do
72 layer
=$(basename "$hash_result")
73 if [[ "$mode" == e
]];then
74 # Add the hashes to keyfile
75 key_aside_dir
=$(mktemp -d "$keyfile.XXXXXXXXXX")
76 key_aside
="$key_aside_dir/key.orig"
77 mv "$keyfile" "$key_aside"
78 sed "${layer}s,.*,$(< "$hash_result")," "$key_aside" > "$keyfile"
80 rmdir "$key_aside_dir"
83 if [[ "$(awk '{ print $5 == $6 ? "hash ok" : "mismatch" }' "$hash_result")" != "hash ok" ]];then
84 die
"Hash check $layer failed"