Skip to content

Commit 469d4f8

Browse files
authored
Merge pull request #81 from RUB-NDS/submodulehint
Submodulehint
2 parents 551e314 + 36b482e commit 469d4f8

File tree

3 files changed

+57
-34
lines changed

3 files changed

+57
-34
lines changed

TLS-Server-Scanner/src/main/java/de/rub/nds/tlsscanner/serverscanner/probe/certificate/CertificateChain.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,28 @@ public CertificateChain(Certificate certificate, String uri) {
142142
LOGGER.debug("Could not find next certificate");
143143
// Could not find issuer for certificate - check if its in
144144
// the trust store
145-
if (TrustAnchorManager.getInstance().isTrustAnchor(
146-
tempCertificate.convertToX509Certificate().getIssuerX500Principal())) {
147-
// Certificate is issued by trust anchor
148-
LOGGER.debug("Could find issuer");
149-
chainIsComplete = true;
150-
org.bouncycastle.asn1.x509.Certificate trustAnchorCertificate = TrustAnchorManager
151-
.getInstance().getTrustAnchorCertificate(
152-
tempCertificate.convertToX509Certificate().getIssuerX500Principal());
153-
if (trustAnchorCertificate != null) {
154-
CertificateReport trustAnchorReport = CertificateReportGenerator
155-
.generateReport(trustAnchorCertificate);
156-
orderedCertificateChain.add(trustAnchorReport);
157-
trustAnchorReport.setTrustAnchor(true);
158-
trustAnchor = trustAnchorReport;
145+
if (TrustAnchorManager.getInstance().isInitialized()) {
146+
if (TrustAnchorManager.getInstance().isTrustAnchor(
147+
tempCertificate.convertToX509Certificate().getIssuerX500Principal())) {
148+
// Certificate is issued by trust anchor
149+
LOGGER.debug("Could find issuer");
150+
chainIsComplete = true;
151+
org.bouncycastle.asn1.x509.Certificate trustAnchorCertificate = TrustAnchorManager
152+
.getInstance().getTrustAnchorCertificate(
153+
tempCertificate.convertToX509Certificate().getIssuerX500Principal());
154+
if (trustAnchorCertificate != null) {
155+
CertificateReport trustAnchorReport = CertificateReportGenerator
156+
.generateReport(trustAnchorCertificate);
157+
orderedCertificateChain.add(trustAnchorReport);
158+
trustAnchorReport.setTrustAnchor(true);
159+
trustAnchor = trustAnchorReport;
160+
}
161+
} else {
162+
LOGGER.debug("Could not find issuer");
163+
chainIsComplete = false;
159164
}
160165
} else {
161-
LOGGER.debug("Could not find issuer");
162-
chainIsComplete = false;
166+
LOGGER.error("Cannot check if the chain is complete since the trust manager is not initalized");
163167
}
164168
break;
165169
}

TLS-Server-Scanner/src/main/java/de/rub/nds/tlsscanner/serverscanner/probe/certificate/CertificateReportGenerator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public static CertificateReport generateReport(org.bouncycastle.asn1.x509.Certif
7979
report.setCertificate(cert);
8080
setVulnerableRoca(report, cert);
8181
TrustAnchorManager anchorManger = TrustAnchorManager.getInstance();
82-
report.setTrustAnchor(anchorManger.isTrustAnchor(report));
82+
if (anchorManger.isInitialized()) {
83+
report.setTrustAnchor(anchorManger.isTrustAnchor(report));
84+
} else {
85+
report.setTrustAnchor(null);
86+
}
8387
if (report.getIssuer().equals(report.getSubject())) {
8488
report.setSelfSigned(true);
8589
} else {
@@ -234,6 +238,9 @@ private static void setRevoked(CertificateReport report, org.bouncycastle.asn1.x
234238
TrustAnchorManager trustAnchorManager = TrustAnchorManager.getInstance();
235239
X509Certificate x509cert = null;
236240
try {
241+
if (!trustAnchorManager.isInitialized()) {
242+
return;
243+
}
237244
x509cert = new X509CertificateObject(cert);
238245
issuerCert = trustAnchorManager.getTrustAnchorCertificate(x509cert.getIssuerX500Principal());
239246
} catch (CertificateParsingException exp) {

TLS-Server-Scanner/src/main/java/de/rub/nds/tlsscanner/serverscanner/trust/TrustAnchorManager.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public class TrustAnchorManager {
4242

4343
private List<TrustPlatform> trustPlatformList;
4444

45-
private final HashMap<String, CertificateEntry> trustAnchors;
45+
private HashMap<String, CertificateEntry> trustAnchors;
4646

4747
private static TrustAnchorManager INSTANCE = null;
4848

49-
private final Set<TrustAnchor> trustAnchorSet;
50-
private final Set<Certificate> asn1CaCertificateSet;
49+
private Set<TrustAnchor> trustAnchorSet;
50+
private Set<Certificate> asn1CaCertificateSet;
5151

5252
public static synchronized TrustAnchorManager getInstance() {
5353
if (INSTANCE == null) {
@@ -65,24 +65,36 @@ private TrustAnchorManager() {
6565
trustPlatformList.add(readPlatform("openjdk.yaml"));
6666
trustPlatformList.add(readPlatform("oracle_java.yaml"));
6767
trustPlatformList.add(readPlatform("apple.yaml"));
68-
} catch (IOException | IllegalArgumentException ex) {
69-
LOGGER.error("Could not load trusted platforms", ex);
70-
}
71-
trustAnchors = new HashMap<>();
72-
for (TrustPlatform platform : trustPlatformList) {
73-
for (CertificateEntry entry : platform.getCertificateEntries()) {
74-
if (!trustAnchors.containsKey(entry.getFingerprint())) {
75-
trustAnchors.put(entry.getFingerprint(), entry);
68+
69+
trustAnchors = new HashMap<>();
70+
for (TrustPlatform platform : trustPlatformList) {
71+
for (CertificateEntry entry : platform.getCertificateEntries()) {
72+
if (!trustAnchors.containsKey(entry.getFingerprint())) {
73+
trustAnchors.put(entry.getFingerprint(), entry);
74+
}
7675
}
77-
}
78-
for (CertificateEntry entry : platform.getBlockedCertificateEntries()) {
79-
if (!trustAnchors.containsKey(entry.getFingerprint())) {
80-
trustAnchors.put(entry.getFingerprint(), entry);
76+
for (CertificateEntry entry : platform.getBlockedCertificateEntries()) {
77+
if (!trustAnchors.containsKey(entry.getFingerprint())) {
78+
trustAnchors.put(entry.getFingerprint(), entry);
79+
}
8180
}
8281
}
82+
this.trustAnchorSet = getFullTrustAnchorSet();
83+
this.asn1CaCertificateSet = getFullCaCertificateSet();
84+
} catch (IOException | IllegalArgumentException ex) {
85+
trustAnchorSet = null;
86+
trustAnchors = null;
87+
trustPlatformList = null;
88+
asn1CaCertificateSet = null;
89+
LOGGER.error("Could not load TrustAnchors. This means that you are running TLS-Scanner without its submodules. "
90+
+ "If you want to evaluate if certificates are trusted by browsers you need to initialize submodules."
91+
+ "You can do this by running the following command:'git submodule update --init --recursive'");
92+
LOGGER.debug(ex);
8393
}
84-
this.trustAnchorSet = getFullTrustAnchorSet();
85-
this.asn1CaCertificateSet = getFullCaCertificateSet();
94+
}
95+
96+
public boolean isInitialized() {
97+
return trustAnchorSet != null && trustPlatformList != null && trustAnchors != null;
8698
}
8799

88100
private TrustPlatform readPlatform(String name) throws IOException {

0 commit comments

Comments
 (0)