I'm trying to convert some PHP code using OpenSSL to Python and I'm stuck
on openssl_sign() which uses an RSA private key to compute a signature.
Example PHP code:
$privkeyid = openssl_get_privatekey($priv_key, $key_pass);
openssl_sign($data, $signature, $privkeyid);
openssl_free_key($privkeyid);
I've tried several permutations of the stuff in M2Crypto.EVP but I can't get
it to work...
The openssl module in PHP basicly does this (C code):
EVP_SignInit(&md_ctx, EVP_sha1());
EVP_SignUpdate(&md_ctx, data, data_len);
EVP_SignFinal(&md_ctx, sigbuf, &siglen, pkey);
Looks like some magic is used to get pkey, I think that's what I'm missing.
See php_openssl_evp_from_zval() in PHP's ext/openssl/openssl.c.
I've tried the following:
key = M2Crypto.EVP.load_key(keyfile, lambda x: passphr)
hmac = M2Crypto.EVP.HMAC(key, 'sha1')
hmac.update(message)
hmac.final()
But this results in:
File "/usr/lib/python2.4/site-packages/M2Crypto/EVP.py", line 39, in __init__
m2.hmac_init(self.ctx, key, self.md)
TypeError: expected a readable buffer object
Segmentation fault
Unfortunately M2Crypto documentation is practically nonexistent..
Best regards,
--
Konrad 5 4101
On 2006-05-20, KW wrote: I'm trying to convert some PHP code using OpenSSL to Python and I'm stuck on openssl_sign() which uses an RSA private key to compute a signature.
I think basicly my question is: how do I extract the key from a private
key in M2Crypto?
Best regards,
--
Konrad
KW wrote: The openssl module in PHP basicly does this (C code): EVP_SignInit(&md_ctx, EVP_sha1()); EVP_SignUpdate(&md_ctx, data, data_len); EVP_SignFinal(&md_ctx, sigbuf, &siglen, pkey);
Looks like some magic is used to get pkey, I think that's what I'm missing. See php_openssl_evp_from_zval() in PHP's ext/openssl/openssl.c.
I've tried the following: key = M2Crypto.EVP.load_key(keyfile, lambda x: passphr) hmac = M2Crypto.EVP.HMAC(key, 'sha1') hmac.update(message) hmac.final()
Does this work?:
key = M2Crypto.EVP.load_key(keyfile, lambda x: passphr)
key.sign_init()
key.sign_update(message)
signature = key.final()
Unfortunately M2Crypto documentation is practically nonexistent..
A lot of the OpenSSL documentation works fine, the names are usually
straight mapping.
On 2006-05-22, he****@osafoundation.org wrote: Does this work?:
key = M2Crypto.EVP.load_key(keyfile, lambda x: passphr) key.sign_init() key.sign_update(message) signature = key.final()
No, I get this:
AttributeError: PKey instance has no attribute 'sign_init'
Best regards,
--
Konrad
That is really strange, because PKey has had sign_init method since
2004. That code works for me (just tested). What version of M2Crypto
are you using? I'd advice you upgrade to 0.15 if possible. See http://wiki.osafoundation.org/bin/vi...ts/MeTooCrypto
--
Heikki Toivonen
On 2006-05-23, he****@osafoundation.org wrote: That is really strange, because PKey has had sign_init method since 2004. That code works for me (just tested). What version of M2Crypto are you using? I'd advice you upgrade to 0.15 if possible. See
http://wiki.osafoundation.org/bin/vi...ts/MeTooCrypto
Great! I was using 0.13.1 from both Debian en Ubuntu and I thought no
further development was done on it..
It would be nice to get this version into Debian.
Best regards,
--
Konrad This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Carl Waldbieser |
last post by:
I tried to adapt the instructions for building the M2Crypto module
(http://sandbox.rulemaker.net/ngps/m2/INSTALL.html) to build a version
compatible with Python2.3, but I've had some mixed results....
|
by: jsmilan |
last post by:
Hi, all;
I'm strictly an amateur developer who has dabbled in a half dozen
languages on eight or nine systems over 20 years or so. I have never
devoted the time or energy to thoroughly learn...
|
by: Marc Poulhičs |
last post by:
Hi,
I'm trying to build a system using HTTPS with python clients that have
to verify the server's identity. From the Python document, it seems that
the server's certificate is not veryfied, and...
|
by: morphex |
last post by:
Hi,
I get the following messages running the testall.py script with
m2crypto 0.13, can anyone tell me what's wrong?
.................................................................EEEEEE...
|
by: John Nagle |
last post by:
Here's a wierd problem:
I have a little test case for M2Crypto, which just opens up SSL connections to
web servers and reads their certificates. This works fine.
But if I execute
...
|
by: John Nagle |
last post by:
I've been running M2Crypto successfully using Python 2.4 on Windows 2000,
and now I'm trying to get it to work on Python 2.3.4 on Linux.
Attempting to initialize a context results in
Traceback...
|
by: John Nagle |
last post by:
Here are three network-related exceptions. These
were caught by "except" with no exception type, because
none of the more specific exceptions matched. This
is what a traceback produced:
1....
|
by: John Nagle |
last post by:
Back in March, I posted this:
That was for M2Crypto 0.17.
It's still broken in M2Crypto 0.18.
And there's no RPM or Windows binary.
Nobody actually uses this stuff, do they?
|
by: Heikki Toivonen |
last post by:
I am happy to announce the M2Crypto 0.19 release!
M2Crypto is the most complete Python wrapper for OpenSSL featuring RSA,
DSA, DH, HMACs, message digests, symmetric ciphers (including AES); SSL...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |