472,985 Members | 3,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 software developers and data experts.

PHP's openssl_sign() using M2Crypto?

KW
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
May 21 '06 #1
5 4101
KW
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
May 21 '06 #2
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.

May 22 '06 #3
KW
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
May 22 '06 #4
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

May 23 '06 #5
KW
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
May 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
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....
5
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...
4
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...
1
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...
8
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 ...
8
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...
10
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....
7
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?
0
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...
2
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...
2
isladogs
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...
0
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...
0
tracyyun
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...
2
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...
4
NeoPa
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 :...
0
isladogs
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...
0
isladogs
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...
4
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.