@@ -23,6 +23,21 @@ readonly DEFAULT_CIPHER='aes-256-cbc'
23
23
24
24
# #### FUNCTIONS
25
25
26
+ # load encryption password
27
+ # by default is stored in git config, modify this function to move elsewhere
28
+ load_password () {
29
+ local password
30
+ password=$( git config --get --local transcrypt.password)
31
+ echo " $password "
32
+ }
33
+
34
+ # save encryption password
35
+ # by default is stored in git config, modify this function to move elsewhere
36
+ save_password () {
37
+ local password=$1
38
+ git config transcrypt.password " $password "
39
+ }
40
+
26
41
# print a canonicalized absolute pathname
27
42
realpath () {
28
43
local path=$1
@@ -136,7 +151,7 @@ git_clean() {
136
151
cat " $tempfile "
137
152
else
138
153
cipher=$( git config --get --local transcrypt.cipher)
139
- password=$( git config --get --local transcrypt.password )
154
+ password=$( load_password )
140
155
openssl_path=$( git config --get --local transcrypt.openssl-path)
141
156
salt=$( " ${openssl_path} " dgst -hmac " ${filename} :${password} " -sha256 " $tempfile " | tr -d ' \r\n' | tail -c16)
142
157
@@ -160,7 +175,7 @@ git_smudge() {
160
175
tempfile=$( mktemp 2> /dev/null || mktemp -t tmp)
161
176
trap ' rm -f "$tempfile"' EXIT
162
177
cipher=$( git config --get --local transcrypt.cipher)
163
- password=$( git config --get --local transcrypt.password )
178
+ password=$( load_password )
164
179
openssl_path=$( git config --get --local transcrypt.openssl-path)
165
180
tee " $tempfile " | ENC_PASS=$password " $openssl_path " enc -d " -${cipher} " -md MD5 -pass env:ENC_PASS -a 2> /dev/null || cat " $tempfile "
166
181
}
@@ -172,7 +187,7 @@ git_textconv() {
172
187
return
173
188
fi
174
189
cipher=$( git config --get --local transcrypt.cipher)
175
- password=$( git config --get --local transcrypt.password )
190
+ password=$( load_password )
176
191
openssl_path=$( git config --get --local transcrypt.openssl-path)
177
192
ENC_PASS=$password " $openssl_path " enc -d " -${cipher} " -md MD5 -pass env:ENC_PASS -a -in " $filename " 2> /dev/null || cat " $filename "
178
193
}
@@ -511,7 +526,7 @@ save_configuration() {
511
526
# write the encryption info
512
527
git config transcrypt.version " $VERSION "
513
528
git config transcrypt.cipher " $cipher "
514
- git config transcrypt.password " $password "
529
+ save_password " $password "
515
530
git config transcrypt.openssl-path " $openssl_path "
516
531
517
532
# write the filter settings. Sorry for the horrific quote escaping below...
@@ -538,7 +553,7 @@ display_configuration() {
538
553
local current_cipher
539
554
current_cipher=$( git config --get --local transcrypt.cipher)
540
555
local current_password
541
- current_password=$( git config --get --local transcrypt.password )
556
+ current_password=$( load_password )
542
557
local escaped_password=${current_password// \' / \'\\\'\' }
543
558
544
559
printf ' The current repository was configured using transcrypt version %s\n' " $CONFIGURED "
@@ -743,7 +758,7 @@ upgrade_transcrypt() {
743
758
744
759
# Keep current cipher and password
745
760
cipher=$( git config --get --local transcrypt.cipher)
746
- password=$( git config --get --local transcrypt.password )
761
+ password=$( load_password )
747
762
# Keep current openssl-path, or set to default if no existing value
748
763
openssl_path=$( git config --get --local transcrypt.openssl-path 2> /dev/null || printf ' %s' " $openssl_path " )
749
764
@@ -822,7 +837,7 @@ export_gpg() {
822
837
local current_cipher
823
838
current_cipher=$( git config --get --local transcrypt.cipher)
824
839
local current_password
825
- current_password=$( git config --get --local transcrypt.password )
840
+ current_password=$( load_password )
826
841
mkdir -p " ${CRYPT_DIR} "
827
842
828
843
local gpg_encrypt_cmd=" gpg --batch --recipient $gpg_recipient --trust-model always --yes --armor --quiet --encrypt -"
0 commit comments