Hi,
I'm trying to create a little smtp client that could deal with ssl encryption
within a c++ application.
To do that i'm using openssl and following the smtp protocol.
As i understood, i have to initialise the library first and several other
things. I'm doing that:
SSL_load_error_strings();
SSL_library_init();
ctx=SSL_CTX_new(SSLv23_method());
SSL_CTX_set_options(ctx, SSL_OP_ALL);
Then i'm openning a non-secured connection to the server with the BIO objects.
bio=BIO_new_connect((char*)server_address.c_str());
if ( BIO_do_connect(bio) <= 0 )
{
valid=false;
return false;
}
At that point, i can use the bio object to communicate with the
server. I can send an email on a non protected server (so my smtp
protocol is ok).
At the right time i'm sending STARTTLS to the server and it's replying 220
Ready for TLS.
Then, i'm doing that:
SSL * connection=SSL_new(ctx);
SSL_set_bio(connection,bio,bio);
SSL_set_connect_state(connection);
if( SSL_do_handshake(connection) <=0 )
{
return false;
}
The SSL_do_handshake call return something greater than 0 but i always have
these exceptions :
First-chance exception at 0x7c809e3a in app.exe: 0xC0000005: Access violation
reading location 0x6d657270.
First-chance exception at 0x7c809e3a in app.exe: 0xC0000005: Access violation
reading location 0x38303730.
First-chance exception at 0x7c809e3a in app.exe: 0xC0000005: Access violation
reading location 0x08061430.
First-chance exception at 0x7c809e3a in app.exe : 0xC0000005: Access violation
reading location 0x0d300030.
First-chance exception at 0x7c809e3a in app.exe: 0xC0000005: Access violation
reading location 0x908a0200.
First-chance exception at 0x7c809e3a in app.exe : 0xC0000005: Access violation
reading location 0x3d698a0c.
Don't know if it's important because the compiler never stopped on it.
After that i'm sending a EHLO [xxx.xxx.xxx.xxx] command as specified in the rfc
for smtp with STARTTLS.
Then... nothing!!!!
The socket is still opened i can write and read on it but the server never
replied anything.
What am i doing wrong?
I tried to read the s_client.c example but... i'm lost in it! it's
mixing to much things at a time and evenif i can find where the
STARTTLS is sent, i can't figure out what is done before...
Is this because of the exceptions?
Thanks for your help
_________________________________________________________________
Essayez Live.com, votre nouvelle page d'accueil ! Personnalisez-la en quelques
clics pour retrouver tout ce qui vous intéresse au même endroit.
http://www.live.com/getstarted