Completed

simple linux .c ssl connection file not working correctly

Hi

We have this sslconnect.c

Then we call it from other program with

snprintf(sendbuffer,4096, "GET /[login to view URL] HTTP/1.0\r\n\r\n");

SSL_write(ssl, sendbuffer, strlen(sendbuffer));

bzero(buffer,sizeof(buffer));

if (SSL_read(ssl, buffer, 2048) <= 0) {

goto end; // disconnected

}

alarm(0);

printf("What is ssl buffer: %s",buffer);

But it seems no matter what it not getting reply data from remote web server.

sslconnect.c

*

* When using sslconnect, you need to use

SSL_write(ssl, buffer, length) instead of write(sock, buffer, length) and

SSL_read(ssl, buffer, length) instead of read(sock, buffer, length).

* When you are finished using the ssl connection call ssldisconnect().

*/

#include <sys/types.h>

#include <sys/socket.h>

#include <netdb.h>

#include <openssl/crypto.h>

#include <openssl/ssl.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

/* these are global variables that you need to have declared whereever you use sslconnect */

int check;

int sock;

SSL *ssl;

SSL_CTX *ssl_ctx;

void sslconnect(int connectport, char *scanip)

{

struct addrinfo hints, *res;

char strport[16];

/* initialize SSL context */

SSL_library_init();

ssl_ctx = SSL_CTX_new(SSLv23_client_method());

ssl = SSL_new(ssl_ctx);

memset(&hints, 0, sizeof hints);

hints.ai_family = AF_INET;

hints.ai_socktype = SOCK_STREAM;

sprintf(strport, "%d", connectport);

getaddrinfo(scanip, strport, &hints, &res);

sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);

if(connect(sock, res->ai_addr, res->ai_addrlen) == -1) {

check = -1;

return;

}

/* initialize SSL connection */

SSL_set_fd(ssl, sock);

if(SSL_connect(ssl) == -1) {

check = -1;

close(sock);

return;

}

check = 1;

return;

}

void ssldisconnect()

{

/* cleanup */

SSL_shutdown(ssl);

close(sock);

SSL_free(ssl);

SSL_CTX_free(ssl_ctx);

}

Skills: Linux, C Programming, C++ Programming, PHP, Software Architecture

See more: simple linux samba apache mysql, simple linux server, ssl secure file transfer, ssl checker, openssl s_client debug ssl handshake, openssl s_client, unable to get local issuer certificate, openssl tls, google ssl checker, test https connection linux, openssl connect:errno=110, set simple linux server tasks, simple flash login buttons fla file, linux script replace string file, simple linux system information php script, trusted platform module security hardware working correctly, iseries ssl connection, protected secure ssl connection oscommerce, trusted platform module tpm security hardware working correctly, linux http request post file

About the Employer:
( 61 reviews ) Copenhagen K, Sweden

Project ID: #25856318

Awarded to:

vano101

Hello I have over 20 years of experience with C and C++ including working with OpenSSL, Linux and Windows.

$33 USD in 1 day
(1883 Reviews)
8.0

3 freelancers are bidding on average $19 for this job

asifmahmudpro

Hello there, I understand your project description. I am highly interested to work on this project. I can do this work perfectly for you. I have all the skills that you need for your work. I will do this project as so More

$10 USD in 2 days
(0 Reviews)
0.0
MelodicVibez

I can fix it in short.........................................................................................

$15 USD in 1 day
(0 Reviews)
0.0