summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJun Omae <jun66j5@gmail.com>2021-11-25 15:21:08 +0900
committerJeff Forcier <jeff@bitprophet.org>2022-05-16 20:47:45 -0400
commitd3f0d01c3eeaef74c0111bd5ade1c66fdfaaa8ec (patch)
tree75c3e2817753cbbb09c0d99fc902aae58b7af2bd
parentdd1a32c428f1f5c9ea15fe97fde9358e695f4afc (diff)
Pad received signature with leading zeros when RSA key is used
-rw-r--r--paramiko/rsakey.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py
index d2dc99e4..1e2d5bfe 100644
--- a/paramiko/rsakey.py
+++ b/paramiko/rsakey.py
@@ -141,9 +141,16 @@ class RSAKey(PKey):
if isinstance(key, rsa.RSAPrivateKey):
key = key.public_key()
+ # NOTE: pad received signature with leading zeros, key.verify()
+ # expects a signature of key size (e.g. PuTTY doesn't pad)
+ sign = msg.get_binary()
+ diff = key.key_size - len(sign) * 8
+ if diff > 0:
+ sign = b"\x00" * ((diff + 7) // 8) + sign
+
try:
key.verify(
- msg.get_binary(),
+ sign,
data,
padding.PKCS1v15(),
self.HASHES[sig_algorithm](),