aboutsummaryrefslogtreecommitdiff
path: root/utils/encrypt
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-09-20 21:19:05 +0200
committerKarel Kočí <cynerd@email.cz>2017-09-20 21:22:36 +0200
commitf287ecedc78c0cc8fb485c5995b8d1cfae9f0fe8 (patch)
tree5025b33a8c3d4c69ad2b62e1169b669c56f712f9 /utils/encrypt
parent65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3 (diff)
downloadmulticonfig-f287ecedc78c0cc8fb485c5995b8d1cfae9f0fe8.tar.gz
multiconfig-f287ecedc78c0cc8fb485c5995b8d1cfae9f0fe8.tar.bz2
multiconfig-f287ecedc78c0cc8fb485c5995b8d1cfae9f0fe8.zip
Commit current statecomplicated
Diffstat (limited to 'utils/encrypt')
-rw-r--r--utils/encrypt42
1 files changed, 42 insertions, 0 deletions
diff --git a/utils/encrypt b/utils/encrypt
new file mode 100644
index 0000000..d1cb938
--- /dev/null
+++ b/utils/encrypt
@@ -0,0 +1,42 @@
+# vim:ft=sh:noexpandtab
+# Allows work with encrypted files using their temporally copy.
+
+if [ -n "$KEY_FILE" ] && [ -f "files/keys/$(hostname)" ]; then
+ SECRET_KEY="$(openssl aes-192-cbc -d -a -kfile "$KEY_FILE" -in files/keys/"$(hostname)")"
+else
+ SECRET_KEY="$(gpg2 --decrypt files/keys/primary.gpg)"
+fi
+
+# Decrypt to temporally file in /tmp
+# First argument should be the path to file to be decrypted and second argument
+# output file.
+fdecrypt() {
+ PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -d -a -pass env:PASS_ENC -in "$1" -out "$2"
+}
+
+# Encrypt given file to target path
+# First argument have to be a path to file to be encrypted and second argument
+# output file.
+fencprypt() {
+ PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -e -a -pass env:PASS_ENC -in "$1" -out "$2"
+}
+
+# Decrypt file to temporally one
+# First argument have to be path to file to be extracted.
+tfdecrypt() {
+ local TEMPF="$(mktemp /tmp/multiconfig_XXXXXXXX)"
+ fdecrypt "$1" "$TEMPF"
+ echo "$TEMPF"
+}
+
+# Cat decrypted file
+# First argument have to be a path to file to be catted.
+catdecrypt() {
+ PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -d -a -pass env:PASS_ENC -in "$1"
+}
+
+# Encrypt stdin to file
+# First argument have to be a path to output file.
+outencrypt() {
+ PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -e -a -pass env:PASS_ENC -out "$2"
+}