关于 SSL_connect 和 HTTPS 的查询
Query regarding SSL_connect and HTTPS
我想通过代理服务器发送一个 HTTPS 请求,并获取该站点的着陆页 HTML。套接字创建进行得很顺利,但是当我想与服务器建立 SSL 连接时,它给了我一个 "Aborted (Core Dumped)" 错误。我已将原因缩小到 SSL_connect 函数。当我尝试在没有代理服务器的情况下执行相同操作时(使用 struct addrinfo 而不是 struct sockaddr,因为我需要进行 DNS 查询以获取 IP),它运行良好并且我能够获得有效的 HTTP 响应以及 HTML。有人可以帮我吗?
SSL_library_init();
SSL_load_error_strings();
ssl_ctx = SSL_CTX_new(SSLv23_client_method ());
int sockfd2 = socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in httpsProxy;
httpsProxy.sin_family = AF_INET;
httpsProxy.sin_addr.s_addr = inet_addr("<insert IP>");
httpsProxy.sin_port = htons(13128);
connect(sockfd2,(struct sockaddr *)&httpsProxy,sizeof(httpsProxy));
SSL *conn = SSL_new(ssl_ctx);
SSL_set_fd(conn, sockfd2);
int err = SSL_connect(conn);
您需要连接到代理并请求它连接到目标 HTTPS 服务器,没有 使用 SSL/TLS 与代理通信时,仅当成功 然后在与 HTTPS 服务器通信后通过 SSL_connect()
执行 SSL/TLS 握手,不再与代理通信。
SSL_library_init();
SSL_load_error_strings();
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in httpsProxy = {};
httpsProxy.sin_family = AF_INET;
httpsProxy.sin_addr.s_addr = inet_addr("<proxy IP>");
httpsProxy.sin_port = htons(13128);
// connect to proxy...
if (connect(sockfd, (struct sockaddr *)&httpsProxy, sizeof(httpsProxy)) < 0)
{
...
close(sockfd);
return;
}
// ask proxy to connect to target HTTPS server...
if (!<connect proxy to HTTPS server>)
{
...
close(sockfd);
return;
}
// NOW start SSL/TLS with HTTPS server...
ssl_ctx = SSL_CTX_new(SSLv23_client_method ());
SSL *conn = SSL_new(ssl_ctx);
SSL_set_fd(conn, sockfd);
int err = SSL_connect(conn);
...
我想通过代理服务器发送一个 HTTPS 请求,并获取该站点的着陆页 HTML。套接字创建进行得很顺利,但是当我想与服务器建立 SSL 连接时,它给了我一个 "Aborted (Core Dumped)" 错误。我已将原因缩小到 SSL_connect 函数。当我尝试在没有代理服务器的情况下执行相同操作时(使用 struct addrinfo 而不是 struct sockaddr,因为我需要进行 DNS 查询以获取 IP),它运行良好并且我能够获得有效的 HTTP 响应以及 HTML。有人可以帮我吗?
SSL_library_init();
SSL_load_error_strings();
ssl_ctx = SSL_CTX_new(SSLv23_client_method ());
int sockfd2 = socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in httpsProxy;
httpsProxy.sin_family = AF_INET;
httpsProxy.sin_addr.s_addr = inet_addr("<insert IP>");
httpsProxy.sin_port = htons(13128);
connect(sockfd2,(struct sockaddr *)&httpsProxy,sizeof(httpsProxy));
SSL *conn = SSL_new(ssl_ctx);
SSL_set_fd(conn, sockfd2);
int err = SSL_connect(conn);
您需要连接到代理并请求它连接到目标 HTTPS 服务器,没有 使用 SSL/TLS 与代理通信时,仅当成功 然后在与 HTTPS 服务器通信后通过 SSL_connect()
执行 SSL/TLS 握手,不再与代理通信。
SSL_library_init();
SSL_load_error_strings();
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in httpsProxy = {};
httpsProxy.sin_family = AF_INET;
httpsProxy.sin_addr.s_addr = inet_addr("<proxy IP>");
httpsProxy.sin_port = htons(13128);
// connect to proxy...
if (connect(sockfd, (struct sockaddr *)&httpsProxy, sizeof(httpsProxy)) < 0)
{
...
close(sockfd);
return;
}
// ask proxy to connect to target HTTPS server...
if (!<connect proxy to HTTPS server>)
{
...
close(sockfd);
return;
}
// NOW start SSL/TLS with HTTPS server...
ssl_ctx = SSL_CTX_new(SSLv23_client_method ());
SSL *conn = SSL_new(ssl_ctx);
SSL_set_fd(conn, sockfd);
int err = SSL_connect(conn);
...