8330278: Have SSLSocketTemplate.doClientSide use loopback address

Reviewed-by: ssahoo, rhalade
This commit is contained in:
Sean Coffey 2024-05-08 09:30:23 +00:00
parent c6f611cfe0
commit 0eff492e41
2 changed files with 4 additions and 3 deletions
test/jdk/javax/net/ssl/templates

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -273,7 +273,7 @@ public class SSLSocketTemplate extends SSLContextTemplate {
configureClientSocket(sslSocket);
InetAddress serverAddress = this.serverAddress;
InetSocketAddress connectAddress = serverAddress == null
? new InetSocketAddress("localhost", serverPort)
? new InetSocketAddress(InetAddress.getLoopbackAddress(), serverPort)
: new InetSocketAddress(serverAddress, serverPort);
sslSocket.connect(connectAddress, 15000);
} catch (IOException ioe) {

@ -23,6 +23,7 @@
import javax.net.ssl.*;
import java.io.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.security.KeyStore;
import java.security.cert.PKIXBuilderParameters;
@ -334,7 +335,7 @@ abstract public class TLSBase {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(TLSBase.getKeyManager(km), TLSBase.getTrustManager(tm), null);
sock = (SSLSocket)sslContext.getSocketFactory().createSocket();
sock.connect(new InetSocketAddress("localhost", serverPort));
sock.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), serverPort));
System.err.println("Client connected using port " +
sock.getLocalPort());
name = "client(" + sock.toString() + ")";