From 3dcfa7102ac07188ac0c1c8b252d45735abd31ea Mon Sep 17 00:00:00 2001 From: Alex Clayton Date: Mon, 14 Mar 2016 11:44:35 +0000 Subject: Fix handling when client certificate is missing As per patch 'Fix swiften handling when client certificate is missing' (8405fa16b738b6ef6a5920cd9d0f5735f8b62369). Change-Id: Iec5036213d8432a3af78647470381485bfcc01e3 Test-information: Code inspection. Unit tests still pass. diff --git a/src/com/isode/stroke/client/CoreClient.java b/src/com/isode/stroke/client/CoreClient.java index 010a535..6cb0d5d 100644 --- a/src/com/isode/stroke/client/CoreClient.java +++ b/src/com/isode/stroke/client/CoreClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015, Isode Limited, London, England. + * Copyright (c) 2010-2016, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.client; @@ -347,11 +347,20 @@ public class CoreClient { } else { assert (connection_ == null); - connection_ = connection; - assert (sessionStream_ == null); - sessionStream_ = new BasicSessionStream(StreamType.ClientStreamType, connection_, payloadParserFactories_, payloadSerializers_, networkFactories.getTLSContextFactory(), networkFactories.getTimerFactory(), options.tlsOptions); - if (certificate_ != null && !certificate_.isNull()) { + + if (certificate_ != null && certificate_.isNull()) { + // Certificate can not be read so do not initialise session + onDisconnected.emit(new ClientError(ClientError.Type.ClientCertificateLoadError)); + return; + } + + connection_ = connection; + + sessionStream_ = + new BasicSessionStream(StreamType.ClientStreamType, connection_, payloadParserFactories_, payloadSerializers_, + networkFactories.getTLSContextFactory(), networkFactories.getTimerFactory(), options.tlsOptions); + if (certificate_ != null) { sessionStream_.setTLSCertificate(certificate_); } sessionStreamDataReadConnection_ = sessionStream_.onDataRead.connect(new Slot1() { -- cgit v0.10.2-6-g49f6