mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-27 14:30:19 +00:00
Merge remote-tracking branch 'origin/master' into 3962.pre-determined-rsa-keys
This commit is contained in:
commit
01b14fe05c
0
newsfragments/3914.minor
Normal file
0
newsfragments/3914.minor
Normal file
0
newsfragments/3953.minor
Normal file
0
newsfragments/3953.minor
Normal file
@ -15,6 +15,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing_extensions import TypeAlias
|
from typing_extensions import TypeAlias
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from cryptography.exceptions import InvalidSignature
|
from cryptography.exceptions import InvalidSignature
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
@ -68,20 +70,39 @@ def create_signing_keypair_from_string(private_key_der: bytes) -> tuple[PrivateK
|
|||||||
|
|
||||||
:returns: 2-tuple of (private_key, public_key)
|
:returns: 2-tuple of (private_key, public_key)
|
||||||
"""
|
"""
|
||||||
priv_key = load_der_private_key(
|
load = partial(
|
||||||
|
load_der_private_key,
|
||||||
private_key_der,
|
private_key_der,
|
||||||
password=None,
|
password=None,
|
||||||
backend=default_backend(),
|
backend=default_backend(),
|
||||||
)
|
)
|
||||||
if not isinstance(priv_key, rsa.RSAPrivateKey):
|
|
||||||
|
try:
|
||||||
|
# Load it once without the potentially expensive OpenSSL validation
|
||||||
|
# checks. These have superlinear complexity. We *will* run them just
|
||||||
|
# below - but first we'll apply our own constant-time checks.
|
||||||
|
unsafe_priv_key = load(unsafe_skip_rsa_key_validation=True)
|
||||||
|
except TypeError:
|
||||||
|
# cryptography<39 does not support this parameter, so just load the
|
||||||
|
# key with validation...
|
||||||
|
unsafe_priv_key = load()
|
||||||
|
# But avoid *reloading* it since that will run the expensive
|
||||||
|
# validation *again*.
|
||||||
|
load = lambda: unsafe_priv_key
|
||||||
|
|
||||||
|
if not isinstance(unsafe_priv_key, rsa.RSAPrivateKey):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Private Key did not decode to an RSA key"
|
"Private Key did not decode to an RSA key"
|
||||||
)
|
)
|
||||||
if priv_key.key_size != 2048:
|
if unsafe_priv_key.key_size != 2048:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Private Key must be 2048 bits"
|
"Private Key must be 2048 bits"
|
||||||
)
|
)
|
||||||
return priv_key, priv_key.public_key()
|
|
||||||
|
# Now re-load it with OpenSSL's validation applied.
|
||||||
|
safe_priv_key = load()
|
||||||
|
|
||||||
|
return safe_priv_key, safe_priv_key.public_key()
|
||||||
|
|
||||||
|
|
||||||
def der_string_from_signing_key(private_key: PrivateKey) -> bytes:
|
def der_string_from_signing_key(private_key: PrivateKey) -> bytes:
|
||||||
|
2
tox.ini
2
tox.ini
@ -7,7 +7,7 @@
|
|||||||
# the tox-gh-actions package.
|
# the tox-gh-actions package.
|
||||||
[gh-actions]
|
[gh-actions]
|
||||||
python =
|
python =
|
||||||
3.7: py37-coverage,typechecks,codechecks
|
3.7: py37-coverage
|
||||||
3.8: py38-coverage
|
3.8: py38-coverage
|
||||||
3.9: py39-coverage
|
3.9: py39-coverage
|
||||||
3.10: py310-coverage
|
3.10: py310-coverage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user