Hi,
I am just beginning with SSL and for now I am trying to get client and
server talking only this is not happening.
The client and server code is provided below. No certification needed at
this time.
Any ideas what I am doing wrong?
Kostia
[EMAIL PROTECTED]
Server:
+++++++++++++++
/* SSL preliminaries. We keep the certificate and key with the context. */
SSL_load_error_strings();
SSLeay_add_ssl_algorithms();
ctx = SSL_CTX_new (SSLv3_server_method());
CHK_NULL(ctx);
listen_sd = socket (AF_INET, SOCK_STREAM, 0);
memset (&sa_serv, '\0', sizeof(sa_serv));
sa_serv.sin_family = AF_INET;
sa_serv.sin_addr.s_addr = INADDR_ANY;
sa_serv.sin_port = htons (1111); /* Server Port number */
err = bind(listen_sd, (struct sockaddr*) &sa_serv,
sizeof (sa_serv));
/* Receive a TCP connection. */
err = listen (listen_sd, 5);
client_len = sizeof(sa_cli);
sd = accept (listen_sd, (struct sockaddr*) &sa_cli, &client_len);
closesocket (listen_sd);
printf ("Connection from %lx, port %x\n", sa_cli.sin_addr.s_addr,
sa_cli.sin_port);
/* ----------------------------------------------- */
/* TCP connection is ready. Do server side SSL. */
ssl = SSL_new (ctx);
//CHK_NULL(ssl);
SSL_set_fd (ssl, sd);
err = SSL_accept (ssl);
//CHK_SSL(err);
/* Get the cipher - opt */ //WILL RETURN NONE
printf ("SSL connection using %s\n", SSL_get_cipher (ssl));
/* DATA EXCHANGE - Receive message and send reply. */
while((err = SSL_read (ssl, buf, sizeof(buf) - 1)) == -1)
++++++++++++++++++++++++++++++++++++++++++++++
CLIENT
++++++++++++++++++++++++++++++++++++++++++++++
SSL_load_error_strings();
SSLeay_add_ssl_algorithms();
ctx = SSL_CTX_new (SSLv3_client_method());
CHK_NULL(ctx);
/* ----------------------------------------------- */
/* Create a socket and connect to server using normal socket calls. */
sd = socket (AF_INET, SOCK_STREAM, 0);
CHK_ERR(sd, "socket");
memset (&sa, '\0', sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr ("127.0.0.1"); /* Server IP */
sa.sin_port = htons (1111); /* Server Port number */
err = connect(sd, (struct sockaddr*) &sa, sizeof(sa));
/* ----------------------------------------------- */
/* Now we have TCP conncetion. Start SSL negotiation. */
ssl = SSL_new (ctx);
SSL_set_fd (ssl, sd);
err = SSL_connect (ssl);
/* Following two steps are optional and not required for
data exchange to be successful. */
/* Get the cipher - opt */
printf ("SSL connection using %s\n", SSL_get_cipher (ssl));
/* --------------------------------------------------- */
/* DATA EXCHANGE - Send a message and receive a reply. */
err = SSL_write (ssl, "Hello World!", strlen("Hello World!"));
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]