Commit 7924fd45 authored by mar-ar's avatar mar-ar Committed by oroulet

enabled to use pem format without ending .pem

parent a9397ca8
......@@ -12,10 +12,10 @@ from cryptography.hazmat.primitives.ciphers import algorithms
from cryptography.hazmat.primitives.ciphers import modes
async def load_certificate(path):
async def load_certificate(path, format=None):
_, ext = os.path.splitext(path)
async with aiofiles.open(path, mode='rb') as f:
if ext == ".pem":
if ext == ".pem" or format == 'pem' or format == 'PEM':
return x509.load_pem_x509_certificate(await f.read(), default_backend())
else:
return x509.load_der_x509_certificate(await f.read(), default_backend())
......@@ -27,10 +27,10 @@ def x509_from_der(data):
return x509.load_der_x509_certificate(data, default_backend())
async def load_private_key(path):
async def load_private_key(path, format=None):
_, ext = os.path.splitext(path)
async with aiofiles.open(path, mode='rb') as f:
if ext == ".pem":
if ext == ".pem" or format == 'pem' or format == 'PEM':
return serialization.load_pem_private_key(await f.read(), password=None, backend=default_backend())
else:
return serialization.load_der_private_key(await f.read(), password=None, backend=default_backend())
......
......@@ -125,14 +125,14 @@ class Server:
return f"OPC UA Server({self.endpoint.geturl()})"
__repr__ = __str__
async def load_certificate(self, path: str):
async def load_certificate(self, path: str, format: str =None):
"""
load server certificate from file, either pem or der
"""
self.certificate = await uacrypto.load_certificate(path)
self.certificate = await uacrypto.load_certificate(path, format)
async def load_private_key(self, path):
self.iserver.private_key = await uacrypto.load_private_key(path)
async def load_private_key(self, path, format=None):
self.iserver.private_key = await uacrypto.load_private_key(path, format)
def disable_clock(self, val: bool = True):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment