wbond / oscrypto

Compiler-free Python crypto library backed by the OS, supporting CPython and PyPy
MIT License
318 stars 71 forks source link

Strange error when I try to create a TLSSocket Connection #59

Closed vivekhub closed 2 years ago

vivekhub commented 2 years ago

Using Oscrypto 1.3.0 on a mac M1, I am getting a really strange error when I open a TLSSocket. Something I am doing wrong here? This works on an Intel Mac

Python 3.9.12 (main, Mar 26 2022, 15:44:31) 
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from oscrypto import tls
>>> t=tls.TLSSession(manual_validation=True)
>>> c = tls.TLSSocket('www.google.com', 443, session=t)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/vivekv/Library/Caches/pypoetry/virtualenvs/digital-resilience-pmVk26sL-py3.9/lib/python3.9/site-packages/oscrypto/_mac/tls.py", line 532, in __init__
    self._handshake()
  File "/Users/vivekv/Library/Caches/pypoetry/virtualenvs/digital-resilience-pmVk26sL-py3.9/lib/python3.9/site-packages/oscrypto/_mac/tls.py", line 654, in _handshake
    cipher_suite = int_to_bytes(supported_cipher_suite, width=2)
  File "/Users/vivekv/Library/Caches/pypoetry/virtualenvs/digital-resilience-pmVk26sL-py3.9/lib/python3.9/site-packages/asn1crypto/util.py", line 243, in int_to_bytes
    return value.to_bytes(width, byteorder='big', signed=signed)
OverflowError: int too big to convert
>>> 
wbond commented 2 years ago

This should be fixed on master now. Apparently one of the data types from the Security framework changes from uint32_t on x86_64 to uint16_t on arm64 when running on macOS.