-
Notifications
You must be signed in to change notification settings - Fork 71
Importing public keys #1
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Oh yes, the functions are in X.509 handling is a bit weak at the moment, it will decode the certificate into an object, but there's no function to decode the public key object and set all of its properties based on key type (e.g. RSA, DSA, ECDSA). This would be pretty simple to do based on what you see in |
Realised the docs for util functions weren't generating (fixed it), here's the certificate import: http://python-pkcs11.readthedocs.io/en/latest/api.html#module-pkcs11.util.x509 If you felt able to submit a PR for importing the key from a certificate object, here's how we decode the ASN.1 object for an X.509 certificate: https://github.com/danni/python-pkcs11/blob/master/pkcs11/util/x509.py#L29 -- you want to pull out the You'd then need a mapping from algorithm OIDs (e.g. RSA) to the existing decode utils within python-pkcs11 which you could pass |
For ECDH, the you just need to decode the the certificate and pass the When deriving shared keys, the other user's EC_POINT (still X9.62 DER encoded) is passed as a mechanism parameter. See http://python-pkcs11.readthedocs.io/en/latest/applied.html#ec-diffie-hellman |
Thank you for your reply. I finally succeeded with using the packages of cryptography and pyasn1. It might appear a bit awkward, but it works for me. This is what I did so far: Importing the needed modules: Reading the x509 certificate: Retrieving the public key from certificate: To parse the ASN.1 information I used the following code from
Finally I had to prepend an identifier for the regarding uncompressed elliptic curve (0x0461): As |
Do you have an example key/code, I can clean this up and include utilities/documentation for you. |
What exactly do you mean by an example key/code? |
I meant an example certificate.
…On Wed, 28 Jun 2017 at 16:46, Ovomaltine85 ***@***.***> wrote:
What exactly do you mean by an example key/code?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAH5wGGWQhxazcaCz7l7B8vUhCSzCfu2ks5sIfa0gaJpZM4OEW0Z>
.
|
Sorry for late reply. Unfortunately I cannot post here the certificate I used for testing. But the workaround I suggested should work with any X.509 certificate which is PEM-encoded and is based on a secp384r1 Elliptic Curve. |
I've added a new function to master called |
I tested your fix and got the following result. At first I downloaded the current master from github, because the enhancement is not part of the current release. I installed the master with Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work. For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj ` So I switched back to the last stable release (0.2.2) and installed it again with pip3. As the new function I tested the new function and got the following error: The variable
How do you produce the parameter (pubdata) for |
Ah, so you're passing just the
|
Yeah, that works better if I pass the certificate directly in DER format to the function. So far it works as it gives me now the EC_POINT attribute. But I cannot pass this value directly to the Thank you! |
It should give you the What HSM are you running against? If it's SoftHSM v2.2 it had a mistake in it's encoding/decoding of EC_POINT on some Linux, that SoftHSM v2.3 appears to fix (not entirely sure on what was going on there, but I was getting substrate underrun issues). Also make sure you have the latest python-pkcs11, because I cleaned up some of my encoding handling to make sure I was in the right form, with the right number of DER wrappers (urgh). I'll write a test of doing ECDH against an external crypto platform to make sure there are no more secret interchange issues. |
It turns out the standard actually explains the disparity:
I'm adding a flag to |
Here's what I've added to the tests:
|
Hi!
Thank you for this great library and the effort you invested. I tested a lot and it really works well.
I've one question regarding the derivation of a shared secret when using EC. How can public keys be imported, which are part of a x509 certificate? I read in the documentation something about a function called
import_key()
, but I did not found it. Is it already implemented?Unfortunately the examples and test file always generate new keys, but I need to get the public key from an existing x509.
Thank you!
The text was updated successfully, but these errors were encountered: