Add support for custom tls server names. (#22372)

* Add support for custom tls server names.

* Update samples

* Fix missing declaration.
This commit is contained in:
Brendan Burns 2025-11-19 18:36:11 -08:00 committed by GitHub
parent a1b962d0b6
commit 8a4246cbaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 576 additions and 32 deletions

View File

@ -120,6 +120,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -433,6 +434,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1820,8 +1844,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -376,6 +377,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1635,8 +1659,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -86,6 +86,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -304,6 +305,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1565,8 +1589,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -86,6 +86,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -300,6 +301,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1539,8 +1563,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -86,6 +86,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -300,6 +301,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1539,8 +1563,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -86,6 +86,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -300,6 +301,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1562,8 +1586,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -376,6 +377,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1635,8 +1659,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -376,6 +377,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1635,8 +1659,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -92,6 +92,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -380,6 +381,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1655,8 +1679,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -97,6 +97,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -393,6 +394,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1640,8 +1664,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -376,6 +377,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1635,8 +1659,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -379,6 +380,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1638,8 +1662,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -382,6 +383,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1641,8 +1665,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -376,6 +377,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1635,8 +1659,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -91,6 +91,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -376,6 +377,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1635,8 +1659,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());

View File

@ -134,6 +134,7 @@ public class ApiClient {
protected InputStream sslCaCert;
protected boolean verifyingSsl;
protected KeyManager[] keyManagers;
protected String tlsServerName;
protected OkHttpClient httpClient;
protected JSON json;
@ -428,6 +429,29 @@ public class ApiClient {
return this;
}
/**
* Get TLS server name for SNI (Server Name Indication).
*
* @return The TLS server name
*/
public String getTlsServerName() {
return tlsServerName;
}
/**
* Set TLS server name for SNI (Server Name Indication).
* This is used to verify the server certificate against a specific hostname
* instead of the hostname in the URL.
*
* @param tlsServerName The TLS server name to use for certificate verification
* @return ApiClient
*/
public ApiClient setTlsServerName(String tlsServerName) {
this.tlsServerName = tlsServerName;
applySslSettings();
return this;
}
/**
* <p>Getter for the field <code>dateFormat</code>.</p>
*
@ -1709,8 +1733,18 @@ public class ApiClient {
trustManagerFactory.init(caKeyStore);
}
trustManagers = trustManagerFactory.getTrustManagers();
if (tlsServerName != null && !tlsServerName.isEmpty()) {
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Verify the certificate against tlsServerName instead of the actual hostname
return OkHostnameVerifier.INSTANCE.verify(tlsServerName, session);
}
};
} else {
hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());