From a3a01be8cef5aa7f023834d3d45eafb1426bb038 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sun, 9 Aug 2015 19:00:15 +0300 Subject: [PATCH 1/3] remove unused code --- gui/qt/main_window.py | 13 --------- lib/x509.py | 65 ------------------------------------------- 2 files changed, 78 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index df85a19d5..85223d9ae 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -2915,16 +2915,3 @@ class ElectrumWindow(QMainWindow): text.setText(mpk_text) vbox.addLayout(Buttons(CloseButton(d))) d.exec_() - - @protected - def create_csr(self, alias, challenge, password): - from electrum import x509 - import tlslite - xprv = self.wallet.get_master_private_key(self.wallet.root_name, password) - _, _, _, c, k = bitcoin.deserialize_xkey(xprv) - csr = x509.create_csr(alias, challenge, k) - csr = tlslite.utils.pem.pem(bytearray(csr), "CERTIFICATE REQUEST") - with open('test.csr', 'w') as f: - f.write(csr) - #os.system('openssl asn1parse -i -in test.csr') - return 'test.csr' diff --git a/lib/x509.py b/lib/x509.py index 3f722a166..11716022e 100644 --- a/lib/x509.py +++ b/lib/x509.py @@ -190,68 +190,3 @@ def load_certificates(ca_path): ca_keyID[x.get_keyID()] = fp return ca_list, ca_keyID - - -def int_to_bytestr(i): - s = chr(i % 256) - while i > 256: - i >>= 8 - s = chr(i % 256) + s - return s - -def create_csr(commonName, challenge, k): - from bitcoin import point_to_ser - private_key = ecdsa.SigningKey.from_string(k, curve = ecdsa.SECP256k1) - public_key = private_key.get_verifying_key() - pubkey = point_to_ser(public_key.pubkey.point, False) - asn1_type_table = { - 'BOOLEAN': 0x01, 'INTEGER': 0x02, - 'BIT STRING': 0x03, 'OCTET STRING': 0x04, - 'NULL': 0x05, 'OBJECT IDENTIFIER': 0x06, - 'SEQUENCE': 0x30, 'SET': 0x31, - 'PrintableString': 0x13, 'IA5String': 0x16, - 'UTCTime': 0x17, 'ENUMERATED': 0x0A, - 'UTF8String': 0x0C, 'PrintableString': 0x13, - } - def x(t, s): - c = asn1_type_table[t] & 0x3f if type(t) == str else t - l = len(s) - if l < 128: - ls = chr(l) - else: - n = int_to_bytestr(l) - ls = chr(len(n) + 128) + n - return chr(c) + ls + s - x_int = lambda i: x('INTEGER', int_to_bytestr(i)) - x_seq = lambda *items: x('SEQUENCE', ''.join(items)) - x_bitstring = lambda s: x('BIT STRING', s) - x_utf8 = lambda s: x('UTF8String', s) - x_set = lambda *items: x('SET', ''.join(items)) - x_printable = lambda s: x('PrintableString', s) - x_obj = lambda oid: x('OBJECT IDENTIFIER', encode_OID(oid)) - body = x_seq( - x_int(0), - x_seq( - x_set(x_seq(x_obj('2.5.4.3'), x_utf8(commonName))) - ), - x_seq( - x_seq( - x_obj('1.2.840.10045.2.1'), - x_obj('1.3.132.0.10') - ), - x_bitstring(chr(0) + pubkey) - ), - x(0xa0, x_seq(x_obj('1.2.840.113549.1.9.7'), x_set(x_utf8(challenge))) - ) - ) - signature = private_key.sign_deterministic(body, hashfunc=hashlib.sha256, sigencode = ecdsa.util.sigencode_der) - assert public_key.verify(signature, body, hashfunc=hashlib.sha256, sigdecode = ecdsa.util.sigdecode_der) - csr = x_seq( - body, - x_seq(x_obj(ALGO_ECDSA_SHA256)), - x_bitstring(chr(0) + signature) - ) - return csr - - - From b5854b6e8ba638a338603f9740387a8afb990684 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sun, 9 Aug 2015 19:22:26 +0300 Subject: [PATCH 2/3] account: remove unused variables --- lib/account.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/account.py b/lib/account.py index a50d3f037..705052b5b 100644 --- a/lib/account.py +++ b/lib/account.py @@ -187,7 +187,6 @@ class OldAccount(Account): @classmethod def mpk_from_seed(klass, seed): - curve = SECP256k1 secexp = klass.stretch_key(seed) master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 ) master_public_key = master_private_key.get_verifying_key().to_string().encode('hex') @@ -211,7 +210,6 @@ class OldAccount(Account): @classmethod def get_pubkey_from_mpk(self, mpk, for_change, n): - curve = SECP256k1 z = self.get_sequence(mpk, for_change, n) master_public_key = ecdsa.VerifyingKey.from_string( mpk, curve = SECP256k1 ) pubkey_point = master_public_key.pubkey.point + z*curve.generator @@ -239,7 +237,6 @@ class OldAccount(Account): def check_seed(self, seed): - curve = SECP256k1 secexp = self.stretch_key(seed) master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 ) master_public_key = master_private_key.get_verifying_key().to_string() From abc7429b0ffc6d3fdadbf78cc6272891a8e5e1e9 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sun, 9 Aug 2015 19:27:26 +0300 Subject: [PATCH 3/3] bitcoin: remove multiple imports --- lib/bitcoin.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 96b61b429..5e3f6723c 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -604,8 +604,6 @@ def CKD_priv(k, c, n): return _CKD_priv(k, c, rev_hex(int_to_hex(n,4)).decode('hex'), is_prime) def _CKD_priv(k, c, s, is_prime): - import hmac - from ecdsa.util import string_to_number, number_to_string order = generator_secp256k1.order() keypair = EC_KEY(k) cK = GetPubKey(keypair.pubkey,True) @@ -627,8 +625,6 @@ def CKD_pub(cK, c, n): # helper function, callable with arbitrary string def _CKD_pub(cK, c, s): - import hmac - from ecdsa.util import string_to_number, number_to_string order = generator_secp256k1.order() I = hmac.new(c, cK + s, hashlib.sha512).digest() curve = SECP256k1 @@ -706,7 +702,6 @@ def xpub_from_xprv(xprv, testnet=False): def bip32_root(seed, testnet=False): - import hmac header_pub, header_priv = _get_headers(testnet) I = hmac.new("Bitcoin seed", seed, hashlib.sha512).digest() master_k = I[0:32]