From 6c5c202b3f1b03ba05b8da2af94b557b9e6ebfb6 Mon Sep 17 00:00:00 2001 From: jackeyji Date: Fri, 1 Mar 2024 16:06:41 +0800 Subject: [PATCH] fix _MyRSAPrivateNumbers error Signed-off-by: jackeyji --- python-tpm2-pytss-RSAPrivateNumbers.patch | 70 +++++++++++++++++++++++ python-tpm2-pytss.spec | 6 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 python-tpm2-pytss-RSAPrivateNumbers.patch diff --git a/python-tpm2-pytss-RSAPrivateNumbers.patch b/python-tpm2-pytss-RSAPrivateNumbers.patch new file mode 100644 index 0000000..0b78b06 --- /dev/null +++ b/python-tpm2-pytss-RSAPrivateNumbers.patch @@ -0,0 +1,70 @@ +From 0fbb9d099370c0a7031dd13990986538f586836a Mon Sep 17 00:00:00 2001 +From: Erik Larsson +Date: Fri, 26 Jan 2024 12:01:41 +0100 +Subject: [PATCH] internal/crypto: fix _MyRSAPrivateNumbers with cryptograpy >= + 42.0.1 + +RSAPrivateNumbers was moved to a rust implementation in 42.0.1. +So inheritance is no longer possible, so turn the class into a +wrapper instead of a subclass. + +Fixes #561 + +Signed-off-by: Erik Larsson +--- + src/tpm2_pytss/internal/crypto.py | 21 +++++++++------------ + 1 file changed, 9 insertions(+), 12 deletions(-) + +diff --git a/src/tpm2_pytss/internal/crypto.py b/src/tpm2_pytss/internal/crypto.py +index 93e51813..42030c56 100644 +--- a/src/tpm2_pytss/internal/crypto.py ++++ b/src/tpm2_pytss/internal/crypto.py +@@ -23,7 +23,7 @@ + from cryptography.hazmat.primitives.ciphers import modes, Cipher, CipherAlgorithm + from cryptography.hazmat.backends import default_backend + from cryptography.exceptions import UnsupportedAlgorithm, InvalidSignature +-from typing import Tuple, Type ++from typing import Tuple, Type, Any + import secrets + import sys + +@@ -220,7 +220,7 @@ def public_to_key(obj): + return key + + +-class _MyRSAPrivateNumbers(rsa.RSAPrivateNumbers): ++class _MyRSAPrivateNumbers: + def __init__(self, p: int, n: int, e: int, pubnums: rsa.RSAPublicNumbers): + + q = n // p +@@ -231,7 +231,12 @@ def __init__(self, p: int, n: int, e: int, pubnums: rsa.RSAPublicNumbers): + dmq1 = rsa.rsa_crt_dmq1(d, q) + iqmp = rsa.rsa_crt_iqmp(p, q) + +- super().__init__(p, q, d, dmp1, dmq1, iqmp, pubnums) ++ self._private_numbers = rsa.RSAPrivateNumbers( ++ p, q, d, dmp1, dmq1, iqmp, pubnums ++ ) ++ ++ def private_key(self, *args: Any, **kwargs: Any) -> rsa.RSAPrivateKey: ++ return self._private_numbers.private_key(*args, **kwargs) + + @staticmethod + def _xgcd(a: int, b: int) -> Tuple[int, int, int]: +@@ -251,15 +256,7 @@ def _xgcd(a: int, b: int) -> Tuple[int, int, int]: + # + @staticmethod + def _modinv(a, m): +- +- if sys.version_info < (3, 8): +- g, x, y = _MyRSAPrivateNumbers._xgcd(a, m) +- if g != 1: +- raise Exception("modular inverse does not exist") +- else: +- return x % m +- else: +- return pow(a, -1, m) ++ return pow(a, -1, m) + + @staticmethod + def _generate_d(p, q, e, n): diff --git a/python-tpm2-pytss.spec b/python-tpm2-pytss.spec index dba0595..ac71a8c 100644 --- a/python-tpm2-pytss.spec +++ b/python-tpm2-pytss.spec @@ -6,11 +6,12 @@ Summary: TPM 2.0 TSS Bindings for Python Name: python-%{srcname} Version: 2.1.0 -Release: 1%{?dist} +Release: 2%{?dist} License: BSD-2-Clause URL: https://github.com/tpm2-software/tpm2-pytss Source: %{pypi_source %{srcname}} +Patch0001: python-tpm2-pytss-RSAPrivateNumbers.patch Patch3001: python-tpm2-pytss-1.2.0-openssl.patch BuildRequires: python3-devel python3-pytest python3-pytest-xdist tpm2-tss-devel gcc @@ -62,6 +63,9 @@ based command line strings and loading tpm2-tools context files. %doc README.md %changelog +* Fri Mar 01 2024 jackeyji - 2.1.0-2 +- fix _MyRSAPrivateNumbers error + * Mon Sep 25 2023 Shuo Wang - 2.1.0-1 - update to 2.1.0 -- Gitee