Skip to content

Commit

Permalink
202003.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lechgu committed Mar 17, 2020
1 parent c56a484 commit 5922262
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = .venv
ignore = E203
ignore = E203, E231

[isort]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ Hush does not require a master password as other password managers do, instead i

#### What's new?

- Version 202003.5 (Mar 17, 2020)

- Fixed configuration initialization issue

- Version 202003.4 (Mar 6, 2020)

- introduced GCM mode for the AES encryption. Choose between GCM and EAX. For the secrets encrypted with the previous version explicitly pass `--mode eax` to decrypt.
- Introduced GCM mode for the AES encryption. Choose between GCM and EAX. For the secrets encrypted with the previous version explicitly pass `--mode eax` to decrypt.

- Version 202001.4 (Jan 23, 2020)

Expand Down
50 changes: 30 additions & 20 deletions hush/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def config_callback(ctx, param, value):


@click.group()
@click.version_option("202003.4")
@click.version_option("202003.5")
@click.option(
"-c",
"--config-file",
Expand Down Expand Up @@ -344,23 +344,33 @@ def config(ctx, list, set, val):
"-p", "--public-key-file", type=str, required=True, help="Public key file",
)
@click.option(
"--yes", type=bool, help="Overwrite the existing config file if exists.",
"-f",
"--overwrite",
is_flag=True,
help="Overwrite the existing config file if exists.",
)
def init(ctx, private_key_file, public_key_file, yes):
if not yes and os.path.exists(ctx.config_file):
yn = click.prompt(f"{ctx.config_file} exists, overwrite? [y/n]")
yes = yn.strip() and yn[0].lower() == "y"
if yes:
with configuration(ctx.config_file) as config:
values = [
("generate", "length", str(DEFAULT_PASSWORD_LENGTH)),
("generate", "character_clsses", DEFAULT_CHARACTER_CLASSES),
("decrypt", "private_key_file", private_key_file),
("encrypt", "public_key_file", public_key_file),
]
for (section, key, v) in values:
if section not in config.sections():
config.add_section(section)
config[section][key] = v

pass
def init(ctx, private_key_file, public_key_file, overwrite):
if os.path.exists(ctx.config_file):
if overwrite:
os.remove(ctx.config_file)
else:
yn = click.prompt(f"{ctx.config_file} exists, overwrite? [y/n]")
yes = yn.strip() and yn[0].lower() == "y"
if yes:
os.remove(ctx.config_file)
else:
return 1

with configuration(ctx.config_file) as config:
values = [
("generate", "length", str(DEFAULT_PASSWORD_LENGTH)),
("generate", "character_clsses", DEFAULT_CHARACTER_CLASSES),
("encrypt", "public_key_file", public_key_file),
("encrypt", "mode", "eax"),
("decrypt", "private_key_file", private_key_file),
("decrypt", "mode", "eax"),
]
for (section, key, v) in values:
if section not in config.sections():
config.add_section(section)
config[section][key] = v
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ multi_line_output=3
include_trailing_comma = true

[pycalver]
current_version = "v202001.0003"
current_version = "v202003.0005"
version_pattern = "{pycalver}"
commit = false
tag = false
Expand All @@ -30,7 +30,7 @@ push = false

[tool.poetry]
name = "hush"
version = "202003.4"
version = "202003.5"
description = "Minimalistic command line secret management"
license = "BSD-3-Clause"
authors = ["Lech Gudalewicz <[email protected]>"]
Expand Down
44 changes: 43 additions & 1 deletion tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ def config_file(lines):
os.remove(file_name)


@contextmanager
def temp_file():
file_name = mktemp()
yield file_name
os.remove(file_name)


def test_version():
runner = CliRunner()
output = runner.invoke(cli, "--version").output.strip()

assert "202003.4" in output
assert "202003.5" in output


def test_generate_default():
Expand Down Expand Up @@ -278,6 +285,41 @@ def test_change_passphrase_empty():
assert result.output.strip() == "secret"


def test_config_init():
runner = CliRunner()
with temp_file() as t:
with keypair():
result = runner.invoke(
cli, ["-c", t, "init", "-r", "rsa.pri", "-p", "rsa.pub"],
)
assert result.exit_code == 0
result = runner.invoke(cli, ["-c", t, "config", "encrypt.mode"])
assert result.exit_code == 0
assert result.output.strip() == "eax"


def test_config_init_override():
runner = CliRunner()
with temp_file() as t:
with keypair():
result = runner.invoke(
cli, ["-c", t, "init", "-r", "rsa.pri", "-p", "rsa.pub"],
)
assert result.exit_code == 0
result = runner.invoke(
cli, ["-c", t, "config", "-s", "encrypt.mode", "gcm"]
)
assert result.exit_code == 0
result = runner.invoke(cli, ["-c", t, "config", "encrypt.mode"])
assert result.exit_code == 0
assert result.output.strip() == "gcm"
result = runner.invoke(
cli,
["-c", t, "init", "-f", "-r", "rsa.pri", "-p", "rsa.pub",],
)
assert result.exit_code == 0


def test_alterantive_config():
lines = """
[generate]
Expand Down

0 comments on commit 5922262

Please sign in to comment.