Hello!
Did you use OpenSSL in a VC++ Component before?
I am developing an ATL component with VC++ in windows 2000 environment but
encountered the problem . I am not sure if I can use OpenSSL function in a
component. For example:
pkey = PEM_read_PrivateKey(fp12, NULL,NULL, NULL);??
Pls give me some help.
Zoe
Details::
Hello!
I am developing an ATL component with VC++ in windows 2000 environment.
Actually, I'd like to use this component in a web server.
When Client wants to connect to the Server, Client downloads this
component---OutCtl from Server.
The task of the component OutCtl is:
1. Read private key of the client ( in a special place of client machine:
key.pem)
2. Do the digital signature
I set one property of the component as Signature.
Then I'd like to pass this property to Client side by VBScript or JavaScript.
I will use that property later.
The function using OpenSSL in my component mainly as the following:
#include openssl/rsa.h
#include openssl/evp.h
#include openssl/objects.h
#include openssl/x509.h
#include openssl/err.h
#include openssl/pem.h
#include openssl/ssl.h
#include string.h
void COutCtl: : DoSignature( )
{
int err;
int sig_len;
unsigned char sig_buf [4096];
static char keyfile[] = D:\key.pem;
static char data[] = I owe you...;
EVP_MD_CTX md_ctx;
EVP_PKEY * pkey;
FILE *fp12;
/* Just load the crypto library error strings,
* SSL_load_error_strings() loads the crypto AND the SSL ones */
/* SSL_load_error_strings();*/
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();
/* Read private key */
fp12 = fopen (keyfile, r+);
if (fp12 == NULL) {
printf (Can't read private key.\n);
exit (1);
}
pkey = PEM_read_PrivateKey(fp12, NULL,NULL, NULL);
fclose (fp12);
if (pkey == NULL) {
ERR_print_errors_fp (stderr);
exit (1);
}
/* Do the signature */
EVP_SignInit (md_ctx, EVP_sha1());
EVP_SignUpdate (md_ctx, data, strlen(data));
sig_len = sizeof(sig_buf);
err = EVP_SignFinal (md_ctx, sig_buf, sig_len, pkey);
if (err != 1) {
ERR_print_errors_fp(stderr);
exit (1);
}
// m_bstrSignature will be passed to the property Signature
m_bstrSignature= (CComBSTR) sig_buf;
EVP_PKEY_free (pkey);
}
STDMETHODIMP COutCtl::get_Signature (BSTR *pval)
{
*pval= m_bstrSignature;
return S_OK;
}
Then in a test page OutCtl.html:
html
head
titleATL 3.0 test pages for object OutCtl/title
/head
body
OBJECT ID =OutCtl CLASSID=CLSID: 48933cd2_etc..
script Language =VBScript
document.write (Hello!! OutCtl.Signature)
/script
/body/html
The component OutCtl passed when building Dll .
When I test another property (a string for testing purpose), The test page
OutCtl.html works. But It loaded extremely slowly when I added the funtion void
COutCtl: : DoSignature( ) in my component. There is no error appeared. Only IE
stopped there when open OutCtl.html. I tried to debug step by step. At last I
found the problem appeared when the first statement needing OpenSSL being used:
key = PEM_read_PrivateKey(fp12, NULL,NULL, NULL);
Actually, I have used the same function of void COutCtl: : DoSignature( ) in a
VC++ Application ( not a ATL Component), And the whole application is OK. I can
print out the Signature.
But Can't I work with Open SSL in a Component? By the way, I have found all the
.h files of OpenSSL in my External Dependencies , such as evp.h, sha.h,
pem.h...Etc. I have set Debug Multithreaded DLL in project setting.
Is there anyone using OPenSSL in a component before?
I do appreciate if you can give me any information about my problem.
Thank you!
Zoe
__
OpenSSL Project http://www.openssl.org
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]