simple linux .c ssl connection file not working correctly
$10-30 USD
Completed
Posted almost 4 years ago
$10-30 USD
Paid on delivery
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);
}
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 soon as possible for you. We can discuss more in chat about your work.
So, I will look forward to hearing from you.
Thank you.
Stay home, be safe, and take care.