From 716cf1b389b4f88bad61e56587575b6f97ee57ca Mon Sep 17 00:00:00 2001 From: Nick Hudson Date: Thu, 19 Sep 2013 17:01:13 +0100 Subject: Don't crash if server doesn't send cert in TLS handshake If a TLS connection results in the server choosing an anonymous cipher suite, then no server certificate will be returned by the server. This ought not to happen, since XMPP clients are expected only to propose non-anonymous cipher suites, but it could be that a client is coded to propose anonymous suites, or that a bug in the server means that it fails to return a server certificate. This change updates the ServerIdentityVerifier to make it resilient against these situations, treating this situation as equivalent to "certificate presented by server does not verify". Test-information: In my testing, I was deliberately using anonymous ciphers and getting Stroke crashes. After this patch, I don't get Stroke crashes any more (but the connection fails because the certificate verification fails). Change-Id: Ia7b9b8dad7a054ff266a78ef33a56157320654c8 diff --git a/src/com/isode/stroke/tls/ServerIdentityVerifier.java b/src/com/isode/stroke/tls/ServerIdentityVerifier.java index 3dcd855..20caae8 100644 --- a/src/com/isode/stroke/tls/ServerIdentityVerifier.java +++ b/src/com/isode/stroke/tls/ServerIdentityVerifier.java @@ -21,6 +21,9 @@ public class ServerIdentityVerifier { } public boolean certificateVerifies(Certificate certificate) { + if (certificate==null) { + return false; + } boolean hasSAN = false; // DNS names -- cgit v0.10.2-6-g49f6