diff --git a/plinth/modules/openvpn/__init__.py b/plinth/modules/openvpn/__init__.py index 776c63429..4cd43edfa 100644 --- a/plinth/modules/openvpn/__init__.py +++ b/plinth/modules/openvpn/__init__.py @@ -3,6 +3,8 @@ FreedomBox app to configure OpenVPN server. """ +import os + from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ @@ -36,6 +38,8 @@ app = None setup_process = None +SERVER_CONFIGURATION_FILE = '/etc/openvpn/server/freedombox.conf' + class OpenVPNApp(app_module.App): """FreedomBox app for OpenVPN.""" @@ -100,3 +104,13 @@ def setup(helper, old_version=None): def is_setup(): """Return whether the service is running.""" return actions.superuser_run('openvpn', ['is-setup']).strip() == 'true' + + +def is_using_ecc(): + """Return whether the service is using RSA.""" + if os.path.exists(SERVER_CONFIGURATION_FILE): + with open(SERVER_CONFIGURATION_FILE, 'r') as file_handle: + for line in file_handle: + if line.strip() == 'dh none': + return True + return False diff --git a/plinth/modules/openvpn/tests/test_configuration.py b/plinth/modules/openvpn/tests/test_configuration.py new file mode 100644 index 000000000..fdeed6185 --- /dev/null +++ b/plinth/modules/openvpn/tests/test_configuration.py @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +""" +Test module for OpenVPN configuration. +""" + +from unittest.mock import patch + +import pytest + +from plinth.modules import openvpn + + +@pytest.fixture(name='conf_file') +def fixture_conf_file(tmp_path): + """Fixture that returns an empty configuration file.""" + return str(tmp_path / 'freedombox.conf') + + +def test_identify_rsa_configuration(conf_file): + """Identify RSA configuration based on configuration file.""" + with patch('plinth.modules.openvpn.SERVER_CONFIGURATION_FILE', conf_file): + with open(conf_file, 'w') as file_handle: + file_handle.write('dh /etc/openvpn/freedombox-keys/pki/dh.pem') + assert not openvpn.is_using_ecc() + + +def test_identify_ecc_configuration(conf_file): + """Identify ECC configuration based on configuration file.""" + with patch('plinth.modules.openvpn.SERVER_CONFIGURATION_FILE', conf_file): + with open(conf_file, 'w') as file_handle: + file_handle.write('dh none') + assert openvpn.is_using_ecc()