through error when fediverse server is configured but crypto is missing
This commit is contained in:
parent
6e0bc62eea
commit
ea1698499f
2 changed files with 12 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from src import IRCBot, ModuleManager, utils
|
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):
|
def _format_username(username, instance):
|
||||||
return "@%s@%s" % (username, instance)
|
return "@%s@%s" % (username, instance)
|
||||||
|
@ -25,6 +25,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
raise ValueError("`tls-key` not provided in bot config")
|
raise ValueError("`tls-key` not provided in bot config")
|
||||||
if not "tls-certificate" in self.bot.config:
|
if not "tls-certificate" in self.bot.config:
|
||||||
raise ValueError("`tls-certificate` not provided in 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)
|
server_username, instance = ap_utils.split_username(server_username)
|
||||||
self.server = ap_server.Server(self.bot, self.exports,
|
self.server = ap_server.Server(self.bot, self.exports,
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
import base64, typing
|
import base64, typing
|
||||||
from cryptography.hazmat.primitives import hashes, serialization
|
|
||||||
from cryptography.hazmat.primitives.asymmetric import padding, rsa
|
try:
|
||||||
from cryptography.hazmat.backends import default_backend
|
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 = (
|
SIGNATURE_FORMAT = (
|
||||||
"keyId=\"%s\",headers=\"%s\",signature=\"%s\",algorithm=\"rsa-sha256\"")
|
"keyId=\"%s\",headers=\"%s\",signature=\"%s\",algorithm=\"rsa-sha256\"")
|
||||||
|
|
||||||
|
|
||||||
def _private_key(key_filename: str) -> rsa.RSAPrivateKey:
|
def _private_key(key_filename: str) -> rsa.RSAPrivateKey:
|
||||||
with open(key_filename, "rb") as key_file:
|
with open(key_filename, "rb") as key_file:
|
||||||
return serialization.load_pem_private_key(
|
return serialization.load_pem_private_key(
|
||||||
|
|
Loading…
Reference in a new issue