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 4129
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |