mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Add test to make sure we don't check the wrong certificates
Right now we happily accept every certificate in our local key store as long as the hostname matches the certificate DN. So this test fails. It's not a huge deal since the user accepted the certificate at one point. But we want to do this right.
This commit is contained in:
parent
c5c195d243
commit
8368ba8a11
@ -115,6 +115,21 @@ public class TrustManagerFactoryTest extends AndroidTestCase {
|
||||
assertFalse("The certificate should have been rejected but wasn't", certificateValid);
|
||||
}
|
||||
|
||||
public void testCertificateOfOtherHost() throws Exception {
|
||||
TrustManagerFactory.addCertificate(MATCHING_HOST, PORT1, mCert1);
|
||||
TrustManagerFactory.addCertificate(MATCHING_HOST, PORT2, mCert2);
|
||||
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1, true);
|
||||
boolean certificateValid;
|
||||
try {
|
||||
trustManager.checkServerTrusted(new X509Certificate[] { mCert2 }, "authType");
|
||||
certificateValid = true;
|
||||
} catch (CertificateException e) {
|
||||
certificateValid = false;
|
||||
}
|
||||
assertFalse("The certificate should have been rejected but wasn't", certificateValid);
|
||||
}
|
||||
|
||||
private static class DummyApplication extends Application {
|
||||
private final Context mContext;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user