through error when fediverse server is configured but crypto is missing

This commit is contained in:
jesopo 2019-09-18 10:18:49 +01:00
parent 6e0bc62eea
commit ea1698499f
2 changed files with 12 additions and 5 deletions

View file

@ -1,6 +1,6 @@
import urllib.parse
from src import IRCBot, ModuleManager, utils
from . import ap_actor, ap_server, ap_utils
from . import ap_actor, ap_security, ap_server, ap_utils
def _format_username(username, instance):
return "@%s@%s" % (username, instance)
@ -25,6 +25,9 @@ class Module(ModuleManager.BaseModule):
raise ValueError("`tls-key` not provided in bot config")
if not "tls-certificate" in self.bot.config:
raise ValueError("`tls-certificate` not provided in bot config")
if not ap_security.has_crypto:
raise ValueError("cyprography library is not installed "
"(https://pypi.org/project/cryptography/)")
server_username, instance = ap_utils.split_username(server_username)
self.server = ap_server.Server(self.bot, self.exports,

View file

@ -1,12 +1,16 @@
import base64, typing
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding, rsa
from cryptography.hazmat.backends import default_backend
try:
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding, rsa
from cryptography.hazmat.backends import default_backend
has_crypto = True
except ModuleNotFoundError:
has_crypto = False
SIGNATURE_FORMAT = (
"keyId=\"%s\",headers=\"%s\",signature=\"%s\",algorithm=\"rsa-sha256\"")
def _private_key(key_filename: str) -> rsa.RSAPrivateKey:
with open(key_filename, "rb") as key_file:
return serialization.load_pem_private_key(