-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cryptography 36.0.2 (and rust support) #657
Comments
Thanks very much. I'm currently working on updating Chaquopy to Python 3.10 (#624), so I'll have a look at updating Cryptography after that. The cleanest solution would probably be to take the existing Rust support from the If anyone else needs a new version of this package, please click the thumbs up button above, and post a comment explaining why you need it. |
First of all, I would like to thank you for creating and sharing Chaquopy. I am truly impressed how easy it is to run Python code on Android using this SDK. |
Would version 36.0.2 be new enough for you? If so, you can try using the wheels built by @emanuele-f at https://github.com/emanuele-f/chaquopy-wheels. If you need a newer version than that, please let me know exactly which features you need it for. |
Unfortunately, version 36.0.2 is not suitable for me, given that I have to use AESSIV which was introduced with version 37 (see https://cryptography.io/en/latest/hazmat/primitives/aead/#cryptography.hazmat.primitives.ciphers.aead.AESSIV). The performance improvement of ChaCha20Poly1305 introduced with version 39 would be a bonus, but is not strictly necessary. |
I will probably look into building cryptography 38 soon, but I provide no guarantee. In the long term, it would be great to have it as an official supported package. |
Having Cryptography version 38 work with Chaquopy would be great. Just out of curiosity: Is there any particular reason for choosing version 38 rather than the latest version? |
I'm trying to run the latest mitmproxy release, which strictly dependends on version 38 https://github.com/mitmproxy/mitmproxy/blob/9.0.1/setup.py#L79 |
Hi @mhsmith, following the new instructions at https://github.com/chaquo/chaquopy/tree/master/server/pypi to build for python 3.10, I got the same error as before (e.g. see below for PyYAML). I think the problem is that python 3.8 must be used for the conda env (
After switching to python 3.8 in conda,
and now installing them works good. I've then tried to build the
Kindly request your help to proceed |
Please post the full logs for both of those failures: you can attach them as files if they're too large to paste. And please clarify the following:
|
I will redo on a clean environment and post the full logs. Do you confirm that to build for python 3.10 I have to use |
Any |
Mmm, but some tools that are used to build the wheels does not seem to support python 3.10 (for example, yaml/pyyaml#416), so I cannot see how this can work, this is why I thought that some step was wrong, so tried using python 3.8 to run build-wheel. Anyway, here are the steps following the server/pypi instructions, which lead to the error above (using latest chaquopy master):
It happened using python 3.8 in the conda env, but using
No. Following server/pypi instructions, it stills fails at the pip install step. Here is my commands:
In essence, without modifying the requirements.txt file, I cannot even reach the build step.
|
I couldn't reproduce the PyYAML problem at first, because it looks like it falls back to a pure-Python mode when the build machine doesn't have yaml.h available. Anyway, I've now updated it to a version which has manylinux wheels on PyPI, so that shouldn't be a problem anymore. And I've updated several other requirements which also weren't compatible with Python 3.10. Thanks for reporting that. So it should now be possible to run build-wheel with Python 3.8, 3.9 or 3.10. For Python packages it will then launch a subprocess to do the actual build, with a version matching your |
Hi Malcolm, thanks for the fixes. I confirm that building for python 3.10 works correctly now. I can successfully build the new cryptography wheels, but I'm running into an issue with OpenSSL at runtime. The following error is thrown after cryptography is imported:
Here is the full log: openssl_error.txt This is the wheel I've built that throws the above error: cryptography-38.0.4-0-cp310-cp310-android_21_x86.zip (rename to The error is thrown here: binding.py#L176. This is the relevant issue I've found: openssl/openssl#19067 . It seems like OpenSSL is trying to load the "legacy" provider as a shared library via How can we address this? |
Can you create a fork of this repository and push the files you used to build this wheel? It would also be useful to include a README file which includes the instructions above, updated as necessary to reflect how you built this wheel. |
I've bypassed the above error by removing the I've uploaded the new wheels to https://github.com/emanuele-f/chaquopy-wheels . @newfix you can also find there the cryptography 39.0.2 modules cooked just for you ;) Please give it a try an let me know I've quickly verified that the 38.0.4 wheels work correctly on x86 and arm64 in my PCAPdroid-mitm plugin. On armv7, however, I get |
Thanks: there are some related notes about the OpenSSL legacy provider in #688. |
Thank you very much for building this version! I managed to install it. However, at runtime I get the following error: Is this maybe because the briefcase toolchain I am using to build my application is referring to a different version (3.8) of python? Any advice regarding how I could overcome the above error would be appreciated. |
Hi, yeah, all these wheel are only for python 3.10. You should consider upgrading your project to 3.10. I could try building for 3.8, but only after I fix the issues with armv7 |
@newfix: I'm not sure how you managed to install When using Briefcase, the Python version used to run |
Thank you for the feedback. I did not rename the whl file. I just referenced it from my pyproject.toml file. After modifying my build.gradle file to restrict it to building the "arm64-v8a" abi I managed to build my app incl. the cryptography package. However, at runtime I am getting the error reported above. I will set up a Python 3.10 environment as you suggested and try again. |
Using Python 3.10 I got one step further, but now I am getting the following error:
I tried adding the following code snippet, but it did not resolve the issue:
Any idea how I could solve this? |
I just tried version 38 of the cryptography package and it worked 😃 So the issue with the legacy algorithms only exists for version 39. |
My mistake, should be fixed in the new cryptography 39 wheels I've just uploaded |
Now, version 39 is also working fine 😃 @emanuele-f , @mhsmith : Thank you so much for your great work, for sharing it with others and for the support you are providing! |
Happy to share my work and save other people time :) Pre-built wheels available at https://github.com/emanuele-f/chaquopy-wheels Instructions and patches available at https://github.com/emanuele-f/chaquopy/blob/cryptography-wheel/README_cryptography_39.md |
@mhsmith regarding the issue with armv7, the problem is that the libpython that I build is linked against
It seems like I'm forced to link against Edit: small correction, as explained here, Edit2: I was able to workaround this issue by setting the
I've upload the new armv7a wheels. Updating the cryptography build instructions. Edit3: I've just realized that I mistyped |
Thanks very much. |
Hello, |
Yes, it should be possible. In fact, the tokenizers recipe already has a patch for setting up the Rust toolchain, though I haven't tested it with the current version of the build tool. See #1030 for current notes on Rust. |
Here are some notes I took when building the cryptography 36.0.2 python module in Chaquopy, which was needed to run mitmproxy 8.0.0. I hope this will be useful to integrate it in the officially supported packages.
Overview
mitmproxy 8.0.0 depends on the new cryptography 36.x module, for which
rust
is now mandatory.cryptography uses
setuptools_rust
to build native shared objects andpyo3
to invoke them from python.Here the relevant part of the dependency tree:
Other than rust setup for cross-compilation, the problematic part is that cryptography uses
pyo3 v0.15.1
, which requires a python interpreter to be cross-compiled for the target architecture (and it looks for_sysconfigdata*
in the python lib folder). In theory, both pyo3 and cryptography support building abi3 modules, which work regardless of the specific python version and couldbe built without an existing python interpreter. However, this possibility is only added in pyo3 0.16.4, which is not currently supported by cryptography. See PyO3/pyo3#2310 for more details.
So, in order to build the cryptography module, we currently need:
With some tricks, it's possible to compile only the core of python without the need to also cross-compile its dependencies. In fact, the pyo3 shared modules of cryptography will be linked against the soname used by python library shipped with chaquopy.
Preparing the build environment
The following instructions are meant for building on an archlinux host without docker. Install requirements (most requirements not listed here, see
target/Dockerfile
)Copy the Android toolchains used by chaquopy:
To avoid polluting the build machine, use an overlayfs to install all the stuff:
Build and install the exact python version required by Chaquopy:
Install rust and libraries required for cross-compilation in rust
Building for an ABI
These steps must be performed for each Android ABI.
First select the target ABI:
Setup the environment for cross compilation:
Cross compile python
Finally, build cryptography (assume
rust_cross_compile.patch
is applied (see below), which setsPYO3_CROSS_LIB_DIR
):If build successful, you can retrieve the built wheel from outside the overlayfs in the
build-wheel/sysroot
folder.build-wheel patches
rust_cross_compile.patch
:cryptography meta.yaml
:Add rust to the docker build script
The text was updated successfully, but these errors were encountered: