Skip to content

Commit

Permalink
Sets CFG_KEYSTORE_DISABLED for the CMD_SYM_ENCRYPT
Browse files Browse the repository at this point in the history
Closes rnpgp#11
  • Loading branch information
joke325 authored and Daniel Wyatt committed Mar 7, 2020
1 parent 27b3a5e commit e102063
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/rnp/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,16 @@ setcmd(rnp_cfg_t *cfg, int cmd, const char *arg)
switch (cmd) {
case CMD_ENCRYPT:
rnp_cfg_setbool(cfg, CFG_ENCRYPT_PK, true);
if (rnp_cfg_getbool(cfg, CFG_ENCRYPT_SK)) {
rnp_cfg_setint(cfg, CFG_KEYSTORE_DISABLED, 0);
}
newcmd = CMD_PROTECT;
break;
case CMD_SYM_ENCRYPT:
rnp_cfg_setbool(cfg, CFG_ENCRYPT_SK, true);
if (!rnp_cfg_getbool(cfg, CFG_ENCRYPT_PK) && !rnp_cfg_getbool(cfg, CFG_SIGN_NEEDED)) {
rnp_cfg_setint(cfg, CFG_KEYSTORE_DISABLED, 1);
}
newcmd = CMD_PROTECT;
break;
case CMD_CLEARSIGN:
Expand All @@ -288,6 +294,9 @@ setcmd(rnp_cfg_t *cfg, int cmd, const char *arg)
case CMD_SIGN:
rnp_cfg_setbool(cfg, CFG_NEEDSSECKEY, true);
rnp_cfg_setbool(cfg, CFG_SIGN_NEEDED, true);
if (rnp_cfg_getbool(cfg, CFG_ENCRYPT_SK)) {
rnp_cfg_setint(cfg, CFG_KEYSTORE_DISABLED, 0);
}
newcmd = CMD_PROTECT;
break;
case CMD_DECRYPT:
Expand Down
25 changes: 25 additions & 0 deletions src/tests/cli_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,31 @@ def test_debug_log(self):
run_proc(RNPK, ['--homedir', data_path('test_stream_key_load/g10'), '--list-keys', '--debug', '--all'])
return

def test_pubring_loading(self):
test_dir = tempfile.mkdtemp(prefix='rnpctmp')
test_data = data_path('test_messages/message.txt')
output = path.join(test_dir, 'output')
params = ['--symmetric', '--password', 'pass', '--homedir', test_dir, test_data, '--output', output]

ret, _, err = run_proc(RNP, ['--encrypt'] + params)
if not (ret == 2 and 'wrong pubring path' in err):
raise_err("encrypt w/o pubring didn't fail", err)

ret, _, err = run_proc(RNP, ['--sign'] + params)
if not (ret == 2 and 'wrong pubring path' in err):
raise_err("sign w/o pubring didn't fail", err)

ret, _, err = run_proc(RNP, ['--clearsign'] + params)
if not (ret == 2 and 'wrong pubring path' in err):
raise_err("clearsign w/o pubring didn't fail", err)

ret, _, err = run_proc(RNP, params)
if ret != 0:
raise_err("symmetric w/o pubring failed", err)

shutil.rmtree(test_dir)


class Encryption(unittest.TestCase):
'''
Things to try later:
Expand Down

0 comments on commit e102063

Please sign in to comment.