#SSL_connect error

61 messages ยท Page 1 of 1 (latest)

azure vault
sage thorn
#

Is it your own server you're connecting to? It could be a server-sided issue where it's being disconnected

#

Maybe it's your SSL_CTX too, could you show me the options you've set (if you've set any)

frail garnetBOT
#

@azure vault has reached level 1. GG!

azure vault
#
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

int main() {
    struct sockaddr_in addr;
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1) {
        printf("could not create socket\n");
        return -1;
    }

    struct hostent* server = gethostbyname("echo.websocket.org");
    if (!server) {
        printf("could not find server\n");
        return -1;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(443);
    memcpy(&addr.sin_addr.s_addr, server->h_addr, server->h_length);

    if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
        printf("could not connect\n");
        close(sockfd);
        return -1;
    }

    SSL_library_init();
    SSL_load_error_strings();
    OpenSSL_add_ssl_algorithms();

    SSL_CTX* ctx = SSL_CTX_new(TLS_client_method());
    if (!ctx) {
        printf("SSL_CTX_new failed\n");
        return -1;
    }


    SSL* ssl = SSL_new(ctx);
    int ssl_sockfd = SSL_get_fd(ssl);
    SSL_set_fd(ssl, sockfd);

    if (SSL_connect(ssl) == -1) {
        printf("SSL connect failed\n");
        ERR_print_errors_fp(stderr);
        close(sockfd);
        SSL_free(ssl);
        SSL_CTX_free(ctx);
        return -1;
    }

    char req[1024] = "GET / HTTP/1.1\r\nHost:echo.websocket.org\r\n\r\n";
    SSL_write(ssl, req, strlen(req));

    char resp[1024] = {0};
    SSL_read(ssl, resp, strlen(resp));

    printf("received: %s", resp);
   
    SSL_shutdown(ssl);
    SSL_free(ssl);
    close(sockfd);
    SSL_CTX_free(ctx);

    return 0;
}
#

im using the ws echo site because eventually i want to use websockets with this

#

but first, i want a simple https get request like this:

#

its not even getting to the SSL_write though heh

azure vault
#

all with the same error

sage thorn
#

it took me A WHILE I'm sorry

#
int ssl_sockfd = SSL_get_fd(ssl);
```getting rid of this fixed it
azure vault
#

!!

sage thorn
#

no hold on

#

nope sorry!

#

๐Ÿ˜ญ

azure vault
#

lmao im probably doing something terribly wrong

#

i dont often use C

#

im not a low level guy

sage thorn
#

it works fine on other websites

azure vault
#

why

sage thorn
#

no idea I'll try finding out

azure vault
#

:(

sage thorn
#

hmm

sage thorn
azure vault
#

how do u even debug something like this lmfao

#

scour forums?

sage thorn
azure vault
#

ive done a bit of that already..

sage thorn
#

right it did say something about it supporting both HTTP & WS

#

SSL_set_tlsext_host_name should do it

azure vault
#

oop

frail garnetBOT
#

@azure vault has reached level 2. GG!

sage thorn
azure vault
#

a blank response is better than an error! i suppose

sage thorn
#

ah it's the strlen

#

change it to sizeof(resp)

azure vault
#

:(

#

OH

#

wtf is that

sage thorn
#

sorry for the ssl_write keep it the same

azure vault
#

<= 0 inside

#

of

#

1se

#

YAYYY

#

IT WORK

#

TY

sage thorn
#

๐Ÿ™