mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-07 21:53:41 +08:00
Fix tls_init bug
This commit is contained in:
@@ -2684,6 +2684,7 @@ int tls_init(TLS_CONNECT *conn, TLS_CTX *ctx)
|
|||||||
|
|
||||||
memset(conn, 0, sizeof(*conn));
|
memset(conn, 0, sizeof(*conn));
|
||||||
|
|
||||||
|
conn->is_client = ctx->is_client; // TODO: remove conn->is_client
|
||||||
conn->protocol = ctx->protocol;
|
conn->protocol = ctx->protocol;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ int tls_send_record(TLS_CONNECT *conn)
|
|||||||
while (left) {
|
while (left) {
|
||||||
n = tls_socket_send(conn->sock, conn->record + conn->record_offset, left, 0);
|
n = tls_socket_send(conn->sock, conn->record + conn->record_offset, left, 0);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EAGAIN && errno == EWOULDBLOCK) {
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
return TLS_ERROR_SEND_AGAIN;
|
return TLS_ERROR_SEND_AGAIN;
|
||||||
} else if (errno == EINTR) {
|
} else if (errno == EINTR) {
|
||||||
continue;
|
continue;
|
||||||
@@ -2722,13 +2722,13 @@ int tls12_do_connect(TLS_CONNECT *conn)
|
|||||||
} else if (ret == TLS_ERROR_SEND_AGAIN) {
|
} else if (ret == TLS_ERROR_SEND_AGAIN) {
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
FD_SET(conn->sock, &rfds);
|
FD_SET(conn->sock, &wfds);
|
||||||
select(conn->sock + 1, &rfds, &wfds, NULL, NULL);
|
select(conn->sock + 1, &rfds, &wfds, NULL, NULL);
|
||||||
|
|
||||||
} else if (ret == TLS_ERROR_RECV_AGAIN) {
|
} else if (ret == TLS_ERROR_RECV_AGAIN) {
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
FD_SET(conn->sock, &wfds);
|
FD_SET(conn->sock, &rfds);
|
||||||
select(conn->sock + 1, &rfds, &wfds, NULL, NULL);
|
select(conn->sock + 1, &rfds, &wfds, NULL, NULL);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -122,6 +122,15 @@ bad:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tls_ctx_init(&ctx, TLS_protocol_tlcp, TLS_client_mode) != 1) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (tls_ctx_set_cipher_suites(&ctx, client_ciphers, sizeof(client_ciphers)/sizeof(client_ciphers[0])) != 1) {
|
||||||
|
fprintf(stderr, "%s: context init error\n", prog);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
if (tls_socket_lib_init() != 1) {
|
if (tls_socket_lib_init() != 1) {
|
||||||
error_print();
|
error_print();
|
||||||
return -1;
|
return -1;
|
||||||
@@ -145,12 +154,6 @@ bad:
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tls_ctx_init(&ctx, TLS_protocol_tlcp, TLS_client_mode) != 1
|
|
||||||
|| tls_ctx_set_cipher_suites(&ctx, client_ciphers, sizeof(client_ciphers)/sizeof(client_ciphers[0])) != 1) {
|
|
||||||
fprintf(stderr, "%s: context init error\n", prog);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cacertfile) {
|
if (cacertfile) {
|
||||||
if (tls_ctx_set_ca_certificates(&ctx, cacertfile, TLS_DEFAULT_VERIFY_DEPTH) != 1) {
|
if (tls_ctx_set_ca_certificates(&ctx, cacertfile, TLS_DEFAULT_VERIFY_DEPTH) != 1) {
|
||||||
fprintf(stderr, "%s: context init error\n", prog);
|
fprintf(stderr, "%s: context init error\n", prog);
|
||||||
@@ -199,9 +202,6 @@ bad:
|
|||||||
fclose(outcertsfp);
|
fclose(outcertsfp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tls_shutdown(&conn);
|
|
||||||
// return 0;
|
|
||||||
|
|
||||||
if (get) {
|
if (get) {
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
timeout.tv_sec = TIMEOUT_SECONDS;
|
timeout.tv_sec = TIMEOUT_SECONDS;
|
||||||
|
|||||||
Reference in New Issue
Block a user