-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add support for FritzBox 6690 #66
base: main
Are you sure you want to change the base?
Conversation
|
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 about 1 month 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
TrustManagerFactory
with theKeyStore
. - Use the
TrustManagerFactory
to get theTrustManager
array. - Initialize the
SSLContext
with theTrustManager
array.
-
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