Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4677 warns admin if v3 and https both are enabled #4720

Merged
merged 2 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions admin/securedrop_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,25 @@ def update_config(self):
self.save()
self.validate_gpg_keys()
self.validate_journalist_alert_email()
self.validate_https_and_v3()
return True

def validate_https_and_v3(self):
"""
Checks if https is enabled with v3 onion service.

:returns: False if both v3 and https enabled, True otherwise.
"""
warning_msg = ("You have configured HTTPS on your source interface "
"and v3 onion services. "
"IMPORTANT: Ensure that you update your certificate "
"to include your v3 source URL before advertising "
"it to sources! ")

if self.config.get("v3_onion_services", False) and \
self.config.get("securedrop_app_https_certificate_cert_src"):
print(warning_msg)
return False
return True

def check_for_v2_onion(self):
Expand Down
19 changes: 19 additions & 0 deletions admin/tests/test_securedrop-admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,3 +1042,22 @@ def test_find_or_generate_new_torv3_keys_subsequent_run(tmpdir, capsys):
v3_onion_service_keys = json.load(f)

assert v3_onion_service_keys == old_keys


def test_v3_and_https_cert_message(tmpdir, capsys):
args = argparse.Namespace(site_config='UNKNOWN',
ansible_path='tests/files',
app_path=dirname(__file__))
site_config = securedrop_admin.SiteConfig(args)
site_config.config = {"v3_onion_services": False,
"securedrop_app_https_certificate_cert_src": "ab.crt"} # noqa: E501
# This should return True as v3 is not setup
assert site_config.validate_https_and_v3()

# This should return False as v3 and https are both setup
site_config.config.update({"v3_onion_services": True})
assert not site_config.validate_https_and_v3()

# This should return True as https is not setup
site_config.config.update({"securedrop_app_https_certificate_cert_src": ""}) # noqa: E501
assert site_config.validate_https_and_v3()