Implimented broadcast encryption (testing)
This commit is contained in:
parent
896b96b7c7
commit
d14be90c3b
|
@ -721,8 +721,8 @@ class receiveDataThread(QThread):
|
||||||
printLock.acquire()
|
printLock.acquire()
|
||||||
print 'Length of time program spent failing to decrypt this v2 broadcast:', time.time()- self.messageProcessingStartTime, 'seconds.'
|
print 'Length of time program spent failing to decrypt this v2 broadcast:', time.time()- self.messageProcessingStartTime, 'seconds.'
|
||||||
printLock.release()
|
printLock.release()
|
||||||
else:
|
return
|
||||||
#This is a broadcast I have decrypted and thus am interested in.
|
#At this point this is a broadcast I have decrypted and thus am interested in.
|
||||||
signedBroadcastVersion, readPosition = decodeVarint(decryptedData[:10])
|
signedBroadcastVersion, readPosition = decodeVarint(decryptedData[:10])
|
||||||
beginningOfPubkeyPosition = readPosition #used when we add the pubkey to our pubkey table
|
beginningOfPubkeyPosition = readPosition #used when we add the pubkey to our pubkey table
|
||||||
sendersAddressVersion, sendersAddressVersionLength = decodeVarint(decryptedData[readPosition:readPosition+9])
|
sendersAddressVersion, sendersAddressVersionLength = decodeVarint(decryptedData[readPosition:readPosition+9])
|
||||||
|
@ -950,15 +950,7 @@ class receiveDataThread(QThread):
|
||||||
printLock.release()
|
printLock.release()
|
||||||
else:
|
else:
|
||||||
#This is a message bound for me.
|
#This is a message bound for me.
|
||||||
|
|
||||||
#If this message is bound for one of my version 3 addresses (or higher), then we must check to make sure it meets our demanded proof of work requirement.
|
|
||||||
toAddress = myAddressesByHash[toRipe] #Look up my address based on the RIPE hash.
|
toAddress = myAddressesByHash[toRipe] #Look up my address based on the RIPE hash.
|
||||||
if decodeAddress(toAddress)[1] >= 3:#If the toAddress version number is 3 or higher:
|
|
||||||
requiredNonceTrialsPerByte = config.getint(toAddress,'noncetrialsperbyte')
|
|
||||||
requiredPayloadLengthExtraBytes = config.getint(toAddress,'payloadlengthextrabytes')
|
|
||||||
if not self.isProofOfWorkSufficient(encryptedData,requiredNonceTrialsPerByte,requiredPayloadLengthExtraBytes):
|
|
||||||
print 'Proof of work in msg message insufficient only because it does not meet our higher requirement.'
|
|
||||||
return
|
|
||||||
readPosition = 0
|
readPosition = 0
|
||||||
messageVersion, messageVersionLength = decodeVarint(decryptedData[readPosition:readPosition+10])
|
messageVersion, messageVersionLength = decodeVarint(decryptedData[readPosition:readPosition+10])
|
||||||
readPosition += messageVersionLength
|
readPosition += messageVersionLength
|
||||||
|
@ -1042,18 +1034,24 @@ class receiveDataThread(QThread):
|
||||||
sqlSubmitQueue.put('commit')
|
sqlSubmitQueue.put('commit')
|
||||||
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.
|
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())
|
fromAddress = encodeAddress(sendersAddressVersionNumber,sendersStreamNumber,ripe.digest())
|
||||||
|
#If this message is bound for one of my version 3 addresses (or higher), then we must check to make sure it meets our demanded proof of work requirement.
|
||||||
|
if decodeAddress(toAddress)[1] >= 3:#If the toAddress version number is 3 or higher:
|
||||||
|
if not isAddressInMyAddressBookSubscriptionsListOrWhitelist(fromAddress): #If I'm not friendly with this person:
|
||||||
|
requiredNonceTrialsPerByte = config.getint(toAddress,'noncetrialsperbyte')
|
||||||
|
requiredPayloadLengthExtraBytes = config.getint(toAddress,'payloadlengthextrabytes')
|
||||||
|
if not self.isProofOfWorkSufficient(encryptedData,requiredNonceTrialsPerByte,requiredPayloadLengthExtraBytes):
|
||||||
|
print 'Proof of work in msg message insufficient only because it does not meet our higher requirement.'
|
||||||
|
return
|
||||||
|
blockMessage = False #Gets set to True if the user shouldn't see the message according to black or white lists.
|
||||||
if config.get('bitmessagesettings', 'blackwhitelist') == 'black': #If we are using a blacklist
|
if config.get('bitmessagesettings', 'blackwhitelist') == 'black': #If we are using a blacklist
|
||||||
t = (fromAddress,)
|
t = (fromAddress,)
|
||||||
sqlLock.acquire()
|
sqlLock.acquire()
|
||||||
sqlSubmitQueue.put('''SELECT label, enabled FROM blacklist where address=?''')
|
sqlSubmitQueue.put('''SELECT label FROM blacklist where address=? and enabled='1' ''')
|
||||||
sqlSubmitQueue.put(t)
|
sqlSubmitQueue.put(t)
|
||||||
queryreturn = sqlReturnQueue.get()
|
queryreturn = sqlReturnQueue.get()
|
||||||
sqlLock.release()
|
sqlLock.release()
|
||||||
for row in queryreturn:
|
if queryreturn != []:
|
||||||
label, enabled = row
|
|
||||||
if enabled:
|
|
||||||
printLock.acquire()
|
printLock.acquire()
|
||||||
print 'Message ignored because address is in blacklist.'
|
print 'Message ignored because address is in blacklist.'
|
||||||
printLock.release()
|
printLock.release()
|
||||||
|
@ -1061,18 +1059,13 @@ class receiveDataThread(QThread):
|
||||||
else: #We're using a whitelist
|
else: #We're using a whitelist
|
||||||
t = (fromAddress,)
|
t = (fromAddress,)
|
||||||
sqlLock.acquire()
|
sqlLock.acquire()
|
||||||
sqlSubmitQueue.put('''SELECT label, enabled FROM whitelist where address=?''')
|
sqlSubmitQueue.put('''SELECT label FROM whitelist where address=? and enabled='1' ''')
|
||||||
sqlSubmitQueue.put(t)
|
sqlSubmitQueue.put(t)
|
||||||
queryreturn = sqlReturnQueue.get()
|
queryreturn = sqlReturnQueue.get()
|
||||||
sqlLock.release()
|
sqlLock.release()
|
||||||
if queryreturn == []:
|
if queryreturn == []:
|
||||||
print 'Message ignored because address not in whitelist.'
|
print 'Message ignored because address not in whitelist.'
|
||||||
blockMessage = True
|
blockMessage = True
|
||||||
for row in queryreturn: #It could be in the whitelist but disabled. Let's check.
|
|
||||||
label, enabled = row
|
|
||||||
if not enabled:
|
|
||||||
print 'Message ignored because address in whitelist but not enabled.'
|
|
||||||
blockMessage = True
|
|
||||||
if not blockMessage:
|
if not blockMessage:
|
||||||
print 'fromAddress:', fromAddress
|
print 'fromAddress:', fromAddress
|
||||||
print 'First 150 characters of message:', repr(message[:150])
|
print 'First 150 characters of message:', repr(message[:150])
|
||||||
|
@ -1514,7 +1507,9 @@ class receiveDataThread(QThread):
|
||||||
|
|
||||||
#Send a getdata message to our peer to request the object with the given hash
|
#Send a getdata message to our peer to request the object with the given hash
|
||||||
def sendgetdata(self,hash):
|
def sendgetdata(self,hash):
|
||||||
|
printLock.acquire()
|
||||||
print 'sending getdata to retrieve object with hash:', hash.encode('hex')
|
print 'sending getdata to retrieve object with hash:', hash.encode('hex')
|
||||||
|
printLock.release()
|
||||||
payload = '\x01' + hash
|
payload = '\x01' + hash
|
||||||
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
|
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
|
||||||
headerData += 'getdata\x00\x00\x00\x00\x00'
|
headerData += 'getdata\x00\x00\x00\x00\x00'
|
||||||
|
@ -1990,6 +1985,7 @@ class sendDataThread(QThread):
|
||||||
self.HOST = HOST
|
self.HOST = HOST
|
||||||
self.PORT = PORT
|
self.PORT = PORT
|
||||||
self.streamNumber = streamNumber
|
self.streamNumber = streamNumber
|
||||||
|
self.remoteProtocolVersion = -1 #This must be set using setRemoteProtocolVersion command which is sent through the self.mailbox queue.
|
||||||
self.lastTimeISentData = int(time.time()) #If this value increases beyond five minutes ago, we'll send a pong message to keep the connection alive.
|
self.lastTimeISentData = int(time.time()) #If this value increases beyond five minutes ago, we'll send a pong message to keep the connection alive.
|
||||||
self.objectsOfWhichThisRemoteNodeIsAlreadyAware = objectsOfWhichThisRemoteNodeIsAlreadyAware
|
self.objectsOfWhichThisRemoteNodeIsAlreadyAware = objectsOfWhichThisRemoteNodeIsAlreadyAware
|
||||||
printLock.acquire()
|
printLock.acquire()
|
||||||
|
@ -2092,7 +2088,7 @@ class sendDataThread(QThread):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
printLock.acquire()
|
printLock.acquire()
|
||||||
print 'sendDataThread ID:',id(self),'ignoring command', command,'because it is not in stream',deststream
|
print 'sendDataThread ID:',id(self),'ignoring command', command,'because the thread is not in stream',deststream
|
||||||
printLock.release()
|
printLock.release()
|
||||||
|
|
||||||
|
|
||||||
|
@ -5573,7 +5569,6 @@ class MyForm(QtGui.QMainWindow):
|
||||||
if addressVersionNumber == 2:
|
if addressVersionNumber == 2:
|
||||||
broadcastSendersForWhichImWatching[hash] = 0
|
broadcastSendersForWhichImWatching[hash] = 0
|
||||||
#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.
|
#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.
|
||||||
print '(Within reloadBroadcastSendersForWhichImWatching) The string that we will hash to make the privEncryptionKey is', (encodeVarint(addressVersionNumber)+encodeVarint(streamNumber)+hash).encode('hex')
|
|
||||||
privEncryptionKey = hashlib.sha512(encodeVarint(addressVersionNumber)+encodeVarint(streamNumber)+hash).digest()[:32]
|
privEncryptionKey = hashlib.sha512(encodeVarint(addressVersionNumber)+encodeVarint(streamNumber)+hash).digest()[:32]
|
||||||
MyECSubscriptionCryptorObjects[hash] = highlevelcrypto.makeCryptor(privEncryptionKey.encode('hex'))
|
MyECSubscriptionCryptorObjects[hash] = highlevelcrypto.makeCryptor(privEncryptionKey.encode('hex'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user