toRipe=key# This is the RIPE hash of my pubkeys. We need this below to compare to the destination_ripe included in the encrypted data.
initialDecryptionSuccessful=True
logger.info('EC decryption successful using key associated with ripe hash: %s. msg did NOT specify version.'%key.encode('hex'))
# We didn't bypass a msg version above as it is commented out.
# But the decryption was successful. Which means that there
# wasn't a msg version byte include in this msg.
msgObjectContainedVersion=False
logger.info('EC decryption successful using key associated with ripe hash: %s.'%key.encode('hex'))
#msgObjectContainedVersion = False
break
exceptExceptionaserr:
# What if a client sent us a msg with
# a msg version included? We didn't bypass it above. So
# let's try to decrypt the msg assuming that it is present.
try:
decryptedData=cryptorObject.decrypt(data[readPosition+1:])# notice that we offset by 1 byte compared to the attempt above.
toRipe=key# This is the RIPE hash of my pubkeys. We need this below to compare to the destination_ripe included in the encrypted data.
initialDecryptionSuccessful=True
logger.info('EC decryption successful using key associated with ripe hash: %s. msg DID specifiy version.'%key.encode('hex'))
# There IS a msg version byte include in this msg.
msgObjectContainedVersion=True
break
exceptExceptionaserr:
pass
pass
ifnotinitialDecryptionSuccessful:
# This is not a message bound for me.
logger.info('Length of time program spent failing to decrypt this message: %s seconds.'%(time.time()-messageProcessingStartTime,))
@ -416,15 +355,6 @@ class objectProcessor(threading.Thread):
toAddress=shared.myAddressesByHash[
toRipe]# Look up my address based on the RIPE hash.
readPosition=0
ifnotmsgObjectContainedVersion:# by which I mean "if the msg object didn't have the msg version outside of the encryption". This confusingness will be removed after the protocol v3 upgrade period.
logger.info('Cannot decode incoming broadcast versions higher than 5. Assuming the sender isn\'t being silly, you should upgrade Bitmessage because this message shall be ignored.')
ifbroadcastVersion<4orbroadcastVersion>5:
logger.info('Cannot decode incoming broadcast versions less than 4 or higher than 5. Assuming the sender isn\'t being silly, you should upgrade Bitmessage because this message shall be ignored.')
return
ifbroadcastVersion==1:
logger.info('Version 1 broadcasts are no longer supported. Not processing it at all.')
beginningOfPubkeyPosition=readPosition# used when we add the pubkey to our pubkey table. This variable can be disposed of after the protocol v3 upgrade period because it will necessarily be at the beginning of the decryptedData; ie it will definitely equal 0
logger.info('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:
logger.info('The stream number outside of the encryption on which the POW was completed doesn\'t match the stream number inside the encryption. Ignoring broadcast.')
logger.info('Cannot decode senderAddressVersion less than 4 for broadcast version number 3 or 4. Assuming the sender isn\'t being silly, you should upgrade Bitmessage because this message shall be ignored.')
# At this point this is a broadcast I have decrypted and am
logger.warning('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:
logger.info('The stream number outside of the encryption on which the POW was completed doesn\'t match the stream number inside the encryption. Ignoring broadcast.')
elifbroadcastVersion==5:
ifsendersAddressVersion<4:
logger.info('Cannot decode senderAddressVersion less than 4 for broadcast version number 5. Assuming the sender isn\'t being silly, you should upgrade Bitmessage because this message shall be ignored.')
logger.debug('sender\'s requiredPayloadLengthExtraBytes is %s'%requiredPayloadLengthExtraBytes)
endOfPubkeyPosition=readPosition
readPosition+=sendersAddressVersionLength
sendersStream,sendersStreamLength=decodeVarint(
decryptedData[readPosition:readPosition+9])
ifsendersStream!=cleartextStreamNumber:
logger.info('The stream number outside of the encryption on which the POW was completed doesn\'t match the stream number inside the encryption. Ignoring broadcast.')
ackdata,tr.translateText("MainWindow","Doing work necessary to send message."))))
iffromAddressVersionNumber==2:
payload=""
ifint(time.time())<1416175200:# Sun, 16 Nov 2014 22:00:00 GMT
payload+='\x01'# Message version.
payload+=encodeVarint(fromAddressVersionNumber)
payload+=encodeVarint(fromStreamNumber)
payload+='\x00\x00\x00\x01'# Bitfield of features and behaviors that can be expected from me. (See https://bitmessage.org/wiki/Protocol_specification#Pubkey_bitfield_features )
# We need to convert our private keys to public keys in order
payload+='\x00\x00\x00\x01'# Bitfield of features and behaviors that can be expected from me. (See https://bitmessage.org/wiki/Protocol_specification#Pubkey_bitfield_features )
pubSigningKey=highlevelcrypto.privToPub(
privSigningKeyHex).decode('hex')
pubEncryptionKey=highlevelcrypto.privToPub(
privEncryptionKeyHex).decode('hex')
payload+=pubSigningKey[
1:]# The \x04 on the beginning of the public keys are not sent. This way there is only one acceptable way to encode and send a public key.
payload+=pubEncryptionKey[1:]
payload+=toRipe# This hash will be checked by the receiver of the message to verify that toRipe belongs to them. This prevents a Surreptitious Forwarding Attack.
payload+='\x02'# Type 2 is simple UTF-8 message encoding as specified on the Protocol Specification on the Bitmessage Wiki.
messageToTransmit='Subject:'+ \
subject+'\n'+'Body:'+message
payload+=encodeVarint(len(messageToTransmit))
payload+=messageToTransmit
fullAckPayload=self.generateFullAckMessage(
ackdata,toStreamNumber)# The fullAckPayload is a normal msg protocol message with the proof of work already completed that the receiver of this message can easily send out.
payload+=encodeVarint(len(fullAckPayload))
payload+=fullAckPayload
ifint(time.time())<1416175200:# Sun, 16 Nov 2014 22:00:00 GMT
ackdata,tr.translateText("MainWindow","Error! Could not find sender address (your address) in the keys.dat file."))))
continue
iffromAddressVersionNumber>=3:
payload=""
ifint(time.time())<1416175200:# Sun, 16 Nov 2014 22:00:00 GMT
payload+='\x01'# Message version.
payload+=encodeVarint(fromAddressVersionNumber)
payload+=encodeVarint(fromStreamNumber)
payload+='\x00\x00\x00\x01'# Bitfield of features and behaviors that can be expected from me. (See https://bitmessage.org/wiki/Protocol_specification#Pubkey_bitfield_features )
# We need to convert our private keys to public keys in order
1:]# The \x04 on the beginning of the public keys are not sent. This way there is only one acceptable way to encode and send a public key.
payload+=pubEncryptionKey[1:]
payload+=pubSigningKey[
1:]# The \x04 on the beginning of the public keys are not sent. This way there is only one acceptable way to encode and send a public key.
payload+=pubEncryptionKey[1:]
iffromAddressVersionNumber>=3:
# If the receiver of our message is in our address book,
# subscriptions list, or whitelist then we will allow them to
# do the network-minimum proof of work. Let us check to see if
@ -840,34 +737,30 @@ class singleWorker(threading.Thread):
payload+=encodeVarint(shared.config.getint(
fromaddress,'payloadlengthextrabytes'))
payload+=toRipe# This hash will be checked by the receiver of the message to verify that toRipe belongs to them. This prevents a Surreptitious Forwarding Attack.
payload+='\x02'# Type 2 is simple UTF-8 message encoding as specified on the Protocol Specification on the Bitmessage Wiki.
messageToTransmit='Subject:'+ \
subject+'\n'+'Body:'+message
payload+=encodeVarint(len(messageToTransmit))
payload+=messageToTransmit
ifshared.config.has_section(toaddress):
withshared.printLock:
print'Not bothering to include ackdata because we are sending to ourselves or a chan.'
print'Not bothering to include ackdata because the receiver said that they won\'t relay it anyway.'
fullAckPayload=''
else:
fullAckPayload=self.generateFullAckMessage(
ackdata,toStreamNumber)# The fullAckPayload is a normal msg protocol message with the proof of work already completed that the receiver of this message can easily send out.
payload+=encodeVarint(len(fullAckPayload))
payload+=fullAckPayload
ifint(time.time())<1416175200:# Sun, 16 Nov 2014 22:00:00 GMT
payload+=toRipe# This hash will be checked by the receiver of the message to verify that toRipe belongs to them. This prevents a Surreptitious Forwarding Attack.
payload+='\x02'# Type 2 is simple UTF-8 message encoding as specified on the Protocol Specification on the Bitmessage Wiki.
messageToTransmit='Subject:'+ \
subject+'\n'+'Body:'+message
payload+=encodeVarint(len(messageToTransmit))
payload+=messageToTransmit
ifshared.config.has_section(toaddress):
withshared.printLock:
print'Not bothering to include ackdata because we are sending to ourselves or a chan.'
print'Not bothering to include ackdata because the receiver said that they won\'t relay it anyway.'
fullAckPayload=''
else:
fullAckPayload=self.generateFullAckMessage(
ackdata,toStreamNumber)# The fullAckPayload is a normal msg protocol message with the proof of work already completed that the receiver of this message can easily send out.