Protocol Problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Protocol Problem

Ertel, Holger

Hi,

I’m a newbie in OpenSSL.

I wrote me a SSLClient and a SSLServer for testing OpenSSL under Window2K. I’m using winsockets.

My problem is, when I send the SSL Hello message to the server (with SSL_connect) I get an error (SSL_ERROR_SSL). The errorcode says me, that’s an protocol error. What is wrong on my code?

 

Client:

 

struct sockaddr_in  port;  /* server's address information */

            bool res = false;

 

            m_Sock = (SOCKET)socket (AF_INET, SOCK_STREAM, 0);

            if (m_Sock < 0) return -1;

 

            std::string serverIp = "127.0.0.1";

            int  portnum  = 16688;

 

            //Hier muss noch das Lesen der Konfiguration rein

 

            m_SSLMethod = SSLv2_client_method();

            m_SSLContext = SSL_CTX_new(m_SSLMethod);

           

            port.sin_family = AF_INET;

            port.sin_addr.S_un.S_addr = inet_addr(serverIp.c_str());

            port.sin_port = htons(portnum);

            memset(&(port.sin_zero),0,8);

            if (connect(m_Sock, (struct sockaddr *)&port,sizeof(struct sockaddr)) != 0)

                        return -1;

            //SSL Verbindung aufbauen

            m_SSLConnection = SSL_new(m_SSLContext);                        

            if ( !m_SSLConnection )

            {

                        closesocket(m_Sock);

                        return ERR_get_error();

            } // if

 

            if (SSL_set_fd(m_SSLConnection,m_Sock))

                        printf("Juhu\n");

            int err2 = SSL_connect(m_SSLConnection);

            if ( err2 < 1)

            {

                        int err = SSL_get_error(m_SSLConnection,err2);

            …

 

 

 

and server:

 

 

struct sockaddr_in  sa_serv; 

            struct sockaddr_in sa_client;

            bool res = false;

            unsigned int listen_sd;

            unsigned int sd;

            int client_len;

            char buf [4096];

 

            // Winsock version

            const int m_iWSVer = 0x00000202;

 

            WSADATA wsaData;

            if ( WSAStartup(m_iWSVer,&wsaData) ) return WSAGetLastError();

 

            // Initialize SSL

            SSL_load_error_strings();

            SSLeay_add_ssl_algorithms();

 

 

            listen_sd = (SOCKET)socket (AF_INET, SOCK_STREAM, 0);

            if (listen_sd < 0) return -1;

 

            std::string serverIp = "127.0.0.1";

            int  portnum  = 16688;

 

            //Hier muss noch das Lesen der Konfiguration rein

 

            SSL_METHOD* pSSLMethod = SSLv2_server_method();

            SSL_CTX* pSSLContext = SSL_CTX_new(pSSLMethod);

           

            sa_serv.sin_family = AF_INET;

            sa_serv.sin_addr.S_un.S_addr = inet_addr(serverIp.c_str());

            sa_serv.sin_port = htons(portnum);

            memset(&(sa_serv.sin_zero),0,8);

            if (bind(listen_sd, (struct sockaddr *)&sa_serv,sizeof(struct sockaddr)) != 0)

            {

                        int err = WSAGetLastError();

                        return -1;

            }

            if (listen(listen_sd,5))

                        return -1;

            client_len = sizeof(sa_client);

            sd = accept(listen_sd,(struct sockaddr *)&sa_client,&client_len);

            if (sd < 0) return -1;

           

            //close(listen_sd);

           

            //SSL Verbindung aufbauen

            SSL* pSSLConnection = SSL_new(pSSLContext);                        

            if ( !pSSLConnection )

            {

                        //closesocket(m_Sock);

                        return ERR_get_error();

            } // if

 

            if (SSL_set_fd(pSSLConnection,sd))

                        printf("Juhu\n");

 

 

            //if ( SSL_connect(m_SSLConnection) == -1 )

            int err_2 = SSL_accept(pSSLConnection);

            if (err_2 < 1)

            …..

 

Thank you for your help.

Reply | Threaded
Open this post in threaded view
|

Re: Protocol Problem

Joseph Oreste Bruni
Check out the "openssl s_client" and "openssl s_server" command line  
tools. These will help you isolate which side might be causing the  
problem.


On Jul 8, 2005, at 9:15 AM, Ertel, Holger wrote:

> Hi,
>
> I’m a newbie in OpenSSL.
>
> I wrote me a SSLClient and a SSLServer for testing OpenSSL under  
> Window2K. I’m using winsockets.
>
> My problem is, when I send the SSL Hello message to the server  
> (with SSL_connect) I get an error (SSL_ERROR_SSL). The errorcode  
> says me, that’s an protocol error. What is wrong on my code?
>
>


smime.p7s (3K) Download Attachment