diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index f612e48a..7b684ff5 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -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: diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index 1f9c20be..896b355d 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -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 diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index 95c1f7e2..5eda2aaa 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -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: diff --git a/src/helper_bitcoin.py b/src/helper_bitcoin.py index d4f1d105..a51eaf9c 100644 --- a/src/helper_bitcoin.py +++ b/src/helper_bitcoin.py @@ -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 diff --git a/src/helper_msgcoding.py b/src/helper_msgcoding.py index 05fa1c1b..478cc5cd 100644 --- a/src/helper_msgcoding.py +++ b/src/helper_msgcoding.py @@ -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. diff --git a/src/protocol.py b/src/protocol.py index eb2cc86f..41e39a7c 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -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 diff --git a/src/pyelliptic/cipher.py b/src/pyelliptic/cipher.py index af6c08ca..2c2c54da 100644 --- a/src/pyelliptic/cipher.py +++ b/src/pyelliptic/cipher.py @@ -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 ...") diff --git a/src/pyelliptic/ecc.py b/src/pyelliptic/ecc.py index c670d023..8f254561 100644 --- a/src/pyelliptic/ecc.py +++ b/src/pyelliptic/ecc.py @@ -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) diff --git a/src/pyelliptic/hash.py b/src/pyelliptic/hash.py index 70c9a6ce..b133f447 100644 --- a/src/pyelliptic/hash.py +++ b/src/pyelliptic/hash.py @@ -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) diff --git a/src/shared.py b/src/shared.py index c1099c00..48ac7c91 100644 --- a/src/shared.py +++ b/src/shared.py @@ -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))