|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -from M2Crypto import RSA |
16 | | - |
17 | 15 | from adb import adb_protocol |
18 | 16 |
|
| 17 | +from cryptography.hazmat.backends import default_backend |
| 18 | +from cryptography.hazmat.primitives import hashes |
| 19 | +from cryptography.hazmat.primitives import serialization |
| 20 | +from cryptography.hazmat.primitives.asymmetric import padding |
| 21 | +from cryptography.hazmat.primitives.asymmetric import utils |
| 22 | + |
19 | 23 |
|
20 | | -class M2CryptoSigner(adb_protocol.AuthSigner): |
21 | | - """AuthSigner using M2Crypto.""" |
| 24 | +class CryptographySigner(adb_protocol.AuthSigner): |
| 25 | + """AuthSigner using cryptography.io.""" |
22 | 26 |
|
23 | 27 | def __init__(self, rsa_key_path): |
24 | 28 | with open(rsa_key_path + '.pub') as rsa_pub_file: |
25 | 29 | self.public_key = rsa_pub_file.read() |
26 | 30 |
|
27 | | - self.rsa_key = RSA.load_key(rsa_key_path) |
| 31 | + with open(rsa_key_path) as rsa_prv_file: |
| 32 | + self.rsa_key = serialization.load_pem_private_key( |
| 33 | + rsa_prv_file.read(), None, default_backend()) |
28 | 34 |
|
29 | 35 | def Sign(self, data): |
30 | | - return self.rsa_key.sign(data, 'sha1') |
31 | | - |
32 | | - def GetPublicKey(self): |
33 | | - return self.public_key |
| 36 | + return self.rsa_key.sign( |
| 37 | + data, padding.PKCS1v15(), utils.Prehashed(hashes.SHA1())) |
0 commit comments