F-5885: verify peer hostname for non-loopback hosts in Client example

pull/389/head
Chris Conlon 2026-07-22 16:01:11 -06:00
parent 83d5e683ea
commit e6b9302f20
1 changed files with 31 additions and 0 deletions

View File

@ -446,6 +446,11 @@ public class Client {
sslCtx.setRsaDecCb(rsaDec);
}
/* Verify the peer hostname for non-loopback hosts. The example
* certs carry no loopback name. */
boolean checkDomain = (verifyPeer != 0) &&
!InetAddress.getByName(host).isLoopbackAddress();
if (benchmark != 0) {
int times = benchmark;
int i = 0;
@ -466,6 +471,15 @@ public class Client {
ssl = new WolfSSLSession(sslCtx);
ssl.setFd(sock);
if (checkDomain) {
ret = ssl.checkDomainName(host);
if (ret != WolfSSL.SSL_SUCCESS) {
System.out.println(
"failed to set domain name check!");
System.exit(1);
}
}
do {
ret = ssl.connect();
err = ssl.getError(ret);
@ -648,6 +662,14 @@ public class Client {
ssl.setRsaDecCtx(rsaDecCtx);
}
if (checkDomain) {
ret = ssl.checkDomainName(host);
if (ret != WolfSSL.SSL_SUCCESS) {
System.out.println("failed to set domain name check!");
System.exit(1);
}
}
/* call wolfSSL_connect */
do {
ret = ssl.connect();
@ -822,6 +844,15 @@ public class Client {
/* restore saved WOLFSSL_SESSION */
ssl.setSession(session);
if (checkDomain) {
ret = ssl.checkDomainName(host);
if (ret != WolfSSL.SSL_SUCCESS) {
System.out.println(
"failed to set domain name check!");
System.exit(1);
}
}
/* call wolfSSL_connect */
do {
ret = ssl.connect();