【发布时间】:2020-02-14 08:59:50
【问题描述】:
我正在尝试使用 OpenSSL (1.1.1)。但是在写作过程中我得到写作失败(从 ERR_print_errors 获得)。握手成功(返回 1)。我也试图将其限制为 TLS 1.3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
int main(int argc, char **argv) {
char * request = argv[1]
int request_len = strlen(request)
SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
if (ctx == NULL) {ERR_print_errors_fp(stderr);}
long options = SSL_OP_NO_SSLv2 |
SSL_OP_NO_SSLv3 |
SSL_OP_NO_TLSv1 |
SSL_OP_NO_TLSv1_2;
SSL_CTX_set_options(ctx, options);
SSL *ssl = SSL_new(ctx);
if (ssl == NULL) {ERR_print_errors_fp(stderr);}
BIO * bio = BIO_new_connect("google.com:443")
if (bio == NULL) {ERR_print_errors_fp(stderr);}
SSL_set_bio(ssl, bio, bio);
if (SSL_connect(ssl) != 1) {ERR_print_errors_fp(stderr);}
if (SSL_write(ssl, request, request_len) !=1) {ERR_print_errors_fp(stderr);}
}
【问题讨论】:
-
请提供有关错误的更多详细信息,即按照文档使用SSL_get_error。
-
那么你从哪里得到这个“写作失败”然后你声称得到了?我在你的代码中看不到这样的东西。我建议您分享完整的代码以获得可重现的内容,包括程序中的输入。
-
你真的读过 the
SSL_write()documentation吗?您似乎不必费心检查来自SSL_write()的返回码 - 甚至是SSL_connect()。 -
@ZergOvermind:“有完整的代码” - 不是。它有语法错误,没有
main,没有头文件,也没有argv[1]包含的信息。由于您声称收到了一些不在代码中的错误消息,因此它仍然缺少解释您得到什么样的错误。一旦我用正确的东西填补了缺失的部分,它就非常适合我。现在我已经否决了你的问题,因为你似乎不愿意提供完整的信息来重现这个问题 - 这使得回答你的问题变得不可能(就像我说的 - 它对我有用)。 -
还需要指定OpenSSL版本;只有 1.1.1(包括所有补丁)支持 TLS1.3,但 1.1.1 (永远)没有实现 SSL2,所以你不需要排除它,默认构建忽略 SSL3,所以你可能不需要排除它,但您确实需要排除 TLS1.1 (SSL_OP_NO_TLS1_1)。