openvpn: Function to detect ECC/RSA configuration

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati 2020-10-30 16:05:39 +05:30 committed by James Valleroy
parent de6030b46c
commit eecd4b4d5f
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 46 additions and 0 deletions

View File

@ -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

View File

@ -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()