Code Monkey home page Code Monkey logo

beefish's People

Contributors

coleifer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

beefish's Issues

Well it doesn't work anymore https://github.blog/2021-09-01-improving-git-protocol-security-github/

C:\Users\USER>pip install -e git+git://github.com/coleifer/beefish.git#egg=beefish
Obtaining beefish from git+git://github.com/coleifer/beefish.git#egg=beefish
  Cloning git://github.com/coleifer/beefish.git to c:\users\user\src\beefish
  Running command git clone --filter=blob:none --quiet git://github.com/coleifer/beefish.git 'C:\Users\USER\src\beefish'
  fatal: remote error:
    The unauthenticated git protocol on port 9418 is no longer supported.
  Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
  error: subprocess-exited-with-error

  × git clone --filter=blob:none --quiet git://github.com/coleifer/beefish.git 'C:\Users\USER\src\beefish' did not run successfully.
  │ exit code: 128
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git clone --filter=blob:none --quiet git://github.com/coleifer/beefish.git 'C:\Users\USER\src\beefish' did not run successfully.
│ exit code: 128
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

C:\Users\USER>

python 3.4 exceptions when concatenating bytes to str

Hi I am trying to use beefish with python 3.4 and I get the following error (which I don't get with python 2.7):

  File "/Users/cgia/sources/git/backup/backup/utils.py", line 42, in encrypt
     encrypt_file(file, '/secrets.enc', 'p@ssword')
  File "/Users/cgia/sources/git/backup/env/lib/python3.4/site-packages/beefish.py", line 92, in encrypt_file
     encrypt(in_fh, out_fh, key, chunk_size)
  File "/Users/cgia/sources/git/backup/env/lib/python3.4/site-packages/beefish.py", line 62, in encrypt
     buffer += _gen_padding(bytes_read, cipher.block_size)
  File "/Users/cgia/sources/git/backup/env/lib/python3.4/site-packages/beefish.py", line 37, in _gen_padding
    return padding + chr(bflag)
  TypeError: can't concat bytes to str

I was looking at the source and beefish.py line 37:

return padding + chr(bflag)

The python 3.4 documentation for chr() states:
https://docs.python.org/3.4/library/functions.html#chr

chr(i) - Returns the string representing a character whose Unicode code point is the integer i.

While the documentation for 2.7 states:
https://docs.python.org/2.7/library/functions.html#chr

chr(i) - Return a string of one character whose ASCII code is the integer i.

I attempted to add an str.decode() to line 37, to convert the string to bytes and this seems to work but then I run into other exceptions when trying to decode the file, so I decided I might ask you for help.

to test the differences I used virtualenv with 2.7 and pyvenv with 3.4, with 2.7 the code works perfectly.

thanks

Python3.8 AttributeError: module 'time' has no attribute 'clock'

I found this issue while calling beefish.encrypt() in python3.8.

 File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/beefish.py", line 75, in encrypt
    iv = generate_iv(block_size)
  File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/beefish.py", line 45, in generate_iv
    return Random.get_random_bytes(block_size)
  File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/__init__.py", line 41, in get_random_bytes
    return _UserFriendlyRNG.get_random_bytes(n)
  File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 228, in get_random_bytes
    return _get_singleton().read(n)
  File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
    return _UserFriendlyRNG.read(self, bytes)
  File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read
    self._ec.collect()
  File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect
    t = time.clock()
AttributeError: module 'time' has no attribute 'clock'

PyCrypto is calling time.clock() which has been removed.
Also, PyCrypto seems dead: pycrypto/pycrypto#173. People are suggesting to use PyCryptodome a fork from PyCrypto.

Replace pycrypto with pycryptodome

The dependency pycrypto for this package has been discontinued, and they recommend pycryptodome as a drop-in replacement for the older package. (Ref: https://www.pycrypto.org/)

Why does it matter?
In addition to the usage of discontinued library that has a lot of vulnerabilities reported in the recent years, usage of PyCrypto makes BeeFish not fully compatible with Python3.

Being specific, I encountered problems using BeeFish in Python3 environment because the PyCrypto package uses Python2 xrange function several times in its source, which is not available in Python3.

Traceback (most recent call last):
  File "/Users/bikalpa/LP/plugins/tools/pak_creator.py", line 5, in <module>
    from beefish import encrypt
  File "/Users/bikalpa/LP/plugins/env/src/beefish/beefish.py", line 31, in <module>
    from Crypto.Cipher import Blowfish
  File "/Users/bikalpa/LP/plugins/env/lib/python3.9/site-packages/Crypto/Cipher/Blowfish.py", line 120, in <module>
    key_size = xrange(4,56+1)
NameError: name 'xrange' is not defined

Since pycryptodome provides drop-in replacement to pycrypto, I suggest the dependency be updated to pycrytpodome.

Object type <class 'str'> cannot be passed to C code

>>> beefish.encrypt_file("input.png", "output.png" "p@ssword")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\beefish.py", line 127, in encrypt_file
    encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\beefish.py", line 81, in encrypt
    cipher = get_cipher(key, iv)
  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\beefish.py", line 53, in get_blowfish_cipher
    return Blowfish.new(key, Blowfish.MODE_CBC, iv)  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\Blowfish.py", line 146, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\_mode_cbc.py", line 274, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\Blowfish.py", line 77, in _create_base_cipher
    result = start_operation(c_uint8_ptr(key),
  File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Util\_raw_api.py", line 138, 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

My beefish version is 0.2.1

And every other encryption or decryption method have this problem

test cases failed with python 3.6.6

It produces different results every time I run it with the same input and key.

Also I can't decrypt the file on another machine.

Also I found the test has failed.

test_chunk_sizes (__main__.TestEncryptDecrypt) ... ERROR
test_encrypt_decrypt (__main__.TestEncryptDecrypt) ... ERROR
test_key (__main__.TestEncryptDecrypt) ... ERROR
test_stringio (__main__.TestEncryptDecrypt) ... ERROR
test_chunk_sizes (__main__.TestEncryptDecryptAES) ... ok
test_encrypt_decrypt (__main__.TestEncryptDecryptAES) ... ok
test_key (__main__.TestEncryptDecryptAES) ... ok
test_stringio (__main__.TestEncryptDecryptAES) ... ok

======================================================================
ERROR: test_chunk_sizes (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 191, in test_chunk_sizes
    buf, decrypted = self.crypt_data(num_bytes, b'a', chunk_size=i)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 163, in crypt_data
    self.cipher_type)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 122, in encrypt_file
    encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
    cipher = get_cipher(key, iv)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
    return Blowfish.new(key, Blowfish.MODE_CBC, iv)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
    result = start_operation(c_uint8_ptr(key),
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, 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

======================================================================
ERROR: test_encrypt_decrypt (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 178, in test_encrypt_decrypt
    encrypt_flow(b'a')
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 175, in encrypt_flow
    buf, decrypted = self.crypt_data(i, ch)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 163, in crypt_data
    self.cipher_type)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 122, in encrypt_file
    encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
    cipher = get_cipher(key, iv)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
    return Blowfish.new(key, Blowfish.MODE_CBC, iv)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
    result = start_operation(c_uint8_ptr(key),
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, 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

======================================================================
ERROR: test_key (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 184, in test_key
    buf, decrypted = self.crypt_data(128, b'a', self.key, self.key+'x')
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 163, in crypt_data
    self.cipher_type)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 122, in encrypt_file
    encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
    cipher = get_cipher(key, iv)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
    return Blowfish.new(key, Blowfish.MODE_CBC, iv)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
    result = start_operation(c_uint8_ptr(key),
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, 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

======================================================================
ERROR: test_stringio (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 203, in test_stringio
    encrypt(in_buf, out_buf, self.key, i, self.cipher_type)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
    cipher = get_cipher(key, iv)
  File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
    return Blowfish.new(key, Blowfish.MODE_CBC, iv)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
    result = start_operation(c_uint8_ptr(key),
  File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, 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

----------------------------------------------------------------------
Ran 8 tests in 0.262s

FAILED (errors=4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.