diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 239764eb3..4ec2968ff 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -2742,3 +2742,16 @@ 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 fb63abbbd..d642f9d87 100644 --- a/lib/x509.py +++ b/lib/x509.py @@ -237,11 +237,10 @@ def int_to_bytestr(i): s = chr(i % 256) + s return s -def create_csr(commonName, challenge, secexp): - +def create_csr(commonName, challenge, k): import ecdsa, hashlib from bitcoin import point_to_ser - private_key = ecdsa.SigningKey.from_secret_exponent(secexp, curve = ecdsa.SECP256k1) + 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 = { @@ -295,10 +294,3 @@ def create_csr(commonName, challenge, secexp): -if __name__ == "__main__": - import os - csr = create_csr('test@electrum.org', 'blah', 123456) - with open('test.csr', 'w') as f: - o = tlslite.utils.pem.pem(bytearray(csr), "CERTIFICATE REQUEST") - f.write(o) - os.system('openssl asn1parse -i -in test.csr')