From b41444e8d659ac16fe5082f3ffee33174c0395b4 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Fri, 1 Mar 2013 17:44:52 -0500 Subject: [PATCH 1/2] Comment out RSA code --- addresses.py | 59 ++++++++++++++++++----------------------------- bitmessagemain.py | 31 +++++++++++++------------ 2 files changed, 39 insertions(+), 51 deletions(-) diff --git a/addresses.py b/addresses.py index ce7aa4ff..b29748aa 100644 --- a/addresses.py +++ b/addresses.py @@ -1,6 +1,6 @@ -import rsa import hashlib from struct import * +from pyelliptic import arithmetic #There is another copy of this function in Bitmessagemain.py def convertIntToString(n): @@ -245,50 +245,37 @@ def addressStream(address): if __name__ == "__main__": - #Let's make a new Bitmessage address: - (pubkey, privkey) = rsa.newkeys(256) - print privkey['n'] - print privkey['e'] - print privkey['d'] - print privkey['p'] - print privkey['q'] + print 'Let us make an address from scratch. Suppose we generate two random 32 byte values and call the first one the signing key and the second one the encryption key:' + privateSigningKey = '93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665' + privateEncryptionKey = '4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a' + print 'privateSigningKey =', privateSigningKey + print 'privateEncryptionKey =', privateEncryptionKey + print 'Now let us convert them to public keys by doing an elliptic curve point multiplication.' + publicSigningKey = arithmetic.privtopub(privateSigningKey) + publicEncryptionKey = arithmetic.privtopub(privateEncryptionKey) + print 'publicSigningKey =', publicSigningKey + print 'publicEncryptionKey =', publicEncryptionKey + + print 'Notice that they both begin with the \\x04 which specifies the encoding type. This prefix is not send over the wire. You must strip if off before you send your public key across the wire, and you must add it back when you receive a public key.' + + publicSigningKeyBinary = arithmetic.changebase(publicSigningKey,16,256,minlen=64) + publicEncryptionKeyBinary = arithmetic.changebase(publicEncryptionKey,16,256,minlen=64) ripe = hashlib.new('ripemd160') sha = hashlib.new('sha512') - sha.update(convertIntToString(pubkey.n)+convertIntToString(pubkey.e)) + sha.update(publicSigningKeyBinary+publicEncryptionKeyBinary) ripe.update(sha.digest()) - #print 'sha digest:', sha.digest() - #print 'ripe digest:', ripe.digest() - #print len(sha.digest()) - #print len(ripe.digest()) - - #prepend the version number and stream number - a = '\x01' + '\x08' + ripe.digest() - #print 'lengh of a at beginning = ', len(a) - print 'This is the data to be encoded in the address: ', a.encode('hex') - - returnedAddress = encodeAddress(1,8,ripe.digest()) + addressVersionNumber = 2 + streamNumber = 1 + print 'Ripe digest that we will encode in the address:', ripe.digest().encode('hex') + returnedAddress = encodeAddress(addressVersionNumber,streamNumber,ripe.digest()) + print 'Encoded address:', returnedAddress status,addressVersionNumber,streamNumber,data = decodeAddress(returnedAddress) - print returnedAddress + print '\nAfter decoding address:' print 'Status:', status print 'addressVersionNumber', addressVersionNumber print 'streamNumber', streamNumber print 'length of data(the ripe hash):', len(data) print 'ripe data:', data.encode('hex') - print '\n\nNow let us try making an address with given 2048-bit n and e values.' - testn = 16691381808213609635656612695328489234826227577985206736118595570304213887605602327717776979169783795560145663031146864154748634207927153095849203939039346778471192284119479329875655789428795925773927040539038073349089996911318012189546542694411685389074592231210678771416758973061752125295462189928432307067746658691146428088703129795340914596189054255127032271420140641112277113597275245807890920656563056790943850440012709593297328230145129809419550219898595770524436575484115680960823105256137731976622290028349172297572826751147335728017861413787053794003722218722212196385625462088929496952843002425059308041193 - teste = 65537 - ripe = hashlib.new('ripemd160') - sha = hashlib.new('sha512') - sha.update(convertIntToString(testn)+convertIntToString(teste)) - ripe.update(sha.digest()) - encodedAddress = encodeAddress(1,1,ripe.digest()) - print encodedAddress - status,addressVersionNumber,streamNumber,data = decodeAddress(encodedAddress) - print 'Status:', status - print 'addressVersionNumber', addressVersionNumber - print 'streamNumber', streamNumber - print 'length of data(the ripe hash):', len(data) - diff --git a/bitmessagemain.py b/bitmessagemain.py index 72b198b4..46fb0a08 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -40,8 +40,8 @@ from defaultKnownNodes import * import time import socket import threading -import rsa -from rsa.bigfile import * +#import rsa +#from rsa.bigfile import * import hashlib from struct import * import pickle @@ -54,7 +54,6 @@ import os import shutil #used for moving the messages.dat file import string import socks -#import pyelliptic import highlevelcrypto from pyelliptic.openssl import OpenSSL import ctypes @@ -553,7 +552,7 @@ class receiveDataThread(QThread): return readPosition += broadcastVersionLength sendersAddressVersion, sendersAddressVersionLength = decodeVarint(self.data[readPosition:readPosition+9]) - if sendersAddressVersion == 0 or sendersAddressVersion >=3: + if sendersAddressVersion <= 1 or sendersAddressVersion >=3: #Cannot decode senderAddressVersion higher than 2. Assuming the sender isn\' being silly, you should upgrade Bitmessage because this message shall be ignored. return readPosition += sendersAddressVersionLength @@ -638,7 +637,7 @@ class receiveDataThread(QThread): print 'Time spent processing this interesting broadcast:', time.time()- self.messageProcessingStartTime printLock.release() - elif sendersAddressVersion == 1: + """elif sendersAddressVersion == 1: sendersStream, sendersStreamLength = decodeVarint(self.data[readPosition:readPosition+9]) if sendersStream <= 0: return @@ -716,7 +715,7 @@ class receiveDataThread(QThread): sqlSubmitQueue.put(t) sqlReturnQueue.get() sqlLock.release() - self.emit(SIGNAL("displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),self.inventoryHash,toAddress,fromAddress,subject,body) + self.emit(SIGNAL("displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),self.inventoryHash,toAddress,fromAddress,subject,body)""" #We have received a msg message. @@ -783,7 +782,7 @@ class receiveDataThread(QThread): #This section is for my RSA keys (version 1 addresses). If we don't have any version 1 addresses it will never run. This code will soon be removed. - initialDecryptionSuccessful = False + """initialDecryptionSuccessful = False infile = cStringIO.StringIO(self.data[readPosition:self.payloadLength+24]) outfile = cStringIO.StringIO() #print 'len(myRSAAddressHashes.items()):', len(myRSAAddressHashes.items()) @@ -977,7 +976,7 @@ class receiveDataThread(QThread): print 'Could not decrypt with any RSA keys if you have any.' printLock.release() infile.close() - outfile.close() + outfile.close()""" #A msg message has a valid time and POW and requires processing. The recmsg function calls this one. def processmsg(self,readPosition): @@ -1095,6 +1094,7 @@ class receiveDataThread(QThread): sqlSubmitQueue.put(t) sqlReturnQueue.get() sqlLock.release() + workerQueue.put(('newpubkey',(sendersAddressVersionNumber,sendersStreamNumber,ripe.digest()))) #This will check to see whether we happen to be awaiting this pubkey in order to send a message. If we are, it will do the POW and send it. blockMessage = False #Gets set to True if the user shouldn't see the message according to black or white lists. fromAddress = encodeAddress(sendersAddressVersionNumber,sendersStreamNumber,ripe.digest()) if config.get('bitmessagesettings', 'blackwhitelist') == 'black': #If we are using a blacklist @@ -1306,7 +1306,7 @@ class receiveDataThread(QThread): if addressVersion == 0: print '(Within processpubkey) addressVersion of 0 doesn\'t make sense.' return - if addressVersion >= 3: + if addressVersion >= 3 or addressVersion == 1: printLock.acquire() print 'This version of Bitmessage cannot handle version', addressVersion,'addresses.' printLock.release() @@ -1352,7 +1352,6 @@ class receiveDataThread(QThread): sqlReturnQueue.get() sqlLock.release() printLock.acquire() - print 'added foreign pubkey into our database' printLock.release() workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) else: @@ -1364,12 +1363,11 @@ class receiveDataThread(QThread): sqlReturnQueue.get() sqlLock.release() printLock.acquire() - print 'added foreign pubkey into our database' printLock.release() workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) #This code which deals with old RSA addresses will soon be removed. - elif addressVersion == 1: + """elif addressVersion == 1: nLength, varintLength = decodeVarint(self.data[readPosition:readPosition+10]) readPosition += varintLength nString = self.data[readPosition:readPosition+nLength] @@ -1420,7 +1418,7 @@ class receiveDataThread(QThread): printLock.acquire() print 'added foreign pubkey into our database' printLock.release() - workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) + workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe)))""" #We have received a getpubkey message def recgetpubkey(self): @@ -1461,6 +1459,9 @@ class receiveDataThread(QThread): if addressVersionNumber == 0: print 'The addressVersionNumber of the pubkey request is zero. That doesn\'t make any sense. Ignoring it.' return + elif addressVersionNumber == 1: + print 'The addressVersionNumber of the pubkey request is 1 which isn\'t supported anymore. Ignoring it.' + return elif addressVersionNumber > 2: print 'The addressVersionNumber of the pubkey request is too high. Can\'t understand. Ignoring it.' return @@ -3011,7 +3012,7 @@ class addressGenerator(QThread): reloadMyAddressHashes() #This code which deals with old RSA addresses will soon be removed. - elif self.addressVersionNumber == 1: + """elif self.addressVersionNumber == 1: statusbar = 'Generating new ' + str(config.getint('bitmessagesettings', 'bitstrength')) + ' bit RSA key. This takes a minute on average. If you want to generate multiple addresses now, you can; they will queue.' self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"),statusbar) (pubkey, privkey) = rsa.newkeys(config.getint('bitmessagesettings', 'bitstrength')) @@ -3043,7 +3044,7 @@ class addressGenerator(QThread): self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"),'Done generating address') self.emit(SIGNAL("writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),self.label,address,str(self.streamNumber)) - reloadMyAddressHashes() + reloadMyAddressHashes()""" #Does an EC point multiplication; turns a private key into a public key. def pointMult(self,secret): -- 2.45.1 From 3c4d1e16bc1c96d1bdc8e8fcc85455291669126b Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Sun, 3 Mar 2013 01:54:06 -0500 Subject: [PATCH 2/2] reloadBroadcastSendersForWhichImWatching when deleting item from Subscriptions list --- bitmessagemain.py | 1 + messages.dat reader.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bitmessagemain.py b/bitmessagemain.py index 72b198b4..63024ad7 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -4604,6 +4604,7 @@ class MyForm(QtGui.QMainWindow): sqlLock.release() self.ui.tableWidgetSubscriptions.removeRow(currentRow) self.rerenderInboxFromLabels() + self.reloadBroadcastSendersForWhichImWatching() def on_action_SubscriptionsClipboard(self): currentRow = self.ui.tableWidgetSubscriptions.currentRow() addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(currentRow,1).text() diff --git a/messages.dat reader.py b/messages.dat reader.py index 60c3ddd4..7ca966a6 100644 --- a/messages.dat reader.py +++ b/messages.dat reader.py @@ -92,7 +92,7 @@ def takeSentMessagesOutOfTrash(): #readInbox() #readSent() #readPubkeys() -#readSubscriptions() -readInventory() +readSubscriptions() +#readInventory() -- 2.45.1