From 1864e3ae9879ee80c7b454116683983fc41ea68f Mon Sep 17 00:00:00 2001 From: Dan Staples Date: Fri, 3 Jan 2014 15:26:26 -0500 Subject: [PATCH 1/3] added HIDE_KEY_ID and SECRET_KEYRING options --- duplicity-backup.conf.example | 11 +++++++++++ duplicity-backup.sh | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example index 04d8f09..43fd688 100644 --- a/duplicity-backup.conf.example +++ b/duplicity-backup.conf.example @@ -81,6 +81,17 @@ PASSPHRASE="foobar_gpg_passphrase" GPG_ENC_KEY="foobar_gpg_key" GPG_SIGN_KEY="foobar_gpg_key" +# Do you want to hide the key id of the encrypted files? yes/no +# It uses the gpg's --hidden-recipient command to obfuscate the owner of the backup. +# On restore, gpg will automatically try all available secret keys in order to +# decrypt the backup. See gpg(1) for more details. +# HIDE_KEY_ID='yes' + +# You can optionally specify the secret keyring file to use for the encryption and +# signing keys. If not specified, the default secret keyring is used which is +# usually located at ~/.gnupg/secring.gpg +# SECRET_KEYRING="/home/foobar_user_name/.gnupg/duplicity.gpg + # BACKUP SOURCE INFORMATION # The ROOT of your backup (where you want the backup to start); # This can be / or somwhere else -- I use /home/ because all the diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 26dc124..eb90088 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -186,7 +186,15 @@ LOCKFILE=${LOGDIR}backup.lock if [ "$ENCRYPTION" = "yes" ]; then if [ ! -z "$GPG_ENC_KEY" ] && [ ! -z "$GPG_SIGN_KEY" ]; then - ENCRYPT="--encrypt-key=${GPG_ENC_KEY} --sign-key=${GPG_SIGN_KEY}" + if [ "$HIDE_KEY_ID" = "yes" ]; then + ENCRYPT="--hidden-encrypt-key=${GPG_ENC_KEY} --sign-key=${GPG_SIGN_KEY}" + else + ENCRYPT="--encrypt-key=${GPG_ENC_KEY} --sign-key=${GPG_SIGN_KEY}" + fi + if [ ! -z "$SECRET_KEYRING" ]; then + KEYRING="--secret-keyring ${SECRET_KEYRING}" + ENCRYPT="${ENCRYPT} --encrypt-secret-keyring=${SECRET_KEYRING}" + fi elif [ ! -z "$PASSPHRASE" ]; then ENCRYPT="" fi @@ -506,10 +514,10 @@ backup_this_script() if [ ! -z "$GPG_ENC_KEY" -a ! -z "$GPG_SIGN_KEY" ]; then export GPG_TTY=`tty` if [ "$GPG_ENC_KEY" = "$GPG_SIGN_KEY" ]; then - gpg -a --export-secret-keys ${GPG_ENC_KEY} > ${TMPDIR}/duplicity-backup-encryption-and-sign-secret.key.txt + gpg -a --export-secret-keys ${KEYRING} ${GPG_ENC_KEY} > ${TMPDIR}/duplicity-backup-encryption-and-sign-secret.key.txt else - gpg -a --export-secret-keys ${GPG_ENC_KEY} > ${TMPDIR}/duplicity-backup-encryption-secret.key.txt - gpg -a --export-secret-keys ${GPG_SIGN_KEY} > ${TMPDIR}/duplicity-backup-sign-secret.key.txt + gpg -a --export-secret-keys ${KEYRING} ${GPG_ENC_KEY} > ${TMPDIR}/duplicity-backup-encryption-secret.key.txt + gpg -a --export-secret-keys ${KEYRING} ${GPG_SIGN_KEY} > ${TMPDIR}/duplicity-backup-sign-secret.key.txt fi fi From 417d5262c7f5d7bc0e93707b99d6ab1c5f806a40 Mon Sep 17 00:00:00 2001 From: Dan Staples Date: Fri, 3 Jan 2014 16:25:26 -0500 Subject: [PATCH 2/3] only cleanup if CLEAN_UP_TYPE and CLEAN_UP_VARIABLE are defined --- duplicity-backup.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/duplicity-backup.sh b/duplicity-backup.sh index eb90088..673c55f 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -420,10 +420,12 @@ include_exclude() duplicity_cleanup() { echo "-----------[ Duplicity Cleanup ]-----------" >> ${LOGFILE} - eval ${ECHO} ${DUPLICITY} ${CLEAN_UP_TYPE} ${CLEAN_UP_VARIABLE} ${STATIC_OPTIONS} --force \ + if [[ ! -z ${CLEAN_UP_TYPE} && ! -z ${CLEAN_UP_VARIABLE} ]]; then + eval ${ECHO} ${DUPLICITY} ${CLEAN_UP_TYPE} ${CLEAN_UP_VARIABLE} ${STATIC_OPTIONS} --force \ ${ENCRYPT} \ ${DEST} >> ${LOGFILE} - echo >> ${LOGFILE} + echo >> ${LOGFILE} + fi if [ ! -z ${REMOVE_INCREMENTALS_OLDER_THAN} ] && [[ ${REMOVE_INCREMENTALS_OLDER_THAN} =~ ^[0-9]+$ ]]; then eval ${ECHO} ${DUPLICITY} remove-all-inc-of-but-n-full ${REMOVE_INCREMENTALS_OLDER_THAN} \ ${STATIC_OPTIONS} --force \ From 22099553ab420339483badb74858c3a92121881d Mon Sep 17 00:00:00 2001 From: Dan Staples Date: Mon, 6 Jan 2014 17:24:51 -0500 Subject: [PATCH 3/3] dont include --sign-key when restoring w/ hidden-enc key --- duplicity-backup.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 673c55f..21a6d27 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -187,7 +187,10 @@ LOCKFILE=${LOGDIR}backup.lock if [ "$ENCRYPTION" = "yes" ]; then if [ ! -z "$GPG_ENC_KEY" ] && [ ! -z "$GPG_SIGN_KEY" ]; then if [ "$HIDE_KEY_ID" = "yes" ]; then - ENCRYPT="--hidden-encrypt-key=${GPG_ENC_KEY} --sign-key=${GPG_SIGN_KEY}" + ENCRYPT="--hidden-encrypt-key=${GPG_ENC_KEY}" + if [ "$COMMAND" != "restore" -a "$COMMAND" != "restore-file" -a "$COMMAND" != "restore-dir" ]; then + ENCRYPT="$ENCRYPT --sign-key=${GPG_SIGN_KEY}" + fi else ENCRYPT="--encrypt-key=${GPG_ENC_KEY} --sign-key=${GPG_SIGN_KEY}" fi