Skip to content

Commit e70969f

Browse files
committed
Add an option to disable expensive OpenSSL 3.x RSA private key checks
This commit adds a new unsafe_skip_rsa_key_validation argument to import_private_key(), import_private_key_and_certs(), read_private_key(), read_private_key_and_certs(), read_private_key_list(), and load_keypairs() which can be used to disable somewhat expensive RSA private key validation code in OpenSSL 3.x, reducing the cost back to what it was in earlier OpenSSL versions. Skipping these checks is only recommended when keys being loaded are from a trusted source. A new set_default_skip_rsa_key_validation() function was also added, to set a global default for whether or not to disable this extra key validation.
1 parent 8dba2b1 commit e70969f

File tree

7 files changed

+181
-69
lines changed

7 files changed

+181
-69
lines changed

asyncssh/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
from .public_key import load_keypairs, load_public_keys, load_certificates
8787
from .public_key import load_resident_keys
8888

89+
from .rsa import set_default_skip_rsa_key_validation
90+
8991
from .scp import scp
9092

9193
from .session import DataType, SSHClientSession, SSHServerSession
@@ -164,5 +166,5 @@
164166
'read_certificate_list', 'read_known_hosts', 'read_private_key',
165167
'read_private_key_list', 'read_public_key', 'read_public_key_list',
166168
'run_client', 'run_server', 'scp', 'set_debug_level', 'set_log_level',
167-
'set_sftp_log_level',
169+
'set_sftp_log_level', 'set_default_skip_rsa_key_validation',
168170
]

asyncssh/crypto/rsa.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ class RSAPrivateKey(_RSAKey):
9898

9999
@classmethod
100100
def construct(cls, n: int, e: int, d: int, p: int, q: int,
101-
dmp1: int, dmq1: int, iqmp: int) -> 'RSAPrivateKey':
101+
dmp1: int, dmq1: int, iqmp: int,
102+
skip_validation: bool) -> 'RSAPrivateKey':
102103
"""Construct an RSA private key"""
103104

104105
pub = rsa.RSAPublicNumbers(e, n)
105106
priv = rsa.RSAPrivateNumbers(p, q, d, dmp1, dmq1, iqmp, pub)
106-
priv_key = priv.private_key()
107+
priv_key = priv.private_key(
108+
unsafe_skip_rsa_key_validation=skip_validation)
107109

108110
return cls(priv_key, pub, priv)
109111

0 commit comments

Comments
 (0)