]> jfr.im git - irc/weechat/scripts.git/commitdiff
fish.py 0.9.7: utf-8 encode key passed to blowfish
authorAndreas Kempe <redacted>
Wed, 16 Jun 2021 18:42:44 +0000 (20:42 +0200)
committerSébastien Helleu <redacted>
Sun, 3 Oct 2021 15:57:00 +0000 (17:57 +0200)
The underlying C code performing the blowfish encryption wants bytes and
not a python string. Encode as utf-8 to avoid the issue below.

Traceback (most recent call last):
  File "/home/andkem/.weechat/python/autoload/fish.py", line 861, in fish_modifier_in_privmsg_cb
    b = Blowfish(fish_keys[targetl])
  File "/home/andkem/.weechat/python/autoload/fish.py", line 379, in __init__
    self.blowfish = Crypto.Cipher.Blowfish.new(
  File "/usr/lib/python3.9/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/usr/lib/python3.9/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/usr/lib/python3.9/site-packages/Crypto/Cipher/_mode_ecb.py", line 215, in _create_ecb_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/usr/lib/python3.9/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
    result = start_operation(c_uint8_ptr(key),
  File "/usr/lib/python3.9/site-packages/Crypto/Util/_raw_api.py", line 144, in c_uint8_ptr
    raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
python: error in function "fish_modifier_in_privmsg_cb"

python/fish.py

index 7ddb0f4e0dfd2ba9c0a535a23dafda234cfa3452..720cef8dc5570339afeb036531272ab3e8b29b1b 100644 (file)
@@ -61,7 +61,7 @@ from os import urandom
 
 SCRIPT_NAME = "fish"
 SCRIPT_AUTHOR = "David Flatz <david@upcs.at>"
-SCRIPT_VERSION = "0.9.6"
+SCRIPT_VERSION = "0.9.7"
 SCRIPT_LICENSE = "GPL3"
 SCRIPT_DESC = "FiSH for weechat"
 CONFIG_FILE_NAME = SCRIPT_NAME
@@ -377,7 +377,7 @@ class Blowfish:
             if len(key) > 72:
                 key = key[:72]
             self.blowfish = Crypto.Cipher.Blowfish.new(
-                key, Crypto.Cipher.Blowfish.MODE_ECB
+                key.encode('utf-8'), Crypto.Cipher.Blowfish.MODE_ECB
             )
 
     def decrypt(self, data):