|
18 | 18 | #include "settings.h" |
19 | 19 | #include "posix.h" |
20 | 20 | #include "stream.h" |
| 21 | +#include "net.h" |
21 | 22 | #include "streams/socket.h" |
22 | 23 | #include "netops.h" |
23 | 24 | #include "git2/transport.h" |
@@ -357,15 +358,10 @@ static int ssl_teardown(SSL *ssl) |
357 | 358 | return ret; |
358 | 359 | } |
359 | 360 |
|
360 | | -static int check_host_name(const char *name, const char *host) |
| 361 | +static bool check_host_name(const char *host, const char *name) |
361 | 362 | { |
362 | | - if (!strcasecmp(name, host)) |
363 | | - return 0; |
364 | | - |
365 | | - if (gitno__match_host(name, host) < 0) |
366 | | - return -1; |
367 | | - |
368 | | - return 0; |
| 363 | + return !strcasecmp(host, name) || |
| 364 | + git_net_hostname_matches_cert(host, name); |
369 | 365 | } |
370 | 366 |
|
371 | 367 | static int verify_server_cert(SSL *ssl, const char *host) |
@@ -425,10 +421,7 @@ static int verify_server_cert(SSL *ssl, const char *host) |
425 | 421 | if (memchr(name, '\0', namelen)) |
426 | 422 | continue; |
427 | 423 |
|
428 | | - if (check_host_name(name, host) < 0) |
429 | | - matched = 0; |
430 | | - else |
431 | | - matched = 1; |
| 424 | + matched = !!check_host_name(host, name); |
432 | 425 | } else if (type == GEN_IPADD) { |
433 | 426 | /* Here name isn't so much a name but a binary representation of the IP */ |
434 | 427 | matched = addr && !!memcmp(name, addr, namelen); |
@@ -481,7 +474,7 @@ static int verify_server_cert(SSL *ssl, const char *host) |
481 | 474 | goto cert_fail_name; |
482 | 475 | } |
483 | 476 |
|
484 | | - if (check_host_name((char *)peer_cn, host) < 0) |
| 477 | + if (!check_host_name(host, (char *)peer_cn)) |
485 | 478 | goto cert_fail_name; |
486 | 479 |
|
487 | 480 | goto cleanup; |
|
0 commit comments