From 011b1315c1c4e82f845505234a30cc7376b94af6 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Thu, 9 Sep 2010 14:06:40 +0000 Subject: ZRTP support for XMPP. --- .../impl/gui/main/chat/ChatContact.java | 15 +++++++-- .../impl/neomedia/MediaServiceImpl.java | 4 +-- .../impl/neomedia/MediaStreamImpl.java | 3 +- .../impl/neomedia/ZrtpControlImpl.java | 13 ++++++++ .../transform/zrtp/ZRTPTransformEngine.java | 10 +++--- .../impl/protocol/jabber/CallPeerJabberImpl.java | 9 ++++-- .../jabber/CallPeerMediaHandlerJabberImpl.java | 36 +++++++++++++++++++--- .../OperationSetBasicTelephonyJabberImpl.java | 30 ++++++++++++++++-- .../jabber/ProtocolProviderServiceJabberImpl.java | 22 +++++++++---- .../communicator/service/neomedia/ZrtpControl.java | 12 +++++++- 10 files changed, 126 insertions(+), 28 deletions(-) (limited to 'src/net/java') diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatContact.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatContact.java index 1f11704..cc44d4b 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatContact.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatContact.java @@ -21,8 +21,14 @@ import net.java.sip.communicator.util.*; */ public abstract class ChatContact { + /** + * The height of the avatar icon. + */ public static final int AVATAR_ICON_HEIGHT = 25; + /** + * The width of the avatar icon. + */ public static final int AVATAR_ICON_WIDTH = 25; /** @@ -42,6 +48,9 @@ public abstract class ChatContact */ protected final T descriptor; + /** + * If this instance is selected. + */ private boolean selected; /** @@ -112,7 +121,7 @@ public abstract class ChatContact /** * Gets the avatar image corresponding to the source contact in the form of * an array of bytes. - * + * * @return an array of bytes which represents the avatar image corresponding * to the source contact */ @@ -122,7 +131,7 @@ public abstract class ChatContact * Returns the descriptor object corresponding to this chat contact. In the * case of single chat this could be the MetaContact and in the * case of conference chat this could be the ChatRoomMember. - * + * * @return the descriptor object corresponding to this chat contact. */ public T getDescriptor() @@ -140,7 +149,7 @@ public abstract class ChatContact /** * Gets the implementation-specific identifier which uniquely specifies this * contact. - * + * * @return an identifier which uniquely specifies this contact */ public abstract String getUID(); diff --git a/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java b/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java index 45ad7b9..036f601 100644 --- a/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java +++ b/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java @@ -579,10 +579,10 @@ public class MediaServiceImpl /** * Creates a new Recorder instance that can be used to record a * call which captures and plays back media using a specific - * MediaDevice. + * MediaDevice. * * @param device the MediaDevice which is used for media capture - * and playback by the call to be recorded + * and playback by the call to be recorded * @return a new Recorder instance that can be used to record a * call which captures and plays back media using the specified * MediaDevice diff --git a/src/net/java/sip/communicator/impl/neomedia/MediaStreamImpl.java b/src/net/java/sip/communicator/impl/neomedia/MediaStreamImpl.java index a166fee..e4eb368 100644 --- a/src/net/java/sip/communicator/impl/neomedia/MediaStreamImpl.java +++ b/src/net/java/sip/communicator/impl/neomedia/MediaStreamImpl.java @@ -571,7 +571,8 @@ public class MediaStreamImpl + " in RTPManager with hashCode " + rtpManager.hashCode()); - // If a ZRTP engine is availabe then set the SSRC of this stream + // If a ZRTP engine is available then set the SSRC of this + // stream // currently ZRTP supports only one SSRC per engine ZRTPTransformEngine engine = zrtpControl.getZrtpEngine(); diff --git a/src/net/java/sip/communicator/impl/neomedia/ZrtpControlImpl.java b/src/net/java/sip/communicator/impl/neomedia/ZrtpControlImpl.java index 76adc4a..eee862e 100644 --- a/src/net/java/sip/communicator/impl/neomedia/ZrtpControlImpl.java +++ b/src/net/java/sip/communicator/impl/neomedia/ZrtpControlImpl.java @@ -227,6 +227,19 @@ public class ZrtpControlImpl } /** + * Get the ZRTP Hello Hash data - separate strings. + * + * @return String array containing the version string at offset 0, the Hello + * hash value as hex-digits at offset 1. Hello hash is available + * immediately after class instantiation. Returns null + * if ZRTP is not available. + */ + public String[] getHelloHashSep() + { + return getZrtpEngine().getHelloHashSep(); + } + + /** * Sets the RTPConnector which is to use or uses this ZRTP engine. * * @param connector the RTPConnector which is to use or uses this diff --git a/src/net/java/sip/communicator/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java b/src/net/java/sip/communicator/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java index 281920b..b47857d 100644 --- a/src/net/java/sip/communicator/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java +++ b/src/net/java/sip/communicator/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java @@ -1112,10 +1112,10 @@ public class ZRTPTransformEngine /** * Get the ZRTP Hello Hash data - separate strings. - * - * @return String array containing the version string at offset 0, the Hello - * hash value as hex-digits at offset 1. Hello hash is available - * immediately after class instantiation. Retruns null + * + * @return String array containing the version string at offset 0, the Hello + * hash value as hex-digits at offset 1. Hello hash is available + * immediately after class instantiation. Returns null * if ZRTP is not available. */ public String[] getHelloHashSep() { @@ -1124,7 +1124,7 @@ public class ZRTPTransformEngine else return null; } - + /** * Gets the multistream params * diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java index 582cd56..d5920b8 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java @@ -12,6 +12,7 @@ import org.jivesoftware.smackx.packet.*; import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.*; import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.ContentPacketExtension.*; +import net.java.sip.communicator.service.neomedia.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.service.protocol.media.*; @@ -492,7 +493,8 @@ public class CallPeerJabberImpl public void sendModifyVideoContent(boolean allowed) { ContentPacketExtension ext = new ContentPacketExtension(); - SendersEnum senders = getMediaHandler().getDirection("video"); + SendersEnum senders = getMediaHandler().getDirection( + MediaType.VIDEO.toString()); /* adjust the senders attribute depending on current value and if we * allowed or not local video streaming @@ -528,7 +530,7 @@ public class CallPeerJabberImpl ext.setSenders(senders); ext.setCreator(isInitiator ? CreatorEnum.initiator : CreatorEnum.responder); - ext.setName("video"); + ext.setName(MediaType.VIDEO.toString()); JingleIQ contentIQ = JinglePacketFactory .createContentModify(getProtocolProvider().getOurJID(), @@ -538,7 +540,8 @@ public class CallPeerJabberImpl try { - getMediaHandler().reinitContent("video", senders); + getMediaHandler().reinitContent(MediaType.VIDEO.toString(), + senders); } catch(Exception e) { diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java index fce4df1..e194e3b 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java @@ -248,6 +248,30 @@ public class CallPeerMediaHandlerJabberImpl mutuallySupportedFormats, rtpExtensions, getDynamicPayloadTypes(), getRtpExtensionsRegistry()); + // ZRTP + if(getPeer().getCall().isSipZrtpAttribute()) + { + ZrtpControl control = getZrtpControls().get(mediaType); + if(control == null) + { + control = JabberActivator.getMediaService() + .createZrtpControl(); + getZrtpControls().put(mediaType, control); + } + + String helloHash[] = control.getHelloHashSep(); + + if(helloHash != null && helloHash[1].length() > 0) + { + ZrtpHashPacketExtension hash + = new ZrtpHashPacketExtension(); + hash.setVersion(helloHash[0]); + hash.setValue(helloHash[1]); + + ourContent.addChildExtension(hash); + } + } + answerContentList.add(ourContent); localContentMap.put(content.getName(), ourContent); @@ -376,17 +400,19 @@ public class CallPeerMediaHandlerJabberImpl getZrtpControls().put(mediaType, control); } - String helloHash = control.getHelloHash(); - if(helloHash != null && helloHash.length() > 0) + String helloHash[] = control.getHelloHashSep(); + + if(helloHash != null && helloHash[1].length() > 0) { ZrtpHashPacketExtension hash = new ZrtpHashPacketExtension(); - hash.setValue(helloHash); - //we are currently disabling ZRTP until we find the - //time to fix it + hash.setVersion(helloHash[0]); + hash.setValue(helloHash[1]); + content.addChildExtension(hash); } } + mediaDescs.add(content); } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicTelephonyJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicTelephonyJabberImpl.java index 56fea64..40b127d 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicTelephonyJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicTelephonyJabberImpl.java @@ -32,7 +32,8 @@ public class OperationSetBasicTelephonyJabberImpl extends AbstractOperationSetBasicTelephony implements RegistrationStateChangeListener, PacketListener, - PacketFilter + PacketFilter, + OperationSetSecureTelephony { /** @@ -89,7 +90,7 @@ public class OperationSetBasicTelephonyJabberImpl } else if ((evt.getNewState() == RegistrationState.UNREGISTERED)) { - // TODO: plug jingle unregistraion + // TODO: plug jingle unregistration if (logger.isInfoEnabled()) logger.info("Jingle : OFF "); } @@ -558,4 +559,29 @@ public class OperationSetBasicTelephonyJabberImpl { return protocolProvider; } + + /** + * Gets the secure state of the call session in which a specific peer + * is involved + * + * @param peer the peer for who the call state is required + * @return the call state + */ + public boolean isSecure(CallPeer peer) + { + return ((CallPeerJabberImpl) peer).getMediaHandler().isSecure(); + } + + /** + * Sets the SAS verifications state of the call session in which a specific + * peer is involved + * + * @param peer the peer who toggled (or for whom is remotely + * toggled) the SAS verified flag + * @param verified the new SAS verification status + */ + public void setSasVerified(CallPeer peer, boolean verified) + { + ((CallPeerJabberImpl) peer).getMediaHandler().setSasVerified(verified); + } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java index 04d9013..9f31ece 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java @@ -72,6 +72,12 @@ public class ProtocolProviderServiceJabberImpl = "urn:xmpp:jingle:apps:rtp:video"; /** + * Jingle's Discovery Info URN for ZRTP support with RTP. + */ + public static final String URN_XMPP_JINGLE_RTP_ZRTP + = ZrtpHashPacketExtension.NAMESPACE; + + /** * Jingle's Discovery Info URN for ICE_UDP transport support. */ public static final String URN_XMPP_JINGLE_RAW_UDP_0 @@ -370,7 +376,6 @@ public class ProtocolProviderServiceJabberImpl } password = new String(pass); - if (credentials.isPasswordPersistent()) { JabberActivator.getProtocolProviderFactory() @@ -564,7 +569,7 @@ public class ProtocolProviderServiceJabberImpl SASLAuthentication.supportSASLMechanism("PLAIN", 0); // Insert our sasl mechanism implementation - // in order to support some incompatable servers + // in order to support some incompatible servers SASLAuthentication.unregisterSASLMechanism("DIGEST-MD5"); SASLAuthentication.registerSASLMechanism("DIGEST-MD5", SASLDigestMD5Mechanism.class); @@ -576,11 +581,11 @@ public class ProtocolProviderServiceJabberImpl } catch (XMPPException e1) { // after updating to new smack lib - // login mechanisum changed + // login mechanism changed // this is a way to avoid the problem try { - // server disconnect us after such un error + // server disconnect us after such an error // cleanup try { @@ -637,7 +642,6 @@ public class ProtocolProviderServiceJabberImpl disconnectAndCleanConnection(); } - } catch (NumberFormatException ex) { @@ -648,7 +652,7 @@ public class ProtocolProviderServiceJabberImpl synchronized(connectAndLoginLock) { - // Checks if an error has occured during login, if so we fire + // Checks if an error has occurred during login, if so we fire // it here in order to avoid a deadlock which occurs in // reconnect plugin. The deadlock is cause we fired an event during // login process and have locked initializationLock and we cannot @@ -958,10 +962,15 @@ public class ProtocolProviderServiceJabberImpl { OperationSetBasicTelephonyJabberImpl basicTelephony = new OperationSetBasicTelephonyJabberImpl(this); + addSupportedOperationSet( OperationSetBasicTelephony.class, basicTelephony); + addSupportedOperationSet( + OperationSetSecureTelephony.class, + basicTelephony); + // initialize video telephony OperationSet addSupportedOperationSet( OperationSetVideoTelephony.class, @@ -980,6 +989,7 @@ public class ProtocolProviderServiceJabberImpl //supportedFeatures.add(URN_XMPP_JINGLE_ICE_UDP_1); supportedFeatures.add(URN_XMPP_JINGLE_RTP_AUDIO); supportedFeatures.add(URN_XMPP_JINGLE_RTP_VIDEO); + supportedFeatures.add(URN_XMPP_JINGLE_RTP_ZRTP); } // OperationSetContactCapabilities diff --git a/src/net/java/sip/communicator/service/neomedia/ZrtpControl.java b/src/net/java/sip/communicator/service/neomedia/ZrtpControl.java index 54a961a..be31e03 100644 --- a/src/net/java/sip/communicator/service/neomedia/ZrtpControl.java +++ b/src/net/java/sip/communicator/service/neomedia/ZrtpControl.java @@ -19,7 +19,7 @@ public interface ZrtpControl * Cleans up the current zrtp control and its engine. */ public void cleanup(); - + /** * Sets a ZrtpListener that will listen for * zrtp security events. @@ -73,4 +73,14 @@ public interface ZrtpControl * @return String the zrtp hello hash. */ public String getHelloHash(); + + /** + * Get the ZRTP Hello Hash data - separate strings. + * + * @return String array containing the version string at offset 0, the Hello + * hash value as hex-digits at offset 1. Hello hash is available + * immediately after class instantiation. Returns null + * if ZRTP is not available. + */ + public String[] getHelloHashSep(); } -- cgit v1.1