mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-09-20 12:13:41 +08:00
Fix hostname verify bug
This commit is contained in:
@@ -791,7 +791,7 @@ int tlcp_recv_server_certificate(TLS_CONNECT *conn)
|
||||
tls_send_alert(conn, TLS_alert_bad_certificate);
|
||||
return -1;
|
||||
}
|
||||
if (conn->server_name) {
|
||||
if (conn->host_name_len) {
|
||||
if ((ret = tls_cert_match_server_name(server_cert, server_cert_len,
|
||||
conn->host_name, conn->host_name_len)) < 0) {
|
||||
error_print();
|
||||
|
||||
@@ -1259,8 +1259,8 @@ int tls_recv_server_certificate(TLS_CONNECT *conn)
|
||||
}
|
||||
}
|
||||
|
||||
// check server certificate matches ClientHello.server_name
|
||||
if (conn->server_name) {
|
||||
// check server certificate matches configured hostname
|
||||
if (conn->host_name_len) {
|
||||
if ((ret = tls_cert_match_server_name(server_cert, server_cert_len,
|
||||
conn->host_name, conn->host_name_len)) < 0) {
|
||||
error_print();
|
||||
|
||||
@@ -6237,7 +6237,7 @@ int tls13_recv_server_certificate(TLS_CONNECT *conn)
|
||||
ca_names = conn->ctx->ca_names;
|
||||
ca_names_len = conn->ctx->ca_names_len;
|
||||
}
|
||||
if (conn->server_name) {
|
||||
if (conn->host_name_len) {
|
||||
host_name = conn->host_name;
|
||||
host_name_len = conn->host_name_len;
|
||||
}
|
||||
|
||||
@@ -108,9 +108,11 @@ int tls_server_name_from_bytes(const uint8_t **host_name, size_t *host_name_len,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tls_set_server_name(TLS_CONNECT *conn, const uint8_t *host_name, size_t host_name_len)
|
||||
int tls_set_hostname(TLS_CONNECT *conn, const char *host_name)
|
||||
{
|
||||
if (!conn || !host_name || !host_name_len) {
|
||||
size_t host_name_len;
|
||||
|
||||
if (!conn || !host_name) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
@@ -118,6 +120,11 @@ int tls_set_server_name(TLS_CONNECT *conn, const uint8_t *host_name, size_t host
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
host_name_len = strlen(host_name);
|
||||
if (!host_name_len) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (host_name_len >= sizeof(conn->host_name)) {
|
||||
error_print();
|
||||
return -1;
|
||||
@@ -125,6 +132,23 @@ int tls_set_server_name(TLS_CONNECT *conn, const uint8_t *host_name, size_t host
|
||||
memcpy(conn->host_name, host_name, host_name_len);
|
||||
conn->host_name[host_name_len] = 0;
|
||||
conn->host_name_len = host_name_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tls_set_server_name(TLS_CONNECT *conn)
|
||||
{
|
||||
if (!conn) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (!conn->is_client) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (!conn->host_name_len) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
conn->server_name = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user