From f6a07a374a5c94bcaba350a92953d6dff1b41478 Mon Sep 17 00:00:00 2001 From: Adam Fontenot Date: Mon, 12 Aug 2013 18:13:28 -0500 Subject: [PATCH 1/4] Add backend ability to understand shorter addresses. Introduces addresses version 4. --- src/addresses.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/addresses.py b/src/addresses.py index a6a571f6..46fa35ba 100644 --- a/src/addresses.py +++ b/src/addresses.py @@ -97,13 +97,23 @@ def calculateInventoryHash(data): return sha2.digest()[0:32] def encodeAddress(version,stream,ripe): - if version >= 2: + if version >= 2 and version < 4: if len(ripe) != 20: raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.") if ripe[:2] == '\x00\x00': ripe = ripe[2:] elif ripe[:1] == '\x00': ripe = ripe[1:] + elif version == 4: + if len(ripe) != 20: + raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.") + emptybitcounter = 0 + while True: + if ripe[emptybitcounter] != '\x00': + break + emptybitcounter += 1 + ripe = ripe[emptybitcounter:] + a = encodeVarint(version) + encodeVarint(stream) + ripe sha = hashlib.new('sha512') sha.update(a) @@ -164,7 +174,7 @@ def decodeAddress(address): #print 'addressVersionNumber', addressVersionNumber #print 'bytesUsedByVersionNumber', bytesUsedByVersionNumber - if addressVersionNumber > 3: + if addressVersionNumber > 4: print 'cannot decode address version numbers this high' status = 'versiontoohigh' return status,0,0,0 @@ -191,6 +201,17 @@ def decodeAddress(address): return 'ripetoolong',0,0,0 else: return 'otherproblem',0,0,0 + elif addressVersionNumber == 4: + if len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4]) > 20: + return 'ripetoolong',0,0,0 + elif len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4]) < 4: + return 'ripetooshort',0,0,0 + else: + x00string = '' + for i in range(20 - len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4])): + x00string += '\x00' + return status,addressVersionNumber,streamNumber,x00string+data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4] + def addBMIfNotPresent(address): address = str(address).strip() From f3e8ce3b8206b69d630ee7566d2d30f50ebceeb1 Mon Sep 17 00:00:00 2001 From: Adam Fontenot Date: Mon, 12 Aug 2013 20:59:38 -0500 Subject: [PATCH 2/4] Made changes suggested by nimdahk --- src/addresses.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/addresses.py b/src/addresses.py index 46fa35ba..1db2105d 100644 --- a/src/addresses.py +++ b/src/addresses.py @@ -107,13 +107,8 @@ def encodeAddress(version,stream,ripe): elif version == 4: if len(ripe) != 20: raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.") - emptybitcounter = 0 - while True: - if ripe[emptybitcounter] != '\x00': - break - emptybitcounter += 1 - ripe = ripe[emptybitcounter:] - + ripe = ripe.lstrip('\x00') + a = encodeVarint(version) + encodeVarint(stream) + ripe sha = hashlib.new('sha512') sha.update(a) @@ -207,9 +202,7 @@ def decodeAddress(address): elif len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4]) < 4: return 'ripetooshort',0,0,0 else: - x00string = '' - for i in range(20 - len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4])): - x00string += '\x00' + x00string = '\x00' * (20 - len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4])) return status,addressVersionNumber,streamNumber,x00string+data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4] From 2a565c97a50792af9874e0276f94efccda1a7c1d Mon Sep 17 00:00:00 2001 From: Adam Fontenot Date: Thu, 15 Aug 2013 03:51:46 -0500 Subject: [PATCH 3/4] Allow backend to send and receive version 4 addresses --- src/class_singleWorker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index b29b7f8d..1f48701c 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -540,7 +540,7 @@ class singleWorker(threading.Thread): requiredPayloadLengthExtraBytes = shared.networkDefaultPayloadLengthExtraBytes shared.UISignalQueue.put(('updateSentItemStatusByAckdata', ( ackdata, tr.translateText("MainWindow", "Doing work necessary to send message.\nThere is no required difficulty for version 2 addresses like this.")))) - elif toAddressVersionNumber == 3: + elif toAddressVersionNumber == 3 or toAddressVersionNumber == 4: requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = decodeVarint( pubkeyPayload[readPosition:readPosition + 10]) readPosition += varintLength @@ -617,7 +617,7 @@ class singleWorker(threading.Thread): payload += encodeVarint(len(signature)) payload += signature - if fromAddressVersionNumber == 3: + if fromAddressVersionNumber == 3 or fromAddressVersionNumber == 4: payload = '\x01' # Message version. payload += encodeVarint(fromAddressVersionNumber) payload += encodeVarint(fromStreamNumber) From ef312c6e2c519f7534bb81743e2fa6e07ce95c79 Mon Sep 17 00:00:00 2001 From: Adam Fontenot Date: Thu, 15 Aug 2013 04:26:14 -0500 Subject: [PATCH 4/4] Updated several missed references to version 3 addresses --- src/bitmessagemain.py | 16 ++++++++-------- src/bitmessageqt/__init__.py | 2 +- src/class_receiveDataThread.py | 4 ++-- src/shared.py | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index cae8daeb..7ec8ee0e 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -525,8 +525,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if status == 'versiontoohigh': return 'API Error 0010: Address version number too high (or zero) in address: ' + toAddress return 'API Error 0007: Could not decode address: ' + toAddress + ' : ' + status - if addressVersionNumber < 2 or addressVersionNumber > 3: - return 'API Error 0011: The address version number currently must be 2 or 3. Others aren\'t supported. Check the toAddress.' + if addressVersionNumber < 2 or addressVersionNumber > 4: + return 'API Error 0011: The address version number currently must be 2, 3, or 4. Others aren\'t supported. Check the toAddress.' if streamNumber != 1: return 'API Error 0012: The stream number must be 1. Others aren\'t supported. Check the toAddress.' status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( @@ -542,8 +542,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if status == 'versiontoohigh': return 'API Error 0010: Address version number too high (or zero) in address: ' + fromAddress return 'API Error 0007: Could not decode address: ' + fromAddress + ' : ' + status - if addressVersionNumber < 2 or addressVersionNumber > 3: - return 'API Error 0011: The address version number currently must be 2 or 3. Others aren\'t supported. Check the fromAddress.' + if addressVersionNumber < 2 or addressVersionNumber > 4: + return 'API Error 0011: The address version number currently must be 2, 3, or 4. Others aren\'t supported. Check the fromAddress.' if streamNumber != 1: return 'API Error 0012: The stream number must be 1. Others aren\'t supported. Check the fromAddress.' toAddress = addBMIfNotPresent(toAddress) @@ -607,8 +607,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if status == 'versiontoohigh': return 'API Error 0010: Address version number too high (or zero) in address: ' + fromAddress return 'API Error 0007: Could not decode address: ' + fromAddress + ' : ' + status - if addressVersionNumber < 2 or addressVersionNumber > 3: - return 'API Error 0011: the address version number currently must be 2 or 3. Others aren\'t supported. Check the fromAddress.' + if addressVersionNumber < 2 or addressVersionNumber > 4: + return 'API Error 0011: the address version number currently must be 2, 3, or 4. Others aren\'t supported. Check the fromAddress.' if streamNumber != 1: return 'API Error 0012: the stream number must be 1. Others aren\'t supported. Check the fromAddress.' fromAddress = addBMIfNotPresent(fromAddress) @@ -678,8 +678,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if status == 'versiontoohigh': return 'API Error 0010: Address version number too high (or zero) in address: ' + address return 'API Error 0007: Could not decode address: ' + address + ' : ' + status - if addressVersionNumber < 2 or addressVersionNumber > 3: - return 'API Error 0011: The address version number currently must be 2 or 3. Others aren\'t supported.' + if addressVersionNumber < 2 or addressVersionNumber > 4: + return 'API Error 0011: The address version number currently must be 2, 3, or 4. Others aren\'t supported.' if streamNumber != 1: return 'API Error 0012: The stream number must be 1. Others aren\'t supported.' # First we must check to see if the address is already in the diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 396d0b6e..c50152c0 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1572,7 +1572,7 @@ class MyForm(QtGui.QMainWindow): continue except: pass - if addressVersionNumber > 3 or addressVersionNumber <= 1: + if addressVersionNumber > 4 or addressVersionNumber <= 1: QMessageBox.about(self, _translate("MainWindow", "Address version number"), _translate( "MainWindow", "Concerning the address %1, Bitmessage cannot understand address version numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(addressVersionNumber))) continue diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index 6adfe490..fb37792b 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -1216,7 +1216,7 @@ class receiveDataThread(threading.Thread): if addressVersion == 0: print '(Within processpubkey) addressVersion of 0 doesn\'t make sense.' return - if addressVersion >= 4 or addressVersion == 1: + if addressVersion > 4 or addressVersion == 1: with shared.printLock: print 'This version of Bitmessage cannot handle version', addressVersion, 'addresses.' @@ -1273,7 +1273,7 @@ class receiveDataThread(threading.Thread): shared.sqlLock.release() # shared.workerQueue.put(('newpubkey',(addressVersion,streamNumber,ripe))) self.possibleNewPubkey(ripe) - if addressVersion == 3: + if addressVersion == 3 or addressVersion == 4: if len(data) < 170: # sanity check. print '(within processpubkey) payloadLength less than 170. Sanity check failed.' return diff --git a/src/shared.py b/src/shared.py index da83f374..e5ff8378 100644 --- a/src/shared.py +++ b/src/shared.py @@ -230,7 +230,7 @@ def reloadMyAddressHashes(): if isEnabled: hasEnabledKeys = True status,addressVersionNumber,streamNumber,hash = decodeAddress(addressInKeysFile) - if addressVersionNumber == 2 or addressVersionNumber == 3: + if addressVersionNumber == 2 or addressVersionNumber == 3 or addressVersionNumber == 4: # Returns a simple 32 bytes of information encoded in 64 Hex characters, # or null if there was an error. privEncryptionKey = decodeWalletImportFormat(