mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
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:
parent
de6030b46c
commit
eecd4b4d5f
@ -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
|
||||
|
||||
32
plinth/modules/openvpn/tests/test_configuration.py
Normal file
32
plinth/modules/openvpn/tests/test_configuration.py
Normal 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()
|
||||
Loading…
x
Reference in New Issue
Block a user