-
Notifications
You must be signed in to change notification settings - Fork 238
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
Implement cryptography as one of the backends #49
Conversation
…nds. Use pycrypto backend by default for RSA. Add to_pem and public_key to EC and RSA keys in order to abstract away backend key implementations and be able to convert between keys. Move base64_to_long and int_arr_to_long to jose.utils to be importable by backends.
…turns six.binary_type - str on PY2, bytes on PY3.
… of deducing it from desired algorithm. This matches behavior of ecdsa backend, which allows signing different digests with same key (provided they are shorter than the key).
First of all, thank you for putting this together. At first glance this looks very good. I don't have time to dive into this tonight, but there are a couple of issues that look like they will be easy to fix.
Those are the only issues that came up from a quick pass through. Thanks again for putting this together. |
Very good observations, will try to fix. Thanks. |
Codecov Report
@@ Coverage Diff @@
## master #49 +/- ##
==========================================
+ Coverage 95.57% 95.64% +0.06%
==========================================
Files 7 12 +5
Lines 542 734 +192
==========================================
+ Hits 518 702 +184
- Misses 24 32 +8
Continue to review full report at Codecov.
|
… which uses an incorrect marker to encode a RSA public key into PEM while using OID.
…rrently expected to be (for compatibility), but pass if it fails. Maybe user just needs one of them, which works, or HMACKey. Function jwk.get_key will still try to import RSAKey or ECKey if needed, and throw an ImportError if unsuccessful.
The RSAKey and ECKey in The Travis configuration file was updated to use tox-travis and now runs tests on newer version of PyPy and also CPython 3.5 and 3.6. |
@zejn This looks great. My apologies for taking so long to take a look. |
Released in 1.4.0 |
This pull request implements (optional) cryptography backend for both EC and RSA.
In order to be able to do that I had to refactor
jose.jwk
to make part of the jwk module importable by the backends. The utility functionsbase64_to_long
andint_arr_to_long
were moved tojose.utils
and classKey
was moved tojose.backends.base
.In order to be able to support conversion and reuse between key implementations, each asymmetric key implementation (EC and RSA) now has two new methods. Method
to_pem
returns PEM encoded key data of six.binary_type. Methodpublic_key
returns public key from a private key or self when the instance represents public key.Existing ECDSA signing implementation from ecdsa python library was moved into
jose.backends.ecdsa_backend
and existing PyCrypto was moved intojose.backends.pycrypto_backend
.Default
ECKey
andRSAKey
are chosen at import time injose/backends/__init__.py
, but a better explicit selection might be useful. RSAKey defaults to pycrypto and fallbacks to cryptography backend and EC defaults to cryptography and fallbacks to ecdsa backend.I've tested on Python 2.7 and Python 3.5.