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:
cketti 2013-11-29 11:39:04 +01:00
parent c5c195d243
commit 8368ba8a11
1 changed files with 15 additions and 0 deletions

View File

@ -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;