Sorry, first mistake was semicolon after
if (connection->ssl == NULL);
> Hello,
>
> I am developing an client application using OpenSSL C API. I have an
> error in the this code:
>
> /* connection struct consists of SSL_CTX, SSL and BIO pointers */
> ...
> connection->ctx = SSL_CTX_new(SSLv23_client_method());
> if (connection->ctx == NULL)
> {
> DEBUG_MESSAGE("SSL_CTX_new failed\n");
> DEBUG(ERR_print_errors_fp(stdout));
> return NULL;
> }
> if (!SSL_CTX_load_verify_locations(connection->ctx, NULL,
> "../share/xclient/certificates/"))
> {
> DEBUG_MESSAGE("SSL_CTX_load_verify_locations failed\n");
> DEBUG(ERR_print_errors_fp(stdout));
> return NULL;
> }
> connection->bio = BIO_new_ssl_connect(connection->ctx);
> if (connection->bio == NULL)
> {
> DEBUG_MESSAGE("BIO_new_ssl_connect failed\n");
> DEBUG(ERR_print_errors_fp(stdout));
> return NULL;
> }
> BIO_get_ssl(connection->bio, &connection->ssl);
> if (connection->ssl == NULL);
> {
> DEBUG_MESSAGE("BIO_get_ssl failed\n");
> DEBUG(ERR_print_errors_fp(stdout));
> return NULL;
> }
> SSL_set_mode(connection->ssl, SSL_MODE_AUTO_RETRY);
> BIO_set_conn_hostname(connection->bio,
> xapi_get_dsnp_server_name(xapi_get_http_server_name(uri)));
> if (BIO_do_connect(connection->bio) < 1)
> {
> DEBUG_MESSAGE("BIO_do_connect failed\n");
> DEBUG(ERR_print_errors_fp(stdout));
> return NULL;
> }
> if (SSL_get_verify_result(connection->ssl) != X509_V_OK)
> {
> DEBUG_MESSAGE("SSL_get_verify_result failed\n");
> DEBUG(ERR_print_errors_fp(stdout));
> return NULL;
> }
> ...
>
> After BIO_get_ssl function call SSL pointer is NULL. If I comment out
> the return from the function after this error, BIO_do_connect fails with
> message:
>
> 3078686456:error:0200206F:system library:connect:Connection
> refused:bss_conn.c:269:host=localhost:33500
> 3078686456:error:20073067:BIO routines:CONN_STATE:connect
> error:bss_conn.c:273:
>
> This is my makefile:
>
> CC = gcc
> TARGET = ../../bin/xtool
> CFLAGS = -Wall -ansi -D_REENTERANT -DXCOMMON_DEBUG -I../
> -I/usr/include/glib-1.2 -I/usr/lib/glib/include
> LIBS = -lcurl -lglib -lcrypto -lssl
> SOURCES = main.c\
> ../xapi/api.c
> all:
> $(CC) -o $(TARGET) $(CFLAGS) $(LIBS) $(SOURCES)
>
> What I am doing wrong?
>
> Sincerely, Kyrylo.
>
> ______________________________________________________________________
> OpenSSL Project http://www.openssl.org
> User Support Mailing List [email protected]
> Automated List Manager [email protected]
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]