fix decryption to work in Python 3
Messages can be received and viewed now. Remained problems: * Message sending is not working yet.
This commit is contained in:
parent
741f8dd461
commit
88b14977b8
|
@ -847,7 +847,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
else:
|
||||
self.show()
|
||||
self.setWindowState(
|
||||
self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
|
||||
self.windowState() & ~QtCore.Qt.WindowState.WindowMinimized | QtCore.Qt.WindowState.WindowActive)
|
||||
self.raise_()
|
||||
self.activateWindow()
|
||||
|
||||
|
@ -1664,16 +1664,16 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.init_sent_popup_menu(False)
|
||||
self.ui.blackwhitelist.init_blacklist_popup_menu(False)
|
||||
if event.type() == QtCore.QEvent.Type.WindowStateChange:
|
||||
if self.windowState() & QtCore.Qt.WindowMinimized:
|
||||
if self.windowState() & QtCore.Qt.WindowState.WindowMinimized:
|
||||
if config.getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform:
|
||||
QtCore.QTimer.singleShot(0, self.appIndicatorHide)
|
||||
elif event.oldState() & QtCore.Qt.WindowMinimized:
|
||||
elif event.oldState() & QtCore.Qt.WindowState.WindowMinimized:
|
||||
# The window state has just been changed to
|
||||
# Normal/Maximised/FullScreen
|
||||
pass
|
||||
|
||||
def __icon_activated(self, reason):
|
||||
if reason == QtWidgets.QSystemTrayIcon.Trigger:
|
||||
if reason == QtWidgets.QSystemTrayIcon.ActivationReason.Trigger:
|
||||
self.actionShow.setChecked(not self.actionShow.isChecked())
|
||||
self.appIndicatorShowOrHideWindow()
|
||||
|
||||
|
@ -1756,7 +1756,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
# choose font and calculate font parameters
|
||||
fontName = "Lucida"
|
||||
fontSize = 10
|
||||
font = QtGui.QFont(fontName, fontSize, QtGui.QFont.Bold)
|
||||
font = QtGui.QFont(fontName, fontSize, QtGui.QFont.Weight.Bold)
|
||||
fontMetrics = QtGui.QFontMetrics(font)
|
||||
# text
|
||||
txt = str(inboxUnreadCount)
|
||||
|
@ -4071,7 +4071,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
|
||||
messageTextedit.setCurrentFont(QtGui.QFont())
|
||||
messageTextedit.setTextColor(QtGui.QColor())
|
||||
messageTextedit.setContent(message)
|
||||
messageTextedit.setPlainText(message)
|
||||
|
||||
def tableWidgetAddressBookItemChanged(self, item):
|
||||
if item.type == AccountMixin.CHAN:
|
||||
|
|
|
@ -484,9 +484,9 @@ class MessageList_TimeWidget(BMTableWidgetItem):
|
|||
"""
|
||||
data = super(MessageList_TimeWidget, self).data(role)
|
||||
if role == TimestampRole:
|
||||
return int(data.toPyObject())
|
||||
return int(data)
|
||||
if role == QtCore.Qt.ItemDataRole.UserRole:
|
||||
return str(data.toPyObject())
|
||||
return data.data()
|
||||
return data
|
||||
|
||||
|
||||
|
|
|
@ -356,9 +356,9 @@ class objectProcessor(threading.Thread):
|
|||
' Sanity check failed.')
|
||||
return
|
||||
readPosition += 4
|
||||
publicSigningKey = '\x04' + data[readPosition:readPosition + 64]
|
||||
publicSigningKey = b'\x04' + data[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
publicEncryptionKey = '\x04' + data[readPosition:readPosition + 64]
|
||||
publicEncryptionKey = b'\x04' + data[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
specifiedNonceTrialsPerByteLength = decodeVarint(
|
||||
data[readPosition:readPosition + 10])[1]
|
||||
|
@ -517,9 +517,9 @@ class objectProcessor(threading.Thread):
|
|||
return
|
||||
readPosition += sendersStreamNumberLength
|
||||
readPosition += 4
|
||||
pubSigningKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||
pubSigningKey = b'\x04' + decryptedData[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
pubEncryptionKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||
pubEncryptionKey = b'\x04' + decryptedData[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
if sendersAddressVersionNumber >= 3:
|
||||
requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = \
|
||||
|
@ -568,7 +568,7 @@ class objectProcessor(threading.Thread):
|
|||
readPosition += signatureLengthLength
|
||||
signature = decryptedData[
|
||||
readPosition:readPosition + signatureLength]
|
||||
signedData = data[8:20] + encodeVarint(1) + encodeVarint(
|
||||
signedData = bytes(data[8:20]) + encodeVarint(1) + encodeVarint(
|
||||
streamNumberAsClaimedByMsg
|
||||
) + decryptedData[:positionOfBottomOfAckData]
|
||||
|
||||
|
@ -803,11 +803,11 @@ class objectProcessor(threading.Thread):
|
|||
# of the sender's address to verify that it was
|
||||
# encrypted by with their key rather than some
|
||||
# other key.
|
||||
toRipe = key
|
||||
toRipe = unhexlify(key)
|
||||
initialDecryptionSuccessful = True
|
||||
logger.info(
|
||||
'EC decryption successful using key associated'
|
||||
' with ripe hash: %s', hexlify(key))
|
||||
' with ripe hash: %s', key)
|
||||
except Exception:
|
||||
logger.debug(
|
||||
'cryptorObject.decrypt Exception:', exc_info=True)
|
||||
|
@ -820,13 +820,14 @@ class objectProcessor(threading.Thread):
|
|||
elif broadcastVersion == 5:
|
||||
embeddedTag = data[readPosition:readPosition + 32]
|
||||
readPosition += 32
|
||||
if embeddedTag not in shared.MyECSubscriptionCryptorObjects:
|
||||
hex_tag = hexlify(embeddedTag).decode('ascii')
|
||||
if hex_tag not in shared.MyECSubscriptionCryptorObjects:
|
||||
logger.debug('We\'re not interested in this broadcast.')
|
||||
return
|
||||
# We are interested in this broadcast because of its tag.
|
||||
# We're going to add some more data which is signed further down.
|
||||
signedData = data[8:readPosition]
|
||||
cryptorObject = shared.MyECSubscriptionCryptorObjects[embeddedTag]
|
||||
signedData = bytes(data[8:readPosition])
|
||||
cryptorObject = shared.MyECSubscriptionCryptorObjects[hex_tag]
|
||||
try:
|
||||
decryptedData = cryptorObject.decrypt(data[readPosition:])
|
||||
logger.debug('EC decryption successful')
|
||||
|
@ -866,10 +867,10 @@ class objectProcessor(threading.Thread):
|
|||
)
|
||||
readPosition += sendersStreamLength
|
||||
readPosition += 4
|
||||
sendersPubSigningKey = '\x04' + \
|
||||
sendersPubSigningKey = b'\x04' + \
|
||||
decryptedData[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
sendersPubEncryptionKey = '\x04' + \
|
||||
sendersPubEncryptionKey = b'\x04' + \
|
||||
decryptedData[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
if sendersAddressVersion >= 3:
|
||||
|
|
|
@ -19,17 +19,17 @@ def calculateBitcoinAddressFromPubkey(pubkey):
|
|||
sha = hashlib.new('sha256')
|
||||
sha.update(pubkey)
|
||||
ripe.update(sha.digest())
|
||||
ripeWithProdnetPrefix = '\x00' + ripe.digest()
|
||||
ripeWithProdnetPrefix = b'\x00' + ripe.digest()
|
||||
|
||||
checksum = hashlib.sha256(hashlib.sha256(
|
||||
ripeWithProdnetPrefix).digest()).digest()[:4]
|
||||
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
|
||||
numberOfZeroBytesOnBinaryBitcoinAddress = 0
|
||||
while binaryBitcoinAddress[0] == '\x00':
|
||||
while binaryBitcoinAddress[0] == b'\x00':
|
||||
numberOfZeroBytesOnBinaryBitcoinAddress += 1
|
||||
binaryBitcoinAddress = binaryBitcoinAddress[1:]
|
||||
base58encoded = arithmetic.changebase(binaryBitcoinAddress, 256, 58)
|
||||
return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
||||
return b"1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
||||
|
||||
|
||||
def calculateTestnetAddressFromPubkey(pubkey):
|
||||
|
@ -43,14 +43,14 @@ def calculateTestnetAddressFromPubkey(pubkey):
|
|||
sha = hashlib.new('sha256')
|
||||
sha.update(pubkey)
|
||||
ripe.update(sha.digest())
|
||||
ripeWithProdnetPrefix = '\x6F' + ripe.digest()
|
||||
ripeWithProdnetPrefix = b'\x6F' + ripe.digest()
|
||||
|
||||
checksum = hashlib.sha256(hashlib.sha256(
|
||||
ripeWithProdnetPrefix).digest()).digest()[:4]
|
||||
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
|
||||
numberOfZeroBytesOnBinaryBitcoinAddress = 0
|
||||
while binaryBitcoinAddress[0] == '\x00':
|
||||
while binaryBitcoinAddress[0] == b'\x00':
|
||||
numberOfZeroBytesOnBinaryBitcoinAddress += 1
|
||||
binaryBitcoinAddress = binaryBitcoinAddress[1:]
|
||||
base58encoded = arithmetic.changebase(binaryBitcoinAddress, 256, 58)
|
||||
return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
||||
return b"1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
||||
|
|
|
@ -142,7 +142,8 @@ class MsgDecode(object):
|
|||
|
||||
def decodeSimple(self, data):
|
||||
"""Handle simple encoding"""
|
||||
bodyPositionIndex = string.find(data, '\nBody:')
|
||||
data = data.decode('utf-8', 'backslashreplace')
|
||||
bodyPositionIndex = data.find('\nBody:')
|
||||
if bodyPositionIndex > 1:
|
||||
subject = data[8:bodyPositionIndex]
|
||||
# Only save and show the first 500 characters of the subject.
|
||||
|
|
|
@ -294,7 +294,7 @@ def isProofOfWorkSufficient(
|
|||
if TTL < 300:
|
||||
TTL = 300
|
||||
POW, = unpack('>Q', highlevelcrypto.double_sha512(
|
||||
data[:8] + hashlib.sha512(data[8:]).digest())[0:8])
|
||||
bytes(data[:8]) + hashlib.sha512(data[8:]).digest())[0:8])
|
||||
return POW <= 2 ** 64 / (
|
||||
nonceTrialsPerByte * (
|
||||
len(data) + payloadLengthExtraBytes
|
||||
|
|
|
@ -30,7 +30,7 @@ class Cipher(object):
|
|||
self.ctx = OpenSSL.EVP_CIPHER_CTX_new()
|
||||
if do == 1 or do == 0:
|
||||
k = OpenSSL.malloc(key, len(key))
|
||||
IV = OpenSSL.malloc(iv, len(iv))
|
||||
IV = OpenSSL.malloc(bytes(iv), len(iv))
|
||||
OpenSSL.EVP_CipherInit_ex(
|
||||
self.ctx, self.cipher.get_pointer(), 0, k, IV, do)
|
||||
else:
|
||||
|
@ -59,7 +59,7 @@ class Cipher(object):
|
|||
"""Update result with more data"""
|
||||
i = OpenSSL.c_int(0)
|
||||
buffer = OpenSSL.malloc(b"", len(input) + self.cipher.get_blocksize())
|
||||
inp = OpenSSL.malloc(input, len(input))
|
||||
inp = OpenSSL.malloc(bytes(input), len(input))
|
||||
if OpenSSL.EVP_CipherUpdate(self.ctx, OpenSSL.byref(buffer),
|
||||
OpenSSL.byref(i), inp, len(input)) == 0:
|
||||
raise Exception("[OpenSSL] EVP_CipherUpdate FAIL ...")
|
||||
|
|
|
@ -7,6 +7,7 @@ Asymmetric cryptography using elliptic curves
|
|||
|
||||
from hashlib import sha512
|
||||
from struct import pack, unpack
|
||||
from ctypes import c_char_p
|
||||
|
||||
from .cipher import Cipher
|
||||
from .hash import equals, hmac_sha256
|
||||
|
@ -218,8 +219,8 @@ class ECC(object):
|
|||
if other_key == 0:
|
||||
raise Exception("[OpenSSL] EC_KEY_new_by_curve_name FAIL ...")
|
||||
|
||||
other_pub_key_x = OpenSSL.BN_bin2bn(pubkey_x, len(pubkey_x), None)
|
||||
other_pub_key_y = OpenSSL.BN_bin2bn(pubkey_y, len(pubkey_y), None)
|
||||
other_pub_key_x = OpenSSL.BN_bin2bn(c_char_p(bytes(pubkey_x)), len(pubkey_x), None)
|
||||
other_pub_key_y = OpenSSL.BN_bin2bn(c_char_p(bytes(pubkey_y)), len(pubkey_y), None)
|
||||
|
||||
other_group = OpenSSL.EC_KEY_get0_group(other_key)
|
||||
other_pub_key = OpenSSL.EC_POINT_new(other_group)
|
||||
|
|
|
@ -38,7 +38,7 @@ def hmac_sha256(k, m):
|
|||
Compute the key and the message with HMAC SHA5256
|
||||
"""
|
||||
key = OpenSSL.malloc(k, len(k))
|
||||
d = OpenSSL.malloc(m, len(m))
|
||||
d = OpenSSL.malloc(bytes(m), len(m))
|
||||
md = OpenSSL.malloc(0, 32)
|
||||
i = OpenSSL.pointer(OpenSSL.c_int(0))
|
||||
OpenSSL.HMAC(OpenSSL.EVP_sha256(), key, len(k), d, len(m), md, i)
|
||||
|
|
|
@ -151,7 +151,8 @@ def reloadBroadcastSendersForWhichImWatching():
|
|||
encodeVarint(addressVersionNumber)
|
||||
+ encodeVarint(streamNumber) + hashobj
|
||||
).digest()[:32]
|
||||
MyECSubscriptionCryptorObjects[hashobj] = \
|
||||
hex_hash = hexlify(hashobj).decode('ascii')
|
||||
MyECSubscriptionCryptorObjects[hex_hash] = \
|
||||
highlevelcrypto.makeCryptor(hexlify(privEncryptionKey))
|
||||
else:
|
||||
doubleHashOfAddressData = highlevelcrypto.double_sha512(
|
||||
|
@ -160,7 +161,8 @@ def reloadBroadcastSendersForWhichImWatching():
|
|||
)
|
||||
tag = doubleHashOfAddressData[32:]
|
||||
privEncryptionKey = doubleHashOfAddressData[:32]
|
||||
MyECSubscriptionCryptorObjects[tag] = \
|
||||
hex_tag = hexlify(tag).decode('ascii')
|
||||
MyECSubscriptionCryptorObjects[hex_tag] = \
|
||||
highlevelcrypto.makeCryptor(hexlify(privEncryptionKey))
|
||||
|
||||
|
||||
|
|
Reference in New Issue
Block a user