-
Notifications
You must be signed in to change notification settings - Fork 18
Added docs for template edit request #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
| }; | ||
| SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
| sslContext.init(null, trustAllCerts, new SecureRandom()); |
Check failure
Code scanning / CodeQL
`TrustManager` that accepts all certificates High
TrustManager
ApiClient$
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 months ago
The best fix involves removing the ability to disable certificate validation entirely by replacing the insecure TrustManager with a secure and specific implementation. If the intention is to allow the use of a specific self-signed certificate in development, we should load that certificate into a KeyStore and configure a TrustManagerFactory to validate only that certificate. This approach avoids the blanket trusting of all certificates.
To fix this issue:
- Replace the
disableCertificateValidationmethod to use aKeyStorecontaining only the trusted certificates. - Remove the
X509TrustManagerimplementation that blindly trusts all certificates. - Ensure the
SSLContextis initialized withTrustManagers from a properly configuredTrustManagerFactory.
-
Copy modified lines R1217-R1231 -
Copy modified line R1233
| @@ -1214,23 +1214,23 @@ | ||
| * @throws java.security.KeyManagementException if any. | ||
| * @throws java.security.NoSuchAlgorithmException if any. | ||
| */ | ||
| protected void disableCertificateValidation(ClientBuilder clientBuilder) throws KeyManagementException, NoSuchAlgorithmException { | ||
| TrustManager[] trustAllCerts = new X509TrustManager[] { | ||
| new X509TrustManager() { | ||
| @Override | ||
| public X509Certificate[] getAcceptedIssuers() { | ||
| return null; | ||
| } | ||
| @Override | ||
| public void checkClientTrusted(X509Certificate[] certs, String authType) { | ||
| } | ||
| @Override | ||
| public void checkServerTrusted(X509Certificate[] certs, String authType) { | ||
| } | ||
| } | ||
| }; | ||
| protected void disableCertificateValidation(ClientBuilder clientBuilder, File certificateFile) throws Exception { | ||
| // Load the trusted certificate from the specified file | ||
| KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
| keyStore.load(null, null); | ||
| try (InputStream certStream = Files.newInputStream(certificateFile.toPath())) { | ||
| X509Certificate certificate = (X509Certificate) CertificateFactory.getInstance("X509") | ||
| .generateCertificate(certStream); | ||
| keyStore.setCertificateEntry("trustedCert", certificate); | ||
| } | ||
|
|
||
| // Create a TrustManagerFactory with the trusted key store | ||
| TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); | ||
| tmf.init(keyStore); | ||
|
|
||
| // Initialize SSLContext with the TrustManagers | ||
| SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
| sslContext.init(null, trustAllCerts, new SecureRandom()); | ||
| sslContext.init(null, tmf.getTrustManagers(), new SecureRandom()); | ||
| clientBuilder.sslContext(sslContext); | ||
| } | ||
|
|
No description provided.