From 6105190e78629534d98582b625ce90d338c7cc17 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 18:48:56 -0600 Subject: [PATCH] Fixed critical issues relating to encryption, including misplaced files and failure to erase temporary files. --- src/bash-completion/sns | 1 + src/includes/create.sns.sh | 2 +- src/includes/edit.sns.sh | 8 +++++--- src/includes/init_store.sns.sh | 2 +- src/includes/libencryption.sns.sh | 4 ++-- src/includes/p_header.sh | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/bash-completion/sns b/src/bash-completion/sns index 1ede6c3..1d49269 100644 --- a/src/bash-completion/sns +++ b/src/bash-completion/sns @@ -47,6 +47,7 @@ _sns_complete_entries () { [[ -d $item ]] && item="$item/" item="${item%$suffix}" + item="${item%.gpg}" COMPREPLY+=("${item#$prefix}") done } diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 2303d23..6b1f04e 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -29,7 +29,7 @@ function create(){ if [ -e "$NOTES_DIR/$NOTE" ]; then printf " - %s\n" "Created note: ${NOTE%.*}" else - >&2 printf " $RED_COLOR!$RESET_COLOR%s\n"\ + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ "Something went wrong, and the note was not created." fi } diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index f2e88f7..79ebc47 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -17,7 +17,7 @@ fi # If encryption is enabled, decrypt $NOTE to a temp file, otherwise # operate on the note directly. if [ "$ENCRYPTION" == "TRUE" ]; then - cp "$NOTES_DIR/$NOTE" "$NOTES_DIR$/$NOTE".bk #Insurance + cp "$NOTES_DIR/$NOTE" "$NOTES_DIR/$NOTE.bk" #Insurance TMP_NOTE="$TMP_DIR/$SESSION_ID" decrypt > "$TMP_NOTE" else @@ -26,7 +26,7 @@ fi # Write an ammendment header if [ -z "$CREATE" ]; then - printf "\n%s\n" "edit - $(date $DATE_FMT)" >> "$TMP_NOTE" + printf "\n%s\n" "edit - $(date "$DATE_FMT")" >> "$TMP_NOTE" printf "%s\n" "===================================" >> "$TMP_NOTE" fi @@ -36,9 +36,11 @@ printf " - %s\n" "editing ${NOTE%.*}" # If the file was previously decrypted, encrypt it back if [ "$ENCRYPTION" == "TRUE" ]; then + echo "reencrypting" rm "$NOTES_DIR/$NOTE" encrypt; - if [ ! -r "$NOTE" ]; then + rm "$TMP_NOTE" + if [ ! -r "$NOTES_DIR/$NOTE" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved." cp "$NOTES_DIR/$NOTE.bk" "$NOTES_DIR/$NOTE" else diff --git a/src/includes/init_store.sns.sh b/src/includes/init_store.sns.sh index 40552b7..b3095de 100644 --- a/src/includes/init_store.sns.sh +++ b/src/includes/init_store.sns.sh @@ -16,7 +16,7 @@ EXT=note # File extension to use (for listing notes) DATE_FMT="+%D %T" # Date Format: # If you would like to modify the date format, you may - # specify one appropriate to the `date` command. + # specify one appropriate to the \`date\` command. ENCRYPTION="FALSE" # Main Encryption Toggle: # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST diff --git a/src/includes/libencryption.sns.sh b/src/includes/libencryption.sns.sh index 04ba8b3..2906341 100644 --- a/src/includes/libencryption.sns.sh +++ b/src/includes/libencryption.sns.sh @@ -3,7 +3,7 @@ function encrypt(){ # output file, $NOTE, will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private # GPG key. - gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE" + gpg -r "$PUBKEY" -o "$NOTES_DIR/$NOTE" -e "$TMP_NOTE" } @@ -11,5 +11,5 @@ function decrypt(){ # This function, given a file to decrypt, will attempt to decrypt the file # against the specified recipient's private key, and print the result to # stdout. - gpg -d "$NOTE" + gpg -d "$NOTES_DIR/$NOTE" } diff --git a/src/includes/p_header.sh b/src/includes/p_header.sh index 65a1abf..6fc43d6 100644 --- a/src/includes/p_header.sh +++ b/src/includes/p_header.sh @@ -1,3 +1,3 @@ function p_header(){ - printf "# %s\n## Date: %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")" + printf "# %s\n## %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")" }