cossacklabs / themis

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
https://www.cossacklabs.com/themis
Apache License 2.0
1.85k stars 143 forks source link

Pythemis does not work in virtual environment on macOS 13.3.1(a) #1000

Open radetsky opened 1 year ago

radetsky commented 1 year ago

Describe the bug Impossible to use pythemis.

To Reproduce Steps to reproduce the behavior:

  1. Use macOS 13.3.1(a), M1, python 3.9
  2. Run
    python3 -m vent .python-env 
    source .python-env/bin/activate 
    python3 ./test.py 

    test.py source:

    
    from pythemis import skeygen, scell, smessage
    from base64 import b64encode, b64decode

master_key = skeygen.GenerateSymmetricKey()

cell1 = scell.SCellSeal(key=master_key) cell2 = scell.SCellSeal(passphrase='a password')

plaintext = b'Hello, PyThemis!' context = b'Python context'

encrypted1 = cell1.encrypt(plaintext, context) encrypted2 = cell2.encrypt(plaintext, context)

assert len(encrypted1) > len(plaintext) assert len(encrypted2) > len(plaintext)

print(b64encode(master_key)) print(b64encode(encrypted1)) print(b64encode(encrypted2))

rn_symmetric_key = b'yezqKzmXTFH1/b/o1epvi1usm3dpr03USdhU1aGorhM=' rn_encrypted1 = b'AAEBQAwAAAAQAAAADgAAAAUJkENaFc1anpphYbIO/wEBabtRvjmusafDAkwQZEO2pLZmo5gtOmCT6w==' rn_encrypted2 = b'AAEBQQwAAAAQAAAADgAAABYAAAA41fL+2Ujm7m3XS4ve4QP0p8jONocxvJpHDrPVQA0DABAAWsD16uhZ//X87oE1dA1pfhsbCQtYrFHlR4360pPL' rn_password = b'Passphrase for Themis!' rn_context = b'Themis context'

cell_rn1 = scell.SCellSeal(key=b64decode(rn_symmetric_key)) cell_rn2 = scell.SCellSeal(passphrase=rn_password)

decrypted1 = cell_rn1.decrypt(b64decode(rn_encrypted1), rn_context) decrypted2 = cell_rn2.decrypt(b64decode(rn_encrypted2), rn_context)

print(f"Decrypted from RN with the key: {decrypted1}") print(f"Decrypted from RN with the passphrase: {decrypted2}")


4. See the following error:

Traceback (most recent call last): File "/Users/rad/git/playground/python/themis-venv-test/./themis_without_session.py", line 4, in master_key = skeygen.GenerateSymmetricKey() File "/Users/rad/git/playground/python/themis-venv-test/.python-env/lib/python3.9/site-packages/pythemis/skeygen.py", line 71, in GenerateSymmetricKey res = themis.themis_gen_sym_key(None, byref(key_length)) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/ctypes/init.py", line 379, in getattr func = self.getitem(name) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/ctypes/init.py", line 384, in getitem func = self._FuncPtr((name_or_ordinal, self)) AttributeError: dlsym(RTLD_DEFAULT, themis_gen_sym_key): symbol not found


**Expected behavior**

b'heyFNItlkmGel9THxjZChouchzqY2EKOzRlfxn+jWc0=' b'AAEBQAwAAAAQAAAAEAAAADwof9PffphzYc1sqEhAeK3LJifMYGiVfSY33FluML3vzXsbPmDipBNt7smB' b'AAEBQQwAAAAQAAAAEAAAABYAAADjy/nYs0irxvGjZGd6Mtk7KimMCKjHGH7icxc0QA0DABAA5gwWbybQKNmveAa/GotVzd1N6xq5MF9BVEgooRXL90U=' Decrypted from RN with the key: b'Hello, Themis!' Decrypted from RN with the passphrase: b'Hello, Themis!'


**Environment (please complete the following information):**
- OS: macOS Ventura 13.3.1(a)
- Hardware: M1 MacBook Pro 
- Themis version: 0.14.10
- Installation way:
   - [x] via package manager
   - [ ] built from source

**Additional context**
Without using a virtual environment it works successfully on the same instance of OS.