Skip to content

Commit 90c7c5d

Browse files
chadbrubakerandi34
authored andcommitted
DO NOT MERGE Prevent duplicate certificates in TrustedCertificateIndex
With the separate caching of intermediate certificates in TrustManagerImpl a given intermediate may be passed into .index multiple times. Avoid adding the certificate to the list each time. (cherry-picked from commit d080e064abba665e2dde2a8c113f837ba4d9a85e) Bug: 26232830 Change-Id: I6bed2c65d9e42e052b9b1b129200a997e7dca745 (cherry picked from commit 129c058)
1 parent be492cb commit 90c7c5d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

crypto/src/main/java/org/conscrypt/TrustedCertificateIndex.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ public void index(TrustAnchor anchor) {
6969
if (anchors == null) {
7070
anchors = new ArrayList<TrustAnchor>(1);
7171
subjectToTrustAnchors.put(subject, anchors);
72+
} else {
73+
// Avoid indexing the same certificate multiple times
74+
if (cert != null) {
75+
for (TrustAnchor entry : anchors) {
76+
if (cert.equals(entry.getTrustedCert())) {
77+
return;
78+
}
79+
}
80+
}
7281
}
7382
anchors.add(anchor);
7483
}

0 commit comments

Comments
 (0)