Skip to content

Commit 2262fb7

Browse files
committed
Rename salt-method to base-salt
1 parent 3a4f578 commit 2262fb7

File tree

2 files changed

+58
-55
lines changed

2 files changed

+58
-55
lines changed

tests/test_transcrypt.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Transcrypt(ub.NiceRepr):
2626
>>> sandbox = DemoSandbox(verbose=1, dpath='special:cache').setup()
2727
>>> config = {'digest': 'sha256',
2828
>>> 'kdf': 'pbkdf2',
29-
>>> 'salt_method': '665896be121e1a0a4a7b18f01780061'}
29+
>>> 'base_salt': '665896be121e1a0a4a7b18f01780061'}
3030
>>> self = Transcrypt(sandbox.repo_dpath,
3131
>>> config=config, env=sandbox.env, verbose=1)
3232
>>> print(self.version())
@@ -57,7 +57,7 @@ class Transcrypt(ub.NiceRepr):
5757
'password': None,
5858
'digest': 'md5',
5959
'kdf': 'none',
60-
'salt_method': 'password',
60+
'base_salt': 'password',
6161
}
6262

6363
def __init__(self, dpath, config=None, env=None, transcript_exe=None, verbose=0):
@@ -89,7 +89,7 @@ def _config_args(self):
8989
"-p", self.config['password'],
9090
"-md", self.config['digest'],
9191
"--kdf", self.config['kdf'],
92-
"-sm", self.config['salt_method'],
92+
"-bs", self.config['base_salt'],
9393
]
9494
args = [template.format(**self.config) for template in arg_templates]
9595
return args
@@ -111,7 +111,7 @@ def login(self):
111111
args = self._config_args()
112112
command = [str(self.transcript_exe), *args, '-y']
113113
self._cmd(command)
114-
self.config['salt_method'] = self._load_unversioned_config()['salt_method']
114+
self.config['base_salt'] = self._load_unversioned_config()['base_salt']
115115

116116
def logout(self):
117117
"""
@@ -127,7 +127,7 @@ def rekey(self, new_config):
127127
args = self._config_args()
128128
command = [str(self.transcript_exe), '--rekey', *args, '-y']
129129
self._cmd(command)
130-
self.config['salt_method'] = self._load_unversioned_config()['salt_method']
130+
self.config['base_salt'] = self._load_unversioned_config()['base_salt']
131131

132132
def display(self):
133133
"""
@@ -202,7 +202,7 @@ def _load_unversioned_config(self):
202202
'cipher': self._cmd('git config --get --local transcrypt.cipher')['out'].strip(),
203203
'digest': self._cmd('git config --get --local transcrypt.digest')['out'].strip(),
204204
'kdf': self._cmd('git config --get --local transcrypt.kdf')['out'].strip(),
205-
'salt_method': self._cmd('git config --get --local transcrypt.salt-method')['out'].strip(),
205+
'base_salt': self._cmd('git config --get --local transcrypt.base-salt')['out'].strip(),
206206
'password': self._cmd('git config --get --local transcrypt.password')['out'].strip(),
207207
'openssl_path': self._cmd('git config --get --local transcrypt.openssl-path')['out'].strip(),
208208
}
@@ -237,6 +237,8 @@ def setup(self):
237237
self._setup_gpghome()
238238
self._setup_gitrepo()
239239
self._setup_contents()
240+
if self.verbose > 2:
241+
self._show_manual_env_setup()
240242
return self
241243

242244
def _setup_gpghome(self):
@@ -262,6 +264,8 @@ def _setup_gpghome(self):
262264
ub.cmd('find ' + str(self.gpg_home) + r' -type f -exec chmod 600 {} \;', shell=True, cwd=self.gpg_home)
263265
ub.cmd('find ' + str(self.gpg_home) + r' -type d -exec chmod 700 {} \;', shell=True, cwd=self.gpg_home)
264266
self.env['GNUPGHOME'] = str(self.gpg_home)
267+
if self.verbose:
268+
pass
265269

266270
def _setup_gitrepo(self):
267271
if self.verbose:
@@ -298,7 +302,7 @@ def _setup_contents(self):
298302
self.secret_fpath = self.safe_dpath / 'secret.txt'
299303
self.secret_fpath.write_text('secret content')
300304

301-
def _manual_hack_info(self):
305+
def _show_manual_env_setup(self):
302306
"""
303307
Info on how to get an env to run a failing command manually
304308
"""
@@ -393,7 +397,7 @@ def test_rekey(self):
393397
'password': '12345',
394398
'digest': 'sha256',
395399
'kdf': 'pbkdf2',
396-
'salt_method': 'random',
400+
'base_salt': 'random',
397401
}
398402
raw_before = self.tc.show_raw(self.sandbox.secret_fpath)
399403
self.tc.rekey(new_config)
@@ -408,7 +412,7 @@ def test_legacy_defaults():
408412
'password': 'correct horse battery staple',
409413
'digest': 'md5',
410414
'kdf': 'none',
411-
'salt_method': 'password',
415+
'base_salt': 'password',
412416
}
413417
verbose = 1
414418
self = TestCases(config=config, verbose=verbose)
@@ -423,7 +427,7 @@ def test_secure_defaults():
423427
'password': 'correct horse battery staple',
424428
'digest': 'sha512',
425429
'kdf': 'pbkdf2',
426-
'salt_method': 'random',
430+
'base_salt': 'random',
427431
}
428432
verbose = 1
429433
self = TestCases(config=config, verbose=verbose)
@@ -438,19 +442,19 @@ def test_configured_salt_changes_on_rekey():
438442
'password': 'correct horse battery staple',
439443
'digest': 'sha512',
440444
'kdf': 'pbkdf2',
441-
'salt_method': 'random',
445+
'base_salt': 'random',
442446
}
443447
verbose = 1
444448
self = TestCases(config=config, verbose=verbose)
445449
self.setup()
446450
before_config = self.tc._load_unversioned_config()
447-
self.tc.rekey({'password': '12345', 'salt_method': ''})
451+
self.tc.rekey({'password': '12345', 'base_salt': ''})
448452
self.sandbox.git.commit('-am commit rekey')
449453
after_config = self.tc._load_unversioned_config()
450454
assert before_config['password'] != after_config['password']
451455
assert before_config['cipher'] == after_config['cipher']
452456
assert before_config['kdf'] == after_config['kdf']
453-
assert before_config['salt_method'] == after_config['salt_method']
457+
assert before_config['base_salt'] == after_config['base_salt']
454458
assert before_config['openssl_path'] == after_config['openssl_path']
455459

456460

@@ -463,7 +467,7 @@ def test_configuration_grid():
463467
>>> from test_transcrypt import * # NOQA
464468
>>> self = TestCases()
465469
>>> self.setup()
466-
>>> self.sandbox._manual_hack_info()
470+
>>> self.sandbox._show_manual_env_setup()
467471
>>> self.test_round_trip()
468472
>>> self.test_export_gpg()
469473
"""
@@ -473,10 +477,10 @@ def test_configuration_grid():
473477
'password': ['correct horse battery staple'],
474478
'digest': ['md5', 'sha256'],
475479
'kdf': ['none', 'pbkdf2'],
476-
'salt_method': ['password', 'random', 'mylittlecustomsalt'],
480+
'base_salt': ['password', 'random', 'mylittlecustomsalt'],
477481
}
478482
test_grid = list(ub.named_product(basis))
479-
verbose = 0
483+
verbose = 3
480484
dpath = 'special:temp'
481485
dpath = 'special:cache'
482486
for params in ub.ProgIter(test_grid, desc='test configs', freq=1):
@@ -485,7 +489,7 @@ def test_configuration_grid():
485489
self.setup()
486490
if 1:
487491
# Manual debug
488-
self.sandbox._manual_hack_info()
492+
self.sandbox._show_manual_env_setup()
489493

490494
self.test_round_trip()
491495
self.test_export_gpg()

transcrypt

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ _load_transcrypt_config_vars() {
238238
cipher=$(_load_config_var "transcrypt.cipher") || (echo "failed to load transcrypt.cipher" && false)
239239
digest=$(_load_config_var "transcrypt.digest") || (echo "failed to load transcrypt.digest" && false)
240240
kdf=$(_load_config_var "transcrypt.kdf") || (echo "failed to load transcrypt.kdf" && false)
241-
salt_method=$(_load_config_var "transcrypt.salt-method") || (echo "failed to load transcrypt.salt-method" && false)
241+
base_salt=$(_load_config_var "transcrypt.base-salt") || (echo "failed to load transcrypt.base-salt" && false)
242242
openssl_path=$(_load_config_var "transcrypt.openssl-path") || (echo "failed to load transcrypt.openssl-path" && false)
243243
password=$(_load_unversioned_config_var transcrypt.password) || (echo "failed to load transcrypt.password" && false)
244-
ensure_salt_method
244+
ensure_base_salt
245245
validate_kdf || die "invalid value of kdf in config"
246246
validate_digest || die "invalid value of digest in config"
247247
}
@@ -254,12 +254,12 @@ _load_vars_for_encryption() {
254254
pbkdf2_arg='-pbkdf2'
255255
fi
256256

257-
if [[ "$salt_method" == "password" ]]; then
257+
if [[ "$base_salt" == "password" ]]; then
258258
extra_salt=$password
259-
elif [[ "$salt_method" == "" ]]; then
259+
elif [[ "$base_salt" == "" ]]; then
260260
die "salt must be specified"
261261
else
262-
extra_salt=$salt_method
262+
extra_salt=$base_salt
263263
fi
264264

265265
if [[ "$extra_salt" == "" ]]; then
@@ -569,7 +569,7 @@ validate_kdf() {
569569
_validate_variable_str "kdf" "0 1 none pbkdf2"
570570
}
571571

572-
validate_salt_method() {
572+
validate_base_salt() {
573573
true
574574
}
575575

@@ -605,16 +605,15 @@ get_kdf() {
605605
_get_user_input kdf "$DEFAULT_KDF" "validate_kdf" "$prompt"
606606
}
607607

608-
get_salt_method() {
608+
get_base_salt() {
609609
local prompt
610-
prompt=$(printf 'Which salt method? [%s] ' "$DEFAULT_SALT_METHOD")
611-
if [[ "$salt_method" == "" ]]; then
612-
salt_method=$(_load_versioned_config_var "transcrypt.salt-method" || echo "")
613-
# echo "Loaded salt_method = $salt_method from local config"
610+
prompt=$(printf 'Which base salt? [%s] ' "$DEFAULT_SALT_METHOD")
611+
if [[ "$base_salt" == "" ]]; then
612+
base_salt=$(_load_versioned_config_var "transcrypt.base-salt" || echo "")
613+
# echo "Loaded base_salt = $base_salt from local config"
614614
fi
615-
_get_user_input salt_method "$DEFAULT_SALT_METHOD" "validate_salt_method" "$prompt"
616-
ensure_salt_method
617-
# echo "Got salt_method = $salt_method"
615+
_get_user_input base_salt "$DEFAULT_SALT_METHOD" "validate_base_salt" "$prompt"
616+
ensure_base_salt
618617
}
619618

620619
# ensure we have a password to encrypt with
@@ -642,17 +641,17 @@ get_password() {
642641
done
643642
}
644643

645-
ensure_salt_method() {
644+
ensure_base_salt() {
646645
# Check if randomized salt needs to be written
647-
if [[ "$salt_method" == "random" ]]; then
646+
if [[ "$base_salt" == "random" ]]; then
648647
# Replace random with something random.
649-
# If we have not configured the salt_method (or we need to rekey),
648+
# If we have not configured the base_salt (or we need to rekey),
650649
# then generate new random salt
651-
salt_method=$(openssl rand -hex 32)
650+
base_salt=$(openssl rand -hex 32)
652651
fi
653-
if [[ $rekey ]] && [[ $salt_method != "password" ]]; then
652+
if [[ $rekey ]] && [[ $base_salt != "password" ]]; then
654653
# Assume we want a new random salt unless we are explicitly using password
655-
salt_method=$(openssl rand -hex 32)
654+
base_salt=$(openssl rand -hex 32)
656655
fi
657656
}
658657

@@ -767,7 +766,7 @@ save_configuration() {
767766
_set_config_var "transcrypt.cipher" "$cipher"
768767
_set_config_var "transcrypt.digest" "$digest"
769768
_set_config_var "transcrypt.kdf" "$kdf"
770-
_set_config_var "transcrypt.salt-method" "$salt_method"
769+
_set_config_var "transcrypt.base-salt" "$base_salt"
771770
_set_unversioned_config_var "transcrypt.openssl-path" "$openssl_path"
772771
_set_unversioned_config_var "transcrypt.password" "$password"
773772

@@ -816,9 +815,9 @@ _display_git_configuration() {
816815
_display_runtime_configuration() {
817816
printf ' DIGEST: %s\n' "$digest"
818817
printf ' KDF: %s\n' "$kdf"
819-
printf ' SALT_METHOD: %s\n' "$salt_method"
820-
if [[ "$salt_method" == "configured" ]]; then
821-
printf ' CONFIG_SALT: %s\n' "$salt_method"
818+
printf ' SALT_METHOD: %s\n' "$base_salt"
819+
if [[ "$base_salt" == "configured" ]]; then
820+
printf ' CONFIG_SALT: %s\n' "$base_salt"
822821
fi
823822
printf ' CIPHER: %s\n' "$cipher"
824823
printf ' PASSWORD: %s\n\n' "$password"
@@ -833,8 +832,8 @@ display_configuration() {
833832
_display_git_configuration
834833
_display_runtime_configuration
835834
printf 'Copy and paste the following command to initialize a cloned repository:\n\n'
836-
printf " transcrypt -c '%s' -p '%s' -md '%s' --kdf '%s' -sm '%s'\n" \
837-
"$cipher" "$escaped_password" "$digest" "$kdf" "$salt_method"
835+
printf " transcrypt -c '%s' -p '%s' -md '%s' --kdf '%s' -bs '%s'\n" \
836+
"$cipher" "$escaped_password" "$digest" "$kdf" "$base_salt"
838837
}
839838

840839
# remove transcrypt-related settings from the repository's git config
@@ -1114,8 +1113,8 @@ export_gpg() {
11141113

11151114
local gpg_encrypt_cmd="gpg --batch --recipient $gpg_recipient --trust-model always --yes --armor --quiet --encrypt -"
11161115
#printf 'password=%s\ncipher=%s\n' "$current_password" "$current_cipher" | $gpg_encrypt_cmd >"${CRYPT_DIR}/${gpg_recipient}.asc"
1117-
printf 'password=%s\ncipher=%s\ndigest=%s\nkdf=%s\nsalt_method=%s\n\n' \
1118-
"$password" "$cipher" "$digest" "$kdf" "$salt_method" |
1116+
printf 'password=%s\ncipher=%s\ndigest=%s\nkdf=%s\nbase_salt=%s\n\n' \
1117+
"$password" "$cipher" "$digest" "$kdf" "$base_salt" |
11191118
$gpg_encrypt_cmd >"${CRYPT_DIR}/${gpg_recipient}.asc"
11201119
printf "The transcrypt configuration has been encrypted and exported to:\n%s/crypt/%s.asc\n" "$GIT_DIR" "$gpg_recipient"
11211120
}
@@ -1151,8 +1150,8 @@ import_gpg() {
11511150
password=$(printf '%s' "$configuration" | grep '^password' | cut -d'=' -f 2-)
11521151
digest=$(printf '%s' "$configuration" | grep '^digest' | cut -d'=' -f 2-)
11531152
kdf=$(printf '%s' "$configuration" | grep '^kdf' | cut -d'=' -f 2-)
1154-
salt_method=$(printf '%s' "$configuration" | grep '^salt_method' | cut -d'=' -f 2-)
1155-
salt_method=$(printf '%s' "$configuration" | grep '^salt_method' | cut -d'=' -f 2-)
1153+
base_salt=$(printf '%s' "$configuration" | grep '^base_salt' | cut -d'=' -f 2-)
1154+
base_salt=$(printf '%s' "$configuration" | grep '^base_salt' | cut -d'=' -f 2-)
11561155
}
11571156

11581157
# print this script's usage message to stderr
@@ -1202,7 +1201,7 @@ help() {
12021201
-pbkdf2
12031202
equivalent to passing --kdf2='pbkdf2'
12041203
1205-
-sm, --salt_method=SALT_METHOD
1204+
-bs, --base-salt=SALT_METHOD
12061205
Method used to compute deterministic salt; can be 'password', 'random',
12071206
or a custom string to be used as the salt. Unless set to password,
12081207
the salt is randomized on a rekey.
@@ -1314,8 +1313,8 @@ transcrypt_main() {
13141313
openssl_path='openssl'
13151314
kdf=''
13161315
digest=''
1317-
salt_method=''
1318-
salt_method=''
1316+
base_salt=''
1317+
base_salt=''
13191318

13201319
# used to bypass certain safety checks
13211320
requires_existing_config=''
@@ -1374,12 +1373,12 @@ transcrypt_main() {
13741373
--kdf=*)
13751374
kdf=${1#*=}
13761375
;;
1377-
-sm | --salt-method)
1378-
salt_method=$2
1376+
-bs | --base-salt)
1377+
base_salt=$2
13791378
shift
13801379
;;
1381-
--salt-method=*)
1382-
salt_method=${1#*=}
1380+
--base-salt=*)
1381+
base_salt=${1#*=}
13831382
;;
13841383
-p | --password)
13851384
password=$2
@@ -1520,7 +1519,7 @@ transcrypt_main() {
15201519
get_cipher
15211520
get_digest
15221521
get_kdf
1523-
get_salt_method
1522+
get_base_salt
15241523
get_password
15251524

15261525
if [[ $rekey ]] && [[ $interactive ]]; then

0 commit comments

Comments
 (0)