Skip to content

Commit

Permalink
Merge pull request #148 from TheOneAboveAllTitan/issues/147
Browse files Browse the repository at this point in the history
[x509] Added dedicated file mode for generated x509 certificates #147
  • Loading branch information
nemesifier authored Mar 28, 2020
2 parents 75a77ef + 10e4e8d commit 4e7bd81
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions netjsonconfig/backends/openvpn/openvpn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ...schema import DEFAULT_FILE_MODE
from ...schema import X509_FILE_MODE
from ..base.backend import BaseBackend
from . import converters
from .parser import OpenVpnParser, config_suffix, vpn_pattern
Expand Down Expand Up @@ -121,15 +121,15 @@ def _auto_client_files(cls, client, ca_path=None, ca_contents=None, cert_path=No
client['ca'] = ca_path
files.append(dict(path=ca_path,
contents=ca_contents,
mode=DEFAULT_FILE_MODE))
mode=X509_FILE_MODE))
if cert_path and cert_contents:
client['cert'] = cert_path
files.append(dict(path=cert_path,
contents=cert_contents,
mode=DEFAULT_FILE_MODE))
mode=X509_FILE_MODE))
if key_path and key_contents:
client['key'] = key_path
files.append(dict(path=key_path,
contents=key_contents,
mode=DEFAULT_FILE_MODE,))
mode=X509_FILE_MODE,))
return files
1 change: 1 addition & 0 deletions netjsonconfig/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .countries import countries

DEFAULT_FILE_MODE = '0644'
X509_FILE_MODE = '0600'
MAC_PATTERN = '([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})'
MAC_PATTERN_BLANK = '^({0}|)$'.format(MAC_PATTERN)

Expand Down
6 changes: 3 additions & 3 deletions tests/openvpn/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,17 +586,17 @@ def test_auto_client_complex(self):
# ---------- files ---------- #
# path: {{ca_path_1}}
# mode: 0644
# mode: 0600
{{ca_contents_1}}
# path: {{cert_path_1}}
# mode: 0644
# mode: 0600
{{cert_contents_1}}
# path: {{key_path_1}}
# mode: 0644
# mode: 0600
{{key_contents_1}}
Expand Down
4 changes: 2 additions & 2 deletions tests/openwisp/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ class TestBackend(unittest.TestCase, _TabsMixin):
"files": [
{
"path": "/openvpn/x509/ca_1_service.pem",
"mode": "0644",
"mode": "0600",
"contents": "-----BEGIN CERTIFICATE-----\ntest\n-----END CERTIFICATE-----\n" # noqa
},
{
"path": "/openvpn/x509/l2vpn_client_2693.pem",
"mode": "0644",
"mode": "0600",
"contents": "-----BEGIN CERTIFICATE-----\ntest==\n-----END CERTIFICATE-----\n-----BEGIN RSA PRIVATE KEY-----\ntest\n-----END RSA PRIVATE KEY-----\n" # noqa
}
]
Expand Down

0 comments on commit 4e7bd81

Please sign in to comment.