Added docs for template edit request#503
Closed
mchatlas-hellosign wants to merge 1 commit intomainfrom
Closed
Conversation
| } | ||
| }; | ||
| SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
| sslContext.init(null, trustAllCerts, new SecureRandom()); |
Check failure
Code scanning / CodeQL
`TrustManager` that accepts all certificates High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 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.
Suggested changeset
1
sdks/java-v1/src/main/java/com/dropbox/sign/ApiClient.java
| @@ -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); | ||
| } | ||
|
|
Copilot is powered by AI and may make mistakes. Always verify output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.