print'Cannot decode incoming broadcast versions higher than 2. Assuming the sender isn\'t being silly, you should upgrade Bitmessage because this message shall be ignored.'
ifbroadcastVersion<1orbroadcastVersion>3:
print'Cannot decode incoming broadcast versions higher than 3. Assuming the sender isn\'t being silly, you should upgrade Bitmessage because this message shall be ignored.'
return
ifbroadcastVersion==1:
beginningOfPubkeyPosition=readPosition# used when we add the pubkey to our pubkey table
@ -709,6 +709,159 @@ class receiveDataThread(threading.Thread):
withshared.printLock:
print'Time spent processing this interesting broadcast:',time.time()-self.messageProcessingStartTime
toRipe=key# This is the RIPE hash of the sender's pubkey. We need this below to compare to the RIPE hash of the sender's address to verify that it was encrypted by with their key rather than some other key.
initialDecryptionSuccessful=True
print'EC decryption successful using key associated with ripe hash:',key.encode('hex')
break
exceptExceptionaserr:
pass
# print 'cryptorObject.decrypt Exception:', err
ifnotinitialDecryptionSuccessful:
# This is not a broadcast I am interested in.
withshared.printLock:
print'Length of time program spent failing to decrypt this v2 broadcast:',time.time()-self.messageProcessingStartTime,'seconds.'
return
# At this point this is a broadcast I have decrypted and thus am
# interested in.
signedBroadcastVersion,readPosition=decodeVarint(
decryptedData[:10])
beginningOfPubkeyPosition=readPosition# used when we add the pubkey to our pubkey table
print'Cannot decode senderAddressVersion other than 2 or 3. Assuming the sender isn\'t being silly, you should upgrade Bitmessage because this message shall be ignored.'
return
readPosition+=sendersAddressVersionLength
sendersStream,sendersStreamLength=decodeVarint(
decryptedData[readPosition:readPosition+9])
ifsendersStream!=cleartextStreamNumber:
print'The stream number outside of the encryption on which the POW was completed doesn\'t match the stream number inside the encryption. Ignoring broadcast.'
privEncryptionKey=hashlib.sha512(hashlib.sha512(encodeVarint(toAddressVersionNumber)+encodeVarint(toStreamNumber)+toRipe).digest()).digest()[:32]# Note that this is the first half of the sha512 hash.
shared.neededPubkeys[toripe]=highlevelcrypto.makeCryptor(privEncryptionKey.encode('hex'))# We'll need this for when we receive a pubkey reply: it will be encrypted and we'll need to decrypt it.
privEncryptionKey=doubleHashOfAddressData[:32]# Note that this is the first half of the sha512 hash.
tag=doubleHashOfAddressData[32:]
shared.neededPubkeys[tag]=highlevelcrypto.makeCryptor(privEncryptionKey.encode('hex'))# We'll need this for when we receive a pubkey reply: it will be encrypted and we'll need to decrypt it.
# Initialize the shared.ackdataForWhichImWatching data structure using data
# from the sql database.
@ -252,7 +257,6 @@ class singleWorker(threading.Thread):
payload+=encodeVarint(addressVersionNumber)# Address version number
payload+=encodeVarint(streamNumber)
dataToEncrypt='\x00\x00\x00\x01'# bitfield of features supported by me (see the wiki).
try:
@ -264,7 +268,6 @@ class singleWorker(threading.Thread):
withshared.printLock:
sys.stderr.write(
'Error within sendOutOrStoreMyV4Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n'%err)
toRipe,tr.translateText("MainWindow",'Sending a request for the recipient\'s encryption key.'))))
self.requestPubKey(toaddress)
# Get all messages that are ready to be sent, and also all messages
# which we have sent in the last 28 days which were previously marked
# as 'toodifficult'. If the user as raised the maximum acceptable
@ -530,7 +620,7 @@ class singleWorker(threading.Thread):
forrowinqueryreturn:
pubkeyPayload,=row
# The v3 pubkey message is stored the way we originally received it
# The pubkey message is stored the way we originally received it
# which means that we need to read beyond things like the nonce and
# time to get to the actual public keys.
iftoAddressVersionNumber<=3:
@ -649,7 +739,7 @@ class singleWorker(threading.Thread):
payload+=encodeVarint(len(signature))
payload+=signature
iffromAddressVersionNumber== 3:
iffromAddressVersionNumber>= 3:
payload='\x01'# Message version.
payload+=encodeVarint(fromAddressVersionNumber)
payload+=encodeVarint(fromStreamNumber)
@ -781,7 +871,8 @@ class singleWorker(threading.Thread):
shared.neededPubkeys[ripe]=0
elifaddressVersionNumber>=4:
privEncryptionKey=hashlib.sha512(hashlib.sha512(encodeVarint(addressVersionNumber)+encodeVarint(streamNumber)+ripe).digest()).digest()[:32]# Note that this is the first half of the sha512 hash.
shared.neededPubkeys[ripe]=highlevelcrypto.makeCryptor(privEncryptionKey.encode('hex'))# We'll need this for when we receive a pubkey reply: it will be encrypted and we'll need to decrypt it.
tag=hashlib.sha512(hashlib.sha512(encodeVarint(addressVersionNumber)+encodeVarint(streamNumber)+ripe).digest()).digest()[32:]# Note that this is the second half of the sha512 hash.
shared.neededPubkeys[tag]=highlevelcrypto.makeCryptor(privEncryptionKey.encode('hex'))# We'll need this for when we receive a pubkey reply: it will be encrypted and we'll need to decrypt it.
-300,300)))# the current time plus or minus five minutes.
payload+=encodeVarint(addressVersionNumber)
@ -791,9 +882,9 @@ class singleWorker(threading.Thread):
withshared.printLock:
print'making request for pubkey with ripe:',ripe.encode('hex')
else:
payload+=hashlib.sha512(hashlib.sha512(encodeVarint(addressVersionNumber)+encodeVarint(streamNumber)+ripe).digest()).digest()[32:]# Note that this is the second half of the sha512 hash.
payload+= tag
withshared.printLock:
print'making request for v4 pubkey with ripe:',ripe.encode('hex')
print'making request for v4 pubkey with tag:',tag.encode('hex')
# print 'trial value', trialValue
statusbar='Doing the computations necessary to request the recipient\'s public key.'
#Now, for all addresses, even version 2 addresses, we should create Cryptor objects in a dictionary which we will use to attempt to decrypt encrypted broadcast messages.