#SSL_connect error
61 messages ยท Page 1 of 1 (latest)
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)
no, its not my own server
@azure vault has reached level 1. GG!
#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
ive tried TLS_method() and a couple other methods
all with the same error
ah goodness me
it took me A WHILE I'm sorry
int ssl_sockfd = SSL_get_fd(ssl);
```getting rid of this fixed it
!!
lmao im probably doing something terribly wrong
i dont often use C
im not a low level guy
why
no idea I'll try finding out
hmm
I mean this is just weird. With my own HTTP client it seems to work fine for google.com and many others but not social.krunker.io and echo.websocket.org
most probably ๐ญ
my god..
right it did say something about it supporting both HTTP & WS
SSL_set_tlsext_host_name should do it
oop
@azure vault has reached level 2. GG!
SSL_set_tlsext_host_name(your_ssl_obj, "echo.websocket.org")
sorry for the ssl_write keep it the same
๐