-
Notifications
You must be signed in to change notification settings - Fork 13
Add support for FritzBox 6690 #66
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
base: main
Are you sure you want to change the base?
Conversation
|
| final SSLContext sslContext1 = sslContext; | ||
| try { | ||
| sslContext1.init(keyManagers, trustManagers, secureRandom); | ||
| sslContext.init(keyManagers, trustManagers, secureRandom); |
Check failure
Code scanning / CodeQL
`TrustManager` that accepts all certificates High
TrustManager
NullTrustManager
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 months ago
To fix the problem, we need to replace the NullTrustManager with a TrustManager that only trusts specific self-signed certificates. This involves creating a KeyStore containing the trusted certificates and initializing the TrustManagerFactory with this KeyStore. This way, only the specified certificates will be trusted, and the risk of a machine-in-the-middle attack is mitigated.
- Load the self-signed certificate into a
KeyStore. - Initialize a
TrustManagerFactorywith theKeyStore. - Use the
TrustManagerFactoryto get theTrustManagerarray. - Initialize the
SSLContextwith theTrustManagerarray.
-
Copy modified lines R23-R27 -
Copy modified line R48 -
Copy modified lines R63-R83
| @@ -22,2 +22,7 @@ | ||
| import javax.net.ssl.*; | ||
| import java.io.FileInputStream; | ||
| import java.io.InputStream; | ||
| import java.security.KeyStore; | ||
| import java.security.cert.CertificateFactory; | ||
| import java.security.cert.X509Certificate; | ||
|
|
||
| @@ -42,3 +47,3 @@ | ||
| final KeyManager[] keyManagers = null; | ||
| final TrustManager[] trustManagers = new TrustManager[] { new NullTrustManager() }; | ||
| final TrustManager[] trustManagers = getTrustManagers(); | ||
| final SecureRandom secureRandom = new SecureRandom(); | ||
| @@ -57,2 +62,23 @@ | ||
| } | ||
| } | ||
| private static TrustManager[] getTrustManagers() { | ||
| try { | ||
| // Load the self-signed certificate | ||
| File certificateFile = new File("path/to/self-signed-certificate"); | ||
| KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
| keyStore.load(null, null); | ||
| X509Certificate generatedCertificate; | ||
| try (InputStream cert = new FileInputStream(certificateFile)) { | ||
| generatedCertificate = (X509Certificate) CertificateFactory.getInstance("X509") | ||
| .generateCertificate(cert); | ||
| } | ||
| keyStore.setCertificateEntry(certificateFile.getName(), generatedCertificate); | ||
|
|
||
| // Initialize TrustManagerFactory with the KeyStore | ||
| TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); | ||
| tmf.init(keyStore); | ||
| return tmf.getTrustManagers(); | ||
| } catch (Exception e) { | ||
| throw new HttpException("Error initializing trust managers", e); | ||
| } | ||
| } |


Contributed by Manfred