Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit a109b6f

Browse files
committed
Merge pull request #13 from maruel/pythonrsa
Make adb_debug.py able to use python-rsa if M2Crypto is unavailable.
2 parents 1d4b6ca + 9de0f2b commit a109b6f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

adb/adb_debug.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@
2424

2525
import adb_commands
2626
import common_cli
27-
import sign_m2crypto
27+
28+
try:
29+
import sign_m2crypto
30+
except ImportError:
31+
sign_m2crypto = None
32+
try:
33+
import sign_pythonrsa
34+
except ImportError:
35+
sign_pythonrsa = None
36+
2837

2938
gflags.ADOPT_module_key_flags(common_cli)
3039

@@ -38,8 +47,14 @@
3847

3948
def GetRSAKwargs():
4049
if FLAGS.rsa_key_path:
50+
if not sign_m2crypto and not sign_pythonrsa:
51+
print >> sys.stderr, 'Please install either M2Crypto or python-rsa'
52+
sys.exit(1)
53+
signer = (
54+
sign_m2crypto.M2CryptoSigner if sign_m2crypto
55+
else sign_pythonrsa.PythonRSASigner)
4156
return {
42-
'rsa_keys': [sign_m2crypto.M2CryptoSigner(os.path.expanduser(path))
57+
'rsa_keys': [signer(os.path.expanduser(path))
4358
for path in FLAGS.rsa_key_path],
4459
'auth_timeout_ms': int(FLAGS.auth_timeout_s * 1000.0),
4560
}

adb/fastboot_debug.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python
12
# Copyright 2014 Google Inc. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");

adb/sign_pythonrsa.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ def _load_rsa_private_key(pem):
5353

5454
class PythonRSASigner(object):
5555
"""Implements adb_protocol.AuthSigner using http://stuvel.eu/rsa."""
56-
def __init__(self, pub, priv):
56+
def __init__(self, rsa_key_path=None, pub=None, priv=None):
57+
if rsa_key_path:
58+
with open(rsa_key_path + '.pub') as f:
59+
pub = f.read()
60+
with open(rsa_key_path) as f:
61+
priv = f.read()
5762
self.priv_key = _load_rsa_private_key(priv)
5863
self.pub_key = pub
5964

0 commit comments

Comments
 (0)