From c0293fade7b437e5687e7121c9f6b9de7344ad47 Mon Sep 17 00:00:00 2001 From: Gurmeen Bindra Date: Fri, 8 Aug 2014 12:04:07 +0100 Subject: Update stroke as per swiften wrt getting certificate chain This patch updates Stroke as per the Swiften code to get peerCertificate chain. Test-information: tested using M-Link Console (XMPP client) to look at the certificate and chain Change-Id: I2662511b72f9ca6d176a9f4c1e02d10b5df5d2c7 diff --git a/src/com/isode/stroke/client/ClientSession.java b/src/com/isode/stroke/client/ClientSession.java index c0caeb6..9ceecf0 100644 --- a/src/com/isode/stroke/client/ClientSession.java +++ b/src/com/isode/stroke/client/ClientSession.java @@ -176,6 +176,10 @@ public class ClientSession { public boolean getRosterVersioningSuported() { return rosterVersioningSupported; } + + public List getPeerCertificateChain() { + return stream.getPeerCertificateChain(); + } public JID getLocalJID() { return localJID; diff --git a/src/com/isode/stroke/client/ClientSessionStanzaChannel.java b/src/com/isode/stroke/client/ClientSessionStanzaChannel.java index 95f59d8..0aa024f 100644 --- a/src/com/isode/stroke/client/ClientSessionStanzaChannel.java +++ b/src/com/isode/stroke/client/ClientSessionStanzaChannel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010-2014, Isode Limited, London, England. * All rights reserved. */ /* @@ -16,6 +16,10 @@ import com.isode.stroke.elements.Stanza; import com.isode.stroke.signals.SignalConnection; import com.isode.stroke.signals.Slot; import com.isode.stroke.signals.Slot1; +import com.isode.stroke.tls.Certificate; + +import java.util.ArrayList; +import java.util.List; import java.util.logging.Logger; /** @@ -77,6 +81,13 @@ public class ClientSessionStanzaChannel extends StanzaChannel { } return false; } + + public List getPeerCertificateChain() { + if (session != null) { + return session.getPeerCertificateChain(); + } + return new ArrayList(); + } public boolean isAvailable() { return session != null && ClientSession.State.Initialized.equals(session.getState()); diff --git a/src/com/isode/stroke/client/CoreClient.java b/src/com/isode/stroke/client/CoreClient.java index 646f8fe..a1c6d0a 100644 --- a/src/com/isode/stroke/client/CoreClient.java +++ b/src/com/isode/stroke/client/CoreClient.java @@ -3,7 +3,7 @@ * All rights reserved. */ /* - * Copyright (c) 2010, Remko Tronçon. + * Copyright (c) 2010-2014, Remko Tronçon. * All rights reserved. */ package com.isode.stroke.client; @@ -29,7 +29,6 @@ import com.isode.stroke.signals.SignalConnection; import com.isode.stroke.signals.Slot; import com.isode.stroke.signals.Slot1; import com.isode.stroke.signals.Slot2; -import com.isode.stroke.tls.Certificate; import com.isode.stroke.tls.CertificateTrustChecker; import com.isode.stroke.tls.CertificateVerificationError; import com.isode.stroke.tls.CertificateWithKey; @@ -468,18 +467,9 @@ public class CoreClient { * @return true if the session is initialized and encrypted with TLS, * false otherwise. */ - public boolean isSessionTLSEncrypted() { + public boolean isStreamEncrypted() { return (sessionStream_ != null && sessionStream_.isTLSEncrypted()); } - - /** - * If the session is initialized and encrypted with TLS, then the - * certificate presented by the peer is returned - * @return the peer certificate, if one is available, otherwise null. - */ - public Certificate getSessionCertificate() { - return (isSessionTLSEncrypted() ? sessionStream_.getPeerCertificate() : null); - } private void resetConnector() { if (connectorConnectFinishedConnection_ != null) { diff --git a/src/com/isode/stroke/client/DummyStanzaChannel.java b/src/com/isode/stroke/client/DummyStanzaChannel.java index 25fb817..ac1fc1c 100644 --- a/src/com/isode/stroke/client/DummyStanzaChannel.java +++ b/src/com/isode/stroke/client/DummyStanzaChannel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Isode Limited, London, England. + * Copyright (c) 2014, Isode Limited, London, England. * All rights reserved. */ /* @@ -8,6 +8,8 @@ */ package com.isode.stroke.client; +import java.util.ArrayList; +import java.util.List; import java.util.Vector; import com.isode.stroke.elements.IQ; @@ -16,6 +18,7 @@ import com.isode.stroke.elements.Payload; import com.isode.stroke.elements.Presence; import com.isode.stroke.elements.Stanza; import com.isode.stroke.jid.JID; +import com.isode.stroke.tls.Certificate; /** * Dummy Stanza Channel for Unit Testing @@ -111,5 +114,10 @@ public class DummyStanzaChannel extends StanzaChannel { return (T)(sentStanzas.get(index)); } return null; + } + + @Override + public List getPeerCertificateChain() { + return new ArrayList(); } } diff --git a/src/com/isode/stroke/client/StanzaChannel.java b/src/com/isode/stroke/client/StanzaChannel.java index 62984b5..5a1d270 100644 --- a/src/com/isode/stroke/client/StanzaChannel.java +++ b/src/com/isode/stroke/client/StanzaChannel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010-2014, Isode Limited, London, England. * All rights reserved. */ /* @@ -9,11 +9,14 @@ package com.isode.stroke.client; +import java.util.List; + import com.isode.stroke.elements.Message; import com.isode.stroke.elements.Presence; import com.isode.stroke.elements.Stanza; import com.isode.stroke.queries.IQChannel; import com.isode.stroke.signals.Signal1; +import com.isode.stroke.tls.Certificate; public abstract class StanzaChannel extends IQChannel { @@ -25,6 +28,7 @@ public abstract class StanzaChannel extends IQChannel { public abstract boolean isAvailable(); public abstract boolean getStreamManagementEnabled(); + public abstract List getPeerCertificateChain(); public final Signal1 onMessageReceived = new Signal1(); public final Signal1 onPresenceReceived = new Signal1(); -- cgit v0.10.2-6-g49f6