Hello,
I'm running into some problems when I try to re-create a certificate
from a BYTE array.
I use the d2i_X509_bio function to create the Certificate.
When I then try to extract the public key out of the Certificate and I
check the key with RSA_check_key it gives me a Access violation.
I re-build openssl with debug on and it tells me what I though. The
extracted key is invalid.
What am I doing wrong ? Is the way I use the BIO functions to copy the
Array data into a BIO* correct ?
Thanks
Tom
---------------------- the code ----------------------
// the code
BYTE* getPublicKey(BYTE *data, int x509len)
{
RSA* retValue = NULL;
BYTE *x509CertificateAr = (BYTE *)malloc(x509len);
memcpy(x509CertificateAr, data, x509len);
X509* senderPublicCertificate;
BIO *memoryIO =NULL;
memoryIO =BIO_new(BIO_s_mem());
BIO_write(memoryIO, (const char*)x509CertificateAr, x509len);
senderPublicCertificate = d2i_X509_bio( memoryIO,(X509 **)
NULL);
if( !senderPublicCertificate )
return NULL;
retValue = getPublicKey(senderPublicCertificate);
if( !sendersKey )
return NULL;
int keyCheckResult = RSA_check_key(sendersKey);
if( keyCheckResult != 1 )
return NULL;
return retValue;
}
//----------------------------------------------------------------------
--------
// extracts public key from certificate
RSA* getPublicKey(X509 *certificate)
{
EVP_PKEY *key = X509_extract_key(certificate);
return key->pkey.rsa;
}
---------------------- the code ----------------------
The Array data. (It has been converted so it is a readable format, the
BYTE* really contains the binary data)
30:82:02:80:30:82:01:E9:A0:03:02:01:02:02:01:29:30:0D:06:09:2A:86:48:86:
F7:0D:01:01:04:05:00:30:81:C7:31:0B:30:09:06:03:55:04:06:13:02:41:55:31:
11:30:0F:06:03:55:04:08:13:08:56:69:63:74:6F:72:69:61:31:12:30:10:06:03:
55:04:07:13:09:4D:65:6C:62:6F:75:72:6E:65:31:20:30:1E:06:03:55:04:0A:13:
17:6D:61:78:69:20:6D:75:6C:74:69:6D:65:64:69:61:20:50:74:79:20:4C:74:64:
31:1E:30:1C:06:03:55:04:0B:13:15:54:65:63:68:6E:69:63:61:6C:20:44:65:76:
65:6C:6F:70:6D:65:6E:74:31:2E:30:2C:06:03:55:04:03:13:25:6D:61:78:69:20:
6D:75:6C:74:69:6D:65:64:69:61:20:63:65:72:74:69:66:69:63:61:74:65:20:61:
75:74:68:6F:72:69:74:79:31:1F:30:1D:06:09:2A:86:48:86:F7:0D:01:09:01:16:
10:67:72:65:67:40:6D:61:78:69:2E:63:6F:6D:2E:61:75:30:1E:17:0D:39:39:30:
37:30:38:30:31:30:38:30:30:5A:17:0D:30:30:30:37:30:37:30:31:30:38:30:30:
5A:30:44:31:0B:30:09:06:03:55:04:06:13:02:41:55:31:18:30:16:06:03:55:04:
0A:13:0F:6D:61:78:69:20:6D:75:6C:74:69:6D:65:64:69:61:31:1B:30:19:06:03:
55:04:03:13:12:43:6C:69:65:6E:74:20:43:65:72:74:69:66:69:63:61:74:65:30:
81:9F:30:0D:06:09:2A:86:48:86:F7:0D:01:01:01:05:00:03:81:8D:00:30:81:89:
02:81:81:00:EB:32:F1:60:1F:78:FB:7A:40:F8:19:5A:51:C7:3A:57:67:70:E5:B6:
F7:27:10:82:17:7C:5B:5B:B4:20:FC:38:11:8A:2E:9B:86:FD:9E:88:97:18:D9:3E:
90:E7:02:73:7E:D9:64:AA:B5:24:9E:F5:5B:D4:D8:EC:8B:DA:3B:E7:73:AD:0B:CC:
66:BF:D8:1F:8B:34:1B:C3:77:9F:59:40:CF:76:B7:76:D1:D0:03:86:8E:CC:C6:14:
62:F0:56:E2:4E:7A:C8:41:AE:19:BB:63:3D:5F:F9:E9:F5:BF:7D:8B:AA:79:08:3C:
2B:E7:23:B7:DC:54:FA:C9:A9:C6:BB:89:02:03:01:00:01:30:0D:06:09:2A:86:48:
86:F7:0D:01:01:04:05:00:03:81:81:00:77:BF:07:60:7A:18:39:4B:A0:48:CD:CF:
E6:E3:5A:C7:4E:13:81:04:5B:F5:0B:FB:6A:AE:D4:7A:01:A0:AE:03:C5:4E:4E:4E:
4D:39:5E:69:6A:DF:DE:0D:EA:D8:67:04:40:C8:29:22:99:21:41:C7:CE:E2:2C:AB:
8B:5D:BD:C5:17:2E:31:E9:69:6D:47:20:8F:04:A2:25:38:B3:7D:04:7A:92:C5:F3:
32:F3:A5:6C:98:7B:C5:CC:A0:E4:E4:EC:EE:8D:B7:FA:23:DB:89:48:92:8F:F5:59:
05:9C:43:35:E8:80:A4:A4:60:47:C7:C6:DB:12:7E:4D:DE:E3:F3:85
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]