#At this point, this message claims to be from sendersHash and we are interested in it. We still have to hash the public key to make sure it is truly the key that matches the hash, and also check the signiture.
readPosition+=20
@ -598,8 +612,20 @@ class receiveDataThread(QThread):
@ -683,6 +709,7 @@ class receiveDataThread(QThread):
#We have received a msg message.
defrecmsg(self):
#First we must check to make sure the proof of work is sufficient.
messageProcessingStartTime=time.time()
ifnotself.isProofOfWorkSufficient():
print'Proof of work in msg message insufficient.'
return
@ -731,7 +758,6 @@ class receiveDataThread(QThread):
sqlReturnQueue.get()
sqlLock.release()
self.emit(SIGNAL("updateSentItemStatusByAckdata(PyQt_PyObject,PyQt_PyObject)"),self.data[readPosition:24+self.payloadLength],'Acknowledgement of the message received just now.')
flushInventory()#so that we won't accidentially receive this message twice if the user restarts Bitmessage both soon and un-cleanly.
return
else:
printLock.acquire()
@ -740,7 +766,6 @@ class receiveDataThread(QThread):
printLock.release()
#This is not an acknowledgement bound for me. See if it is a message bound for me by trying to decrypt it with my private keys.
print'As a matter of intellectual curiosity, here is the Bitcoin address associated with the keys owned by the other person:',calculateBitcoinAddressFromPubkey(pubSigningKey),' ..and here is the testnet address:',calculateTestnetAddressFromPubkey(pubSigningKey),'. The other person must take their private signing key from Bitmessage and import it into Bitcoin (or a service like Blockchain.info) for it to be of any use. Do not use this unless you know what you are doing.'
printLock.release()
@ -824,7 +850,6 @@ class receiveDataThread(QThread):
sha.update(pubSigningKey+pubEncryptionKey)
ripe=hashlib.new('ripemd160')
ripe.update(sha.digest())
#Let's store the public key in case we want to reply to this person.
#We don't have the correct nonce or time (which would let us send out a pubkey message) so we'll just fill it with 1's. We won't be able to send this pubkey to others (without doing the proof of work ourselves, which this program is programmed to not do.)
t=(ripe.digest(),False,'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'+'\xFF\xFF\xFF\xFF'+data[messageVersionLength:endOfThePublicKeyPosition],int(time.time())+2419200)#after one month we may remove this pub key from our database. (2419200 = a month)
@ -833,7 +858,6 @@ class receiveDataThread(QThread):
sqlSubmitQueue.put(t)
sqlReturnQueue.get()
sqlLock.release()
blockMessage=False#Gets set to True if the user shouldn't see the message according to black or white lists.
#Now let's consider sending the acknowledgement. We'll need to make sure that our client will properly process the ackData; if the packet is malformed, we could clear out self.data and an attacker could use that behavior to determine that we were capable of decoding this message.
ackDataValidThusFar=True
iflen(ackData)<24:
@ -923,6 +947,27 @@ class receiveDataThread(QThread):
ifackDataValidThusFar:
print'ackData is valid. Will process it.'
self.ackDataThatWeHaveYetToSend.append(ackData)#When we have processed all data, the processData function will pop the ackData out and process it as if it is a message received from our peer.
#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.
@ -948,7 +993,6 @@ class receiveDataThread(QThread):
#decryption failed for this key. The message is for someone else (or for a different key of mine).
ifinitialDecryptionSuccessfulandoutfile.getvalue()[:20]=='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00':#this run of 0s allows the true message receiver to identify his message
#This is clearly a message bound for me.
flushInventory()#so that we won't accidentially receive this message twice if the user restarts Bitmessage soon.
outfile.seek(0)
data=outfile.getvalue()
readPosition=20#To start reading past the 20 zero bytes
@ -1118,7 +1162,7 @@ class receiveDataThread(QThread):
#newItem = QtGui.QTableWidgetItem('Doing work necessary to send broadcast...'+strftime(config.get('bitmessagesettings', 'timeformat'),localtime(int(time.time()))))
newItem=QtGui.QTableWidgetItem('Doing work necessary to send broadcast...')
newItem.setData(Qt.UserRole,ackdata)
newItem=myTableWidgetItem('Doing work necessary to send broadcast...')
connectedHostsList={}#List of hosts to which we are connected. Used to guarantee that the outgoingSynSender thread won't connect to the same remote node twice.
neededPubkeys={}
successfullyDecryptMessageTimings=[]#A list of the amounts of time it took to successfully decrypt msg messages
#These constants are not at the top because if changed they will cause particularly unexpected behavior: You won't be able to either send or receive messages because the proof of work you do (or demand) won't match that done or demanded by others. Don't change them!
averageProofOfWorkNonceTrialsPerByte=320#The amount of work that should be performed (and demanded) per byte of the payload. Double this number to double the work.