adb_shell.auth.sign_pythonrsa module

ADB authentication using the rsa package.

Contents

class adb_shell.auth.sign_pythonrsa.PythonRSASigner(pub=None, priv=None)[source]

Bases: object

Implements adb_protocol.AuthSigner using http://stuvel.eu/rsa.

Parameters:
  • pub (str, None) – The contents of the public key file

  • priv (str, None) – The contents of the private key file

priv_key

The loaded private key

Type:

rsa.key.PrivateKey

pub_key

The contents of the public key file

Type:

str, None

classmethod FromRSAKeyPath(rsa_key_path)[source]

Create a PythonRSASigner instance using the provided private key.

Parameters:

rsa_key_path (str) – The path to the private key; the public key must be rsa_key_path + '.pub'.

Returns:

A PythonRSASigner with private key rsa_key_path and public key rsa_key_path + '.pub'

Return type:

PythonRSASigner

GetPublicKey()[source]

Returns the public key in PEM format without headers or newlines.

Returns:

self.pub_key – The contents of the public key file, or None if a public key was not provided.

Return type:

str, None

Sign(data)[source]

Signs given data using a private key.

Parameters:

data (bytes) – The data to be signed

Returns:

The signed data

Return type:

bytes

class adb_shell.auth.sign_pythonrsa._Accum[source]

Bases: object

A fake hashing algorithm.

The Python rsa lib hashes all messages it signs. ADB does it already, we just need to slap a signature on top of already hashed message. Introduce a “fake” hashing algo for this.

_buf

A buffer for storing data before it is signed

Type:

bytes

digest()[source]

Return the digest value as a string of binary data.

Returns:

self._bufself._buf

Return type:

bytes

update(msg)[source]

Update this hash object’s state with the provided msg.

Parameters:

msg (bytes) – The message to be appended to self._buf

adb_shell.auth.sign_pythonrsa._load_rsa_private_key(pem)[source]

PEM encoded PKCS#8 private key -> rsa.PrivateKey.

ADB uses private RSA keys in pkcs#8 format. The rsa library doesn’t support them natively. Do some ASN unwrapping to extract naked RSA key (in der-encoded form).

See:

Parameters:

pem (str) – The private key to be loaded

Returns:

The loaded private key

Return type:

rsa.key.PrivateKey