Merge pull request #58 from Atheros1/master

Comment out old RSA code
This commit is contained in:
Jonathan Warren 2013-03-02 23:14:18 -08:00
commit 7eb9a92a70
3 changed files with 42 additions and 53 deletions

View File

@ -1,6 +1,6 @@
import rsa
import hashlib import hashlib
from struct import * from struct import *
from pyelliptic import arithmetic
#There is another copy of this function in Bitmessagemain.py #There is another copy of this function in Bitmessagemain.py
def convertIntToString(n): def convertIntToString(n):
@ -245,50 +245,37 @@ def addressStream(address):
if __name__ == "__main__": if __name__ == "__main__":
#Let's make a new Bitmessage address: 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:'
(pubkey, privkey) = rsa.newkeys(256) privateSigningKey = '93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
print privkey['n'] privateEncryptionKey = '4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
print privkey['e'] print 'privateSigningKey =', privateSigningKey
print privkey['d'] print 'privateEncryptionKey =', privateEncryptionKey
print privkey['p'] print 'Now let us convert them to public keys by doing an elliptic curve point multiplication.'
print privkey['q'] 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') ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha512') sha = hashlib.new('sha512')
sha.update(convertIntToString(pubkey.n)+convertIntToString(pubkey.e)) sha.update(publicSigningKeyBinary+publicEncryptionKeyBinary)
ripe.update(sha.digest()) ripe.update(sha.digest())
#print 'sha digest:', sha.digest() addressVersionNumber = 2
#print 'ripe digest:', ripe.digest() streamNumber = 1
#print len(sha.digest()) print 'Ripe digest that we will encode in the address:', ripe.digest().encode('hex')
#print len(ripe.digest()) returnedAddress = encodeAddress(addressVersionNumber,streamNumber,ripe.digest())
print 'Encoded address:', returnedAddress
#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())
status,addressVersionNumber,streamNumber,data = decodeAddress(returnedAddress) status,addressVersionNumber,streamNumber,data = decodeAddress(returnedAddress)
print returnedAddress print '\nAfter decoding address:'
print 'Status:', status print 'Status:', status
print 'addressVersionNumber', addressVersionNumber print 'addressVersionNumber', addressVersionNumber
print 'streamNumber', streamNumber print 'streamNumber', streamNumber
print 'length of data(the ripe hash):', len(data) print 'length of data(the ripe hash):', len(data)
print 'ripe data:', data.encode('hex') 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)

View File

@ -40,8 +40,8 @@ from defaultKnownNodes import *
import time import time
import socket import socket
import threading import threading
import rsa #import rsa
from rsa.bigfile import * #from rsa.bigfile import *
import hashlib import hashlib
from struct import * from struct import *
import pickle import pickle
@ -54,7 +54,6 @@ import os
import shutil #used for moving the messages.dat file import shutil #used for moving the messages.dat file
import string import string
import socks import socks
#import pyelliptic
import highlevelcrypto import highlevelcrypto
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
import ctypes import ctypes
@ -553,7 +552,7 @@ class receiveDataThread(QThread):
return return
readPosition += broadcastVersionLength readPosition += broadcastVersionLength
sendersAddressVersion, sendersAddressVersionLength = decodeVarint(self.data[readPosition:readPosition+9]) 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. #Cannot decode senderAddressVersion higher than 2. Assuming the sender isn\' being silly, you should upgrade Bitmessage because this message shall be ignored.
return return
readPosition += sendersAddressVersionLength readPosition += sendersAddressVersionLength
@ -638,7 +637,7 @@ class receiveDataThread(QThread):
print 'Time spent processing this interesting broadcast:', time.time()- self.messageProcessingStartTime print 'Time spent processing this interesting broadcast:', time.time()- self.messageProcessingStartTime
printLock.release() printLock.release()
elif sendersAddressVersion == 1: """elif sendersAddressVersion == 1:
sendersStream, sendersStreamLength = decodeVarint(self.data[readPosition:readPosition+9]) sendersStream, sendersStreamLength = decodeVarint(self.data[readPosition:readPosition+9])
if sendersStream <= 0: if sendersStream <= 0:
return return
@ -716,7 +715,7 @@ class receiveDataThread(QThread):
sqlSubmitQueue.put(t) sqlSubmitQueue.put(t)
sqlReturnQueue.get() sqlReturnQueue.get()
sqlLock.release() 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. #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. #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]) infile = cStringIO.StringIO(self.data[readPosition:self.payloadLength+24])
outfile = cStringIO.StringIO() outfile = cStringIO.StringIO()
#print 'len(myRSAAddressHashes.items()):', len(myRSAAddressHashes.items()) #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.' print 'Could not decrypt with any RSA keys if you have any.'
printLock.release() printLock.release()
infile.close() infile.close()
outfile.close() outfile.close()"""
#A msg message has a valid time and POW and requires processing. The recmsg function calls this one. #A msg message has a valid time and POW and requires processing. The recmsg function calls this one.
def processmsg(self,readPosition): def processmsg(self,readPosition):
@ -1095,6 +1094,7 @@ class receiveDataThread(QThread):
sqlSubmitQueue.put(t) sqlSubmitQueue.put(t)
sqlReturnQueue.get() sqlReturnQueue.get()
sqlLock.release() 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. 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()) fromAddress = encodeAddress(sendersAddressVersionNumber,sendersStreamNumber,ripe.digest())
if config.get('bitmessagesettings', 'blackwhitelist') == 'black': #If we are using a blacklist if config.get('bitmessagesettings', 'blackwhitelist') == 'black': #If we are using a blacklist
@ -1306,7 +1306,7 @@ class receiveDataThread(QThread):
if addressVersion == 0: if addressVersion == 0:
print '(Within processpubkey) addressVersion of 0 doesn\'t make sense.' print '(Within processpubkey) addressVersion of 0 doesn\'t make sense.'
return return
if addressVersion >= 3: if addressVersion >= 3 or addressVersion == 1:
printLock.acquire() printLock.acquire()
print 'This version of Bitmessage cannot handle version', addressVersion,'addresses.' print 'This version of Bitmessage cannot handle version', addressVersion,'addresses.'
printLock.release() printLock.release()
@ -1352,7 +1352,6 @@ class receiveDataThread(QThread):
sqlReturnQueue.get() sqlReturnQueue.get()
sqlLock.release() sqlLock.release()
printLock.acquire() printLock.acquire()
print 'added foreign pubkey into our database'
printLock.release() printLock.release()
workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe)))
else: else:
@ -1364,12 +1363,11 @@ class receiveDataThread(QThread):
sqlReturnQueue.get() sqlReturnQueue.get()
sqlLock.release() sqlLock.release()
printLock.acquire() printLock.acquire()
print 'added foreign pubkey into our database'
printLock.release() printLock.release()
workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe)))
#This code which deals with old RSA addresses will soon be removed. #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]) nLength, varintLength = decodeVarint(self.data[readPosition:readPosition+10])
readPosition += varintLength readPosition += varintLength
nString = self.data[readPosition:readPosition+nLength] nString = self.data[readPosition:readPosition+nLength]
@ -1420,7 +1418,7 @@ class receiveDataThread(QThread):
printLock.acquire() printLock.acquire()
print 'added foreign pubkey into our database' print 'added foreign pubkey into our database'
printLock.release() printLock.release()
workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe)))"""
#We have received a getpubkey message #We have received a getpubkey message
def recgetpubkey(self): def recgetpubkey(self):
@ -1461,6 +1459,9 @@ class receiveDataThread(QThread):
if addressVersionNumber == 0: if addressVersionNumber == 0:
print 'The addressVersionNumber of the pubkey request is zero. That doesn\'t make any sense. Ignoring it.' print 'The addressVersionNumber of the pubkey request is zero. That doesn\'t make any sense. Ignoring it.'
return return
elif addressVersionNumber == 1:
print 'The addressVersionNumber of the pubkey request is 1 which isn\'t supported anymore. Ignoring it.'
return
elif addressVersionNumber > 2: elif addressVersionNumber > 2:
print 'The addressVersionNumber of the pubkey request is too high. Can\'t understand. Ignoring it.' print 'The addressVersionNumber of the pubkey request is too high. Can\'t understand. Ignoring it.'
return return
@ -3011,7 +3012,7 @@ class addressGenerator(QThread):
reloadMyAddressHashes() reloadMyAddressHashes()
#This code which deals with old RSA addresses will soon be removed. #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.' 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) self.emit(SIGNAL("updateStatusBar(PyQt_PyObject)"),statusbar)
(pubkey, privkey) = rsa.newkeys(config.getint('bitmessagesettings', 'bitstrength')) (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("updateStatusBar(PyQt_PyObject)"),'Done generating address')
self.emit(SIGNAL("writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),self.label,address,str(self.streamNumber)) 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. #Does an EC point multiplication; turns a private key into a public key.
def pointMult(self,secret): def pointMult(self,secret):
@ -4604,6 +4605,7 @@ class MyForm(QtGui.QMainWindow):
sqlLock.release() sqlLock.release()
self.ui.tableWidgetSubscriptions.removeRow(currentRow) self.ui.tableWidgetSubscriptions.removeRow(currentRow)
self.rerenderInboxFromLabels() self.rerenderInboxFromLabels()
self.reloadBroadcastSendersForWhichImWatching()
def on_action_SubscriptionsClipboard(self): def on_action_SubscriptionsClipboard(self):
currentRow = self.ui.tableWidgetSubscriptions.currentRow() currentRow = self.ui.tableWidgetSubscriptions.currentRow()
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(currentRow,1).text() addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(currentRow,1).text()

View File

@ -92,7 +92,7 @@ def takeSentMessagesOutOfTrash():
#readInbox() #readInbox()
#readSent() #readSent()
#readPubkeys() #readPubkeys()
#readSubscriptions() readSubscriptions()
readInventory() #readInventory()