From 2b5119b0cf2e010abfc8e2d4696f3ab3dff0c678 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov <lyubomir.marinov@jitsi.org> Date: Wed, 28 Aug 2013 22:35:31 +0300 Subject: [PATCH] Cleans up code, fixes javadocs, applies tiny optimizations. --- .../jitsi/impl/neomedia/MediaStreamImpl.java | 19 +- .../jitsi/impl/neomedia/ZrtpControlImpl.java | 430 +++++++++--------- .../transform/sdes/SDesControlImpl.java | 237 +++++----- .../jitsi/service/neomedia/SDesControl.java | 58 +-- .../jitsi/service/neomedia/SrtpControl.java | 67 +-- .../jitsi/service/neomedia/ZrtpControl.java | 117 +++-- 6 files changed, 452 insertions(+), 476 deletions(-) diff --git a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java index d89cb71a..0b74b213 100644 --- a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java +++ b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java @@ -2889,15 +2889,13 @@ else if (this instanceof VideoMediaStream) * <p> * * @param originalPt the payload type that we are overriding - * @param overloadPt the payload type that we are overriging it with + * @param overloadPt the payload type that we are overriding it with */ public void addDynamicRTPPayloadTypeOverride(byte originalPt, byte overloadPt) { - if(ptTransformEngine != null) - { + if (ptTransformEngine != null) ptTransformEngine.addPTMappingOverride(originalPt, overloadPt); - } } /** @@ -2905,27 +2903,26 @@ public void addDynamicRTPPayloadTypeOverride(byte originalPt, */ public void removeReceiveStreamForSsrc(long ssrc) { - Vector receiveStreamsVector = rtpManager.getReceiveStreams(); ReceiveStream toRemove = null; - for(int i=0; i<receiveStreamsVector.size(); i++) + + for (Object o : rtpManager.getReceiveStreams()) { - ReceiveStream receiveStream - = (ReceiveStream) receiveStreamsVector.get(i); + ReceiveStream receiveStream = (ReceiveStream) o; + if (receiveStream.getSSRC() == ssrc) { toRemove = receiveStream; break; } } - if (toRemove != null) { synchronized (receiveStreams) { - if (receiveStreams.contains(toRemove)) + if (receiveStreams.remove(toRemove)) { - receiveStreams.remove(toRemove); MediaDeviceSession deviceSession = getDeviceSession(); + if (deviceSession != null) deviceSession.removeReceiveStream(toRemove); } diff --git a/src/org/jitsi/impl/neomedia/ZrtpControlImpl.java b/src/org/jitsi/impl/neomedia/ZrtpControlImpl.java index b200e531..4f8961a2 100644 --- a/src/org/jitsi/impl/neomedia/ZrtpControlImpl.java +++ b/src/org/jitsi/impl/neomedia/ZrtpControlImpl.java @@ -23,11 +23,6 @@ public class ZrtpControlImpl implements ZrtpControl { - /** - * The listener interested in security events about zrtp. - */ - private SrtpListener zrtpListener = null; - /** * Additional info codes for and data to support ZRTP4J. * These could be added to the library. However they are specific for this @@ -35,16 +30,16 @@ public class ZrtpControlImpl */ public static enum ZRTPCustomInfoCodes { - ZRTPNotEnabledByUser, ZRTPDisabledByCallEnd, + ZRTPEnabledByDefault, ZRTPEngineInitFailure, - ZRTPEnabledByDefault + ZRTPNotEnabledByUser } /** - * The zrtp engine control by this ZrtpControl. + * Whether current is master session. */ - private ZRTPTransformEngine zrtpEngine = null; + private boolean masterSession = false; /** * This is the connector, required to send ZRTP packets @@ -53,9 +48,14 @@ public static enum ZRTPCustomInfoCodes private AbstractRTPConnector zrtpConnector = null; /** - * Whether current is master session. + * The zrtp engine control by this ZrtpControl. */ - private boolean masterSession = false; + private ZRTPTransformEngine zrtpEngine = null; + + /** + * The listener interested in security events about zrtp. + */ + private SrtpListener zrtpListener = null; /** * Creates the control. @@ -79,171 +79,25 @@ public void cleanup() zrtpConnector = null; } - /** - * Sets a <tt>ZrtpListener</tt> that will listen for zrtp security events. - * - * @param zrtpListener the <tt>ZrtpListener</tt> to set - */ - public void setSrtpListener(SrtpListener zrtpListener) - { - this.zrtpListener = zrtpListener; - } - - /** - * Returns the <tt>ZrtpListener</tt> which listens for security events. - * - * @return the <tt>ZrtpListener</tt> which listens for security events - */ - public SrtpListener getSrtpListener() - { - return this.zrtpListener; - } - - /** - * Method for getting the default secure status value for communication - * - * @return the default enabled/disabled status value for secure - * communication - */ - public boolean getSecureCommunicationStatus() - { - return - (zrtpEngine != null) && zrtpEngine.getSecureCommunicationStatus(); - } - - /** - * Sets the SAS verification + /* + * (non-Javadoc) * - * @param verified the new SAS verification status - */ - public void setSASVerification(boolean verified) - { - ZRTPTransformEngine engine = getTransformEngine(); - - if (verified) - engine.SASVerified(); - else - engine.resetSASVerified(); - } - - /** - * Returns the zrtp engine currently used by this stream. - * @return the zrtp engine - */ - public ZRTPTransformEngine getTransformEngine() - { - if(zrtpEngine == null) - { - zrtpEngine = new ZRTPTransformEngine(); - - // NOTE: set paranoid mode before initializing - // zrtpEngine.setParanoidMode(paranoidMode); - zrtpEngine.initialize( - "GNUZRTP4J.zid", - false, - ZrtpConfigureUtils.getZrtpConfiguration()); - zrtpEngine.setUserCallback(new SecurityEventManager(this)); - } - return zrtpEngine; - } - - /** - * When in multistream mode, enables the master session. - * @param masterSession whether current control, controls the master session. - */ - public void setMasterSession(boolean masterSession) - { - // by default its not master, change only if set to be master - // sometimes (jingle) streams are re-initing and - // we must reuse old value (true) event that false is submitted - if(masterSession) - this.masterSession = masterSession; - } - - /** - * Starts and enables zrtp in the stream holding this control. - * @param mediaType the media type of the stream this control controls. + * @see + * net.java.sip.communicator.service.neomedia.ZrtpControl#getCiperString() */ - public void start(MediaType mediaType) + public String getCipherString() { - boolean zrtpAutoStart; - - // ZRTP engine initialization - ZRTPTransformEngine engine = getTransformEngine(); - // Create security user callback for each peer. - SecurityEventManager securityEventManager = engine.getUserCallback(); - - // Decide if this will become the ZRTP Master session: - // - Statement: audio media session will be started before video - // media session - // - if no other audio session was started before then this will - // become - // ZRTP Master session - // - only the ZRTP master sessions start in "auto-sensing" mode - // to immediately catch ZRTP communication from other client - // - after the master session has completed its key negotiation - // it will start other media sessions (see SCCallback) - if (masterSession) - { - zrtpAutoStart = true; - securityEventManager.setDHSession(true); - - // we know that audio is considered as master for zrtp - securityEventManager.setSessionType( - mediaType.equals(MediaType.AUDIO) ? - SecurityEventManager.AUDIO_SESSION - : SecurityEventManager.VIDEO_SESSION - ); - } - else - { - // check whether video was not already started - // it may happen when using multistreams, audio has inited - // and started video - // initially engine has value enableZrtp = false - zrtpAutoStart = zrtpEngine.isEnableZrtp(); - securityEventManager.setSessionType( - mediaType.equals(MediaType.AUDIO) ? - SecurityEventManager.AUDIO_SESSION - : SecurityEventManager.VIDEO_SESSION); - } - engine.setConnector(zrtpConnector); - - securityEventManager.setSrtpListener(zrtpListener); - - // tells the engine whether to autostart(enable) - // zrtp communication, if false it just passes packets without - // transformation - engine.setEnableZrtp(zrtpAutoStart); - - engine.sendInfo( - ZrtpCodes.MessageSeverity.Info, - EnumSet.of( - ZRTPCustomInfoCodes.ZRTPEnabledByDefault)); + return getTransformEngine().getUserCallback().getCipherString(); } /** - * Start multi-stream ZRTP sessions. - * - * After the ZRTP Master (DH) session reached secure state the SCCallback - * calls this method to start the multi-stream ZRTP sessions. + * Get negotiated ZRTP protocol version. * - * enable auto-start mode (auto-sensing) to the engine. - * @param master master SRTP data + * @return the integer representation of the negotiated ZRTP protocol version. */ - public void setMultistream(SrtpControl master) + public int getCurrentProtocolVersion() { - if(master == null || master == this) - return; - - if(!(master instanceof ZrtpControlImpl)) - throw new IllegalArgumentException("master is no ZRTP control"); - - ZRTPTransformEngine engine = getTransformEngine(); - - engine.setMultiStrParams(((ZrtpControlImpl) master) - .getTransformEngine().getMultiStrParams()); - engine.setEnableZrtp(true); + return ((zrtpEngine != null) ? zrtpEngine.getCurrentProtocolVersion() : 0); } /** @@ -275,6 +129,16 @@ public String[] getHelloHashSep(int index) return getTransformEngine().getHelloHashSep(index); } + /** + * Get number of supported ZRTP protocol versions. + * + * @return the number of supported ZRTP protocol versions. + */ + public int getNumberSupportedVersions() + { + return ((zrtpEngine != null) ? zrtpEngine.getNumberSupportedVersions(): 0); + } + /** * Get the peer's Hello Hash data. * @@ -292,35 +156,41 @@ public String getPeerHelloHash() { return new String(); } - /** - * Get number of supported ZRTP protocol versions. + /* + * (non-Javadoc) * - * @return the number of supported ZRTP protocol versions. + * @see + * net.java.sip.communicator.service.neomedia.ZrtpControl#getPeerZid + * () */ - public int getNumberSupportedVersions() + public byte[] getPeerZid() { - return ((zrtpEngine != null) ? zrtpEngine.getNumberSupportedVersions(): 0); + return getTransformEngine().getPeerZid(); } - /** - * Get negotiated ZRTP protocol version. + /* + * (non-Javadoc) * - * @return the integer representation of the negotiated ZRTP protocol version. + * @see + * net.java.sip.communicator.service.neomedia.ZrtpControl#getPeerZidString() */ - public int getCurrentProtocolVersion() + public String getPeerZidString() { - return ((zrtpEngine != null) ? zrtpEngine.getCurrentProtocolVersion() : 0); + byte[] zid = getPeerZid(); + String s = new String(ZrtpUtils.bytesToHexString(zid, zid.length)); + return s; } /** - * Sets the <tt>RTPConnector</tt> which is to use or uses this ZRTP engine. + * Method for getting the default secure status value for communication * - * @param connector the <tt>RTPConnector</tt> which is to use or uses this - * ZRTP engine + * @return the default enabled/disabled status value for secure + * communication */ - public void setConnector(AbstractRTPConnector connector) + public boolean getSecureCommunicationStatus() { - zrtpConnector = connector; + return + (zrtpEngine != null) && zrtpEngine.getSecureCommunicationStatus(); } /* @@ -335,16 +205,49 @@ public String getSecurityString() return getTransformEngine().getUserCallback().getSecurityString(); } - /* - * (non-Javadoc) + /** + * Returns the <tt>ZrtpListener</tt> which listens for security events. * - * @see - * net.java.sip.communicator.service.neomedia.ZrtpControl#getCiperString - * () + * @return the <tt>ZrtpListener</tt> which listens for security events */ - public String getCipherString() + public SrtpListener getSrtpListener() { - return getTransformEngine().getUserCallback().getCipherString(); + return this.zrtpListener; + } + + /** + * Returns the timeout value that will we will wait + * and fire timeout secure event if call is not secured. + * The value is in milliseconds. + * @return the timeout value that will we will wait + * and fire timeout secure event if call is not secured. + */ + public long getTimeoutValue() + { + // this is the default value as mentioned in rfc6189 + // we will later grab this setting from zrtp + return 3750; + } + + /** + * Returns the zrtp engine currently used by this stream. + * @return the zrtp engine + */ + public ZRTPTransformEngine getTransformEngine() + { + if(zrtpEngine == null) + { + zrtpEngine = new ZRTPTransformEngine(); + + // NOTE: set paranoid mode before initializing + // zrtpEngine.setParanoidMode(paranoidMode); + zrtpEngine.initialize( + "GNUZRTP4J.zid", + false, + ZrtpConfigureUtils.getZrtpConfiguration()); + zrtpEngine.setUserCallback(new SecurityEventManager(this)); + } + return zrtpEngine; } /* @@ -359,53 +262,144 @@ public boolean isSecurityVerified() return getTransformEngine().getUserCallback().isSecurityVerified(); } - /* - * (non-Javadoc) + /** + * Returns false, ZRTP exchanges is keys over the media path. * - * @see - * net.java.sip.communicator.service.neomedia.ZrtpControl#getPeerZid - * () + * @return false */ - public byte[] getPeerZid() + public boolean requiresSecureSignalingTransport() { - return getTransformEngine().getPeerZid(); + return false; } - /* - * (non-Javadoc) + /** + * Sets the <tt>RTPConnector</tt> which is to use or uses this ZRTP engine. * - * @see - * net.java.sip.communicator.service.neomedia.ZrtpControl#getPeerZidString - * () + * @param connector the <tt>RTPConnector</tt> which is to use or uses this + * ZRTP engine */ - public String getPeerZidString() + public void setConnector(AbstractRTPConnector connector) { - byte[] zid = getPeerZid(); - String s = new String(ZrtpUtils.bytesToHexString(zid, zid.length)); - return s; + zrtpConnector = connector; } /** - * Returns false, ZRTP exchanges is keys over the media path. + * When in multistream mode, enables the master session. + * @param masterSession whether current control, controls the master session. + */ + public void setMasterSession(boolean masterSession) + { + // by default its not master, change only if set to be master + // sometimes (jingle) streams are re-initing and + // we must reuse old value (true) event that false is submitted + if(masterSession) + this.masterSession = masterSession; + } + + /** + * Start multi-stream ZRTP sessions. * - * @return false + * After the ZRTP Master (DH) session reached secure state the SCCallback + * calls this method to start the multi-stream ZRTP sessions. + * + * enable auto-start mode (auto-sensing) to the engine. + * @param master master SRTP data */ - public boolean requiresSecureSignalingTransport() + public void setMultistream(SrtpControl master) { - return false; + if(master == null || master == this) + return; + + if(!(master instanceof ZrtpControlImpl)) + throw new IllegalArgumentException("master is no ZRTP control"); + + ZRTPTransformEngine engine = getTransformEngine(); + + engine.setMultiStrParams(((ZrtpControlImpl) master) + .getTransformEngine().getMultiStrParams()); + engine.setEnableZrtp(true); } /** - * Returns the timeout value that will we will wait - * and fire timeout secure event if call is not secured. - * The value is in milliseconds. - * @return the timeout value that will we will wait - * and fire timeout secure event if call is not secured. + * Sets the SAS verification + * + * @param verified the new SAS verification status */ - public long getTimeoutValue() + public void setSASVerification(boolean verified) { - // this is the default value as mentioned in rfc6189 - // we will later grab this setting from zrtp - return 3750; + ZRTPTransformEngine engine = getTransformEngine(); + + if (verified) + engine.SASVerified(); + else + engine.resetSASVerified(); + } + + /** + * Sets a <tt>ZrtpListener</tt> that will listen for zrtp security events. + * + * @param zrtpListener the <tt>ZrtpListener</tt> to set + */ + public void setSrtpListener(SrtpListener zrtpListener) + { + this.zrtpListener = zrtpListener; + } + + /** + * Starts and enables zrtp in the stream holding this control. + * @param mediaType the media type of the stream this control controls. + */ + public void start(MediaType mediaType) + { + boolean zrtpAutoStart; + + // ZRTP engine initialization + ZRTPTransformEngine engine = getTransformEngine(); + // Create security user callback for each peer. + SecurityEventManager securityEventManager = engine.getUserCallback(); + + // Decide if this will become the ZRTP Master session: + // - Statement: audio media session will be started before video + // media session + // - if no other audio session was started before then this will + // become + // ZRTP Master session + // - only the ZRTP master sessions start in "auto-sensing" mode + // to immediately catch ZRTP communication from other client + // - after the master session has completed its key negotiation + // it will start other media sessions (see SCCallback) + int sessionType + = MediaType.AUDIO.equals(mediaType) + ? SecurityEventManager.AUDIO_SESSION + : SecurityEventManager.VIDEO_SESSION; + + if (masterSession) + { + zrtpAutoStart = true; + securityEventManager.setDHSession(true); + + // we know that audio is considered as master for zrtp + securityEventManager.setSessionType(sessionType); + } + else + { + // check whether video was not already started + // it may happen when using multistreams, audio has inited + // and started video + // initially engine has value enableZrtp = false + zrtpAutoStart = zrtpEngine.isEnableZrtp(); + securityEventManager.setSessionType(sessionType); + } + engine.setConnector(zrtpConnector); + + securityEventManager.setSrtpListener(zrtpListener); + + // tells the engine whether to autostart(enable) + // zrtp communication, if false it just passes packets without + // transformation + engine.setEnableZrtp(zrtpAutoStart); + engine.sendInfo( + ZrtpCodes.MessageSeverity.Info, + EnumSet.of(ZRTPCustomInfoCodes.ZRTPEnabledByDefault)); } } diff --git a/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java b/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java index f5545b71..6bea28d1 100644 --- a/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java +++ b/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java @@ -30,35 +30,16 @@ public class SDesControlImpl /** * List of enabled crypto suites. */ - private List<String> enabledCryptoSuites = new ArrayList<String>(3) - { - private static final long serialVersionUID = 0L; - - { - add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); - add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32); - add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80); - } - }; - + private final List<String> enabledCryptoSuites = new ArrayList<String>(3); /** * List of supported crypto suites. */ - private final List<String> supportedCryptoSuites = new ArrayList<String>(3) - { - private static final long serialVersionUID = 0L; + private final List<String> supportedCryptoSuites = new ArrayList<String>(3); - { - add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); - add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32); - add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80); - } - }; - - private SrtpSDesFactory sdesFactory; private SrtpCryptoAttribute[] attributes; private SDesTransformEngine engine; + private SrtpSDesFactory sdesFactory; private SrtpCryptoAttribute selectedInAttribute; private SrtpCryptoAttribute selectedOutAttribute; private SrtpListener srtpListener; @@ -68,30 +49,29 @@ public class SDesControlImpl */ public SDesControlImpl() { - sdesFactory = new SrtpSDesFactory(); - Random r = new Random() { - private static final long serialVersionUID = 0L; - - @Override - public void nextBytes(byte[] bytes) - { - ZrtpFortuna.getInstance().getFortuna().nextBytes(bytes); - } - }; - sdesFactory.setRandomGenerator(r); - } - - public void setEnabledCiphers(Iterable<String> ciphers) - { - enabledCryptoSuites.clear(); - for(String c : ciphers) - enabledCryptoSuites.add(c); - } + enabledCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); + enabledCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32); + enabledCryptoSuites.add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80); + } + { + supportedCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); + supportedCryptoSuites.add(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32); + supportedCryptoSuites.add(SrtpCryptoSuite.F8_128_HMAC_SHA1_80); + } - public Iterable<String> getSupportedCryptoSuites() - { - return Collections.unmodifiableList(supportedCryptoSuites); + sdesFactory = new SrtpSDesFactory(); + sdesFactory.setRandomGenerator( + new Random() + { + private static final long serialVersionUID = 0L; + + @Override + public void nextBytes(byte[] bytes) + { + ZrtpFortuna.getInstance().getFortuna().nextBytes(bytes); + } + }); } public void cleanup() @@ -103,14 +83,26 @@ public void cleanup() } } - public void setSrtpListener(SrtpListener srtpListener) + public SrtpCryptoAttribute getInAttribute() { - this.srtpListener = srtpListener; + return selectedInAttribute; } - public SrtpListener getSrtpListener() + /** + * Returns the crypto attributes enabled on this computer. + * + * @return The crypto attributes enabled on this computer. + */ + public SrtpCryptoAttribute[] getInitiatorCryptoAttributes() { - return srtpListener; + initAttributes(); + + return attributes; + } + + public SrtpCryptoAttribute getOutAttribute() + { + return selectedOutAttribute; } public boolean getSecureCommunicationStatus() @@ -118,41 +110,24 @@ public boolean getSecureCommunicationStatus() return engine != null; } - /** - * Not used. - * @param masterSession not used. - */ - public void setMasterSession(boolean masterSession) - {} - - public void start(MediaType type) + public SrtpListener getSrtpListener() { - // in srtp the started and security event is one after another - // in some other security mechanisms (e.g. zrtp) there can be started - // and no security one or security timeout event - srtpListener.securityNegotiationStarted( - type.equals(MediaType.AUDIO) ? - SecurityEventManager.AUDIO_SESSION - : SecurityEventManager.VIDEO_SESSION, - this); - - srtpListener.securityTurnedOn( - type.equals(MediaType.AUDIO) ? - SecurityEventManager.AUDIO_SESSION - : SecurityEventManager.VIDEO_SESSION, - selectedInAttribute.getCryptoSuite().encode(), this); + return srtpListener; } - public void setMultistream(SrtpControl master) + public Iterable<String> getSupportedCryptoSuites() { + return Collections.unmodifiableList(supportedCryptoSuites); } public TransformEngine getTransformEngine() { if(engine == null) { - engine = new SDesTransformEngine(selectedInAttribute, - selectedOutAttribute); + engine + = new SDesTransformEngine( + selectedInAttribute, + selectedOutAttribute); } return engine; } @@ -168,23 +143,50 @@ private void initAttributes() attributes = new SrtpCryptoAttribute[enabledCryptoSuites.size()]; for (int i = 0; i < attributes.length; i++) { - attributes[i] = sdesFactory.createCryptoAttribute( - i + 1, - enabledCryptoSuites.get(i)); + attributes[i] + = sdesFactory.createCryptoAttribute( + i + 1, + enabledCryptoSuites.get(i)); } } } /** - * Returns the crypto attributes enabled on this computer. + * Select the local crypto attribute from the initial offering (@see + * {@link #getInitiatorCryptoAttributes()}) based on the peer's first + * matching cipher suite. * - * @return The crypto attributes enabled on this computer. + * @param peerAttributes The peer's crypto offers. + * @return A SrtpCryptoAttribute when a matching cipher suite was found; + * <tt>null</tt>, otherwise. */ - public SrtpCryptoAttribute[] getInitiatorCryptoAttributes() + public SrtpCryptoAttribute initiatorSelectAttribute( + Iterable<SrtpCryptoAttribute> peerAttributes) { - initAttributes(); + for (SrtpCryptoAttribute peerCA : peerAttributes) + { + for (SrtpCryptoAttribute localCA : attributes) + { + if (localCA.getCryptoSuite().equals(peerCA.getCryptoSuite())) + { + selectedInAttribute = peerCA; + selectedOutAttribute = localCA; + return peerCA; + } + } + } + return null; + } - return attributes; + /** + * Returns <tt>true</tt>, SDES always requires the secure transport of its + * keys. + * + * @return <tt>true</tt> + */ + public boolean requiresSecureSignalingTransport() + { + return true; } /** @@ -193,9 +195,8 @@ public SrtpCryptoAttribute[] getInitiatorCryptoAttributes() * is running in the role as responder. * * @param peerAttributes The peer's crypto attribute offering. - * - * @return The local crypto attribute for the answer of the offer or null if - * no matching cipher suite could be found. + * @return The local crypto attribute for the answer of the offer or + * <tt>null</tt> if no matching cipher suite could be found. */ public SrtpCryptoAttribute responderSelectAttribute( Iterable<SrtpCryptoAttribute> peerAttributes) @@ -216,55 +217,49 @@ public SrtpCryptoAttribute responderSelectAttribute( return null; } - /** - * Select the local crypto attribute from the initial offering (@see - * {@link #getInitiatorCryptoAttributes()}) based on the peer's first - * matching cipher suite. - * - * @param peerAttributes The peer's crypto offers. - * - * @return A SrtpCryptoAttribute when a matching cipher suite was found. - * Null otherwise. - */ - public SrtpCryptoAttribute initiatorSelectAttribute( - Iterable<SrtpCryptoAttribute> peerAttributes) + public void setConnector(AbstractRTPConnector newValue) { - for (SrtpCryptoAttribute peerCA : peerAttributes) - { - for (SrtpCryptoAttribute localCA : attributes) - { - if (localCA.getCryptoSuite().equals(peerCA.getCryptoSuite())) - { - selectedInAttribute = peerCA; - selectedOutAttribute = localCA; - return peerCA; - } - } - } - return null; } - public SrtpCryptoAttribute getInAttribute() + public void setEnabledCiphers(Iterable<String> ciphers) { - return selectedInAttribute; + enabledCryptoSuites.clear(); + for(String c : ciphers) + enabledCryptoSuites.add(c); } - public SrtpCryptoAttribute getOutAttribute() + /** + * Not used. + * + * @param masterSession not used. + */ + public void setMasterSession(boolean masterSession) { - return selectedOutAttribute; } - public void setConnector(AbstractRTPConnector newValue) + public void setMultistream(SrtpControl master) { } - /** - * Returns true, SDES always requires the secure transport of its keys. - * - * @return true - */ - public boolean requiresSecureSignalingTransport() + public void setSrtpListener(SrtpListener srtpListener) { - return true; + this.srtpListener = srtpListener; + } + + public void start(MediaType type) + { + // in srtp the started and security event is one after another in some + // other security mechanisms (e.g. zrtp) there can be started and no + // security one or security timeout event + int sessionType + = MediaType.AUDIO.equals(type) + ? SecurityEventManager.AUDIO_SESSION + : SecurityEventManager.VIDEO_SESSION; + + srtpListener.securityNegotiationStarted(sessionType, this); + srtpListener.securityTurnedOn( + sessionType, + selectedInAttribute.getCryptoSuite().encode(), + this); } } diff --git a/src/org/jitsi/service/neomedia/SDesControl.java b/src/org/jitsi/service/neomedia/SDesControl.java index 0e8e34cc..c1bd9d72 100644 --- a/src/org/jitsi/service/neomedia/SDesControl.java +++ b/src/org/jitsi/service/neomedia/SDesControl.java @@ -24,18 +24,11 @@ public interface SDesControl "net.java.sip.communicator.service.neomedia.SDES_CIPHER_SUITES"; /** - * Set the enabled SDES ciphers. - * - * @param ciphers The list of enabled ciphers. - */ - public void setEnabledCiphers(Iterable<String> ciphers); - - /** - * Gets all supported cipher suites. + * Gets the crypto attribute of the incoming MediaStream. * - * @return all supported cipher suites. + * @return the crypto attribute of the incoming MediaStream. */ - public Iterable<String> getSupportedCryptoSuites(); + public SrtpCryptoAttribute getInAttribute(); /** * Returns the crypto attributes enabled on this computer. @@ -45,40 +38,47 @@ public interface SDesControl public SrtpCryptoAttribute[] getInitiatorCryptoAttributes(); /** - * Chooses a supported crypto attribute from the peer's list of supplied - * attributes and creates the local crypto attribute. Used when the control - * is running in the role as responder. + * Gets the crypto attribute of the outgoing MediaStream. * - * @param peerAttributes The peer's crypto attribute offering. + * @return the crypto attribute of the outgoing MediaStream. + */ + public SrtpCryptoAttribute getOutAttribute(); + + /** + * Gets all supported cipher suites. * - * @return The local crypto attribute for the answer of the offer or null if - * no matching cipher suite could be found. + * @return all supported cipher suites. */ - public SrtpCryptoAttribute responderSelectAttribute( - Iterable<SrtpCryptoAttribute> peerAttributes); + public Iterable<String> getSupportedCryptoSuites(); /** - * Select the local crypto attribute from the initial offering (@see - * {@link #getInitiatorCryptoAttributes()}) based on the peer's first + * Selects the local crypto attribute from the initial offering + * ({@link #getInitiatorCryptoAttributes()}) based on the peer's first * matching cipher suite. * * @param peerAttributes The peer's crypto offers. - * - * @return A SrtpCryptoAttribute when a matching cipher suite was found. - * Null otherwise. + * @return A SrtpCryptoAttribute when a matching cipher suite was found; + * <tt>null</tt>, otherwise. */ public SrtpCryptoAttribute initiatorSelectAttribute( Iterable<SrtpCryptoAttribute> peerAttributes); /** - * Gets the crypto attribute of the incoming MediaStream. - * @return the crypto attribute of the incoming MediaStream. + * Chooses a supported crypto attribute from the peer's list of supplied + * attributes and creates the local crypto attribute. Used when the control + * is running in the role as responder. + * + * @param peerAttributes The peer's crypto attribute offering. + * @return The local crypto attribute for the answer of the offer or + * <tt>null</tt> if no matching cipher suite could be found. */ - public SrtpCryptoAttribute getInAttribute(); + public SrtpCryptoAttribute responderSelectAttribute( + Iterable<SrtpCryptoAttribute> peerAttributes); /** - * Gets the crypto attribute of the outgoing MediaStream. - * @return the crypto attribute of the outgoing MediaStream. + * Sets the enabled SDES ciphers. + * + * @param ciphers The list of enabled ciphers. */ - public SrtpCryptoAttribute getOutAttribute(); + public void setEnabledCiphers(Iterable<String> ciphers); } diff --git a/src/org/jitsi/service/neomedia/SrtpControl.java b/src/org/jitsi/service/neomedia/SrtpControl.java index 97c7b2ba..778ac12c 100644 --- a/src/org/jitsi/service/neomedia/SrtpControl.java +++ b/src/org/jitsi/service/neomedia/SrtpControl.java @@ -23,12 +23,13 @@ public interface SrtpControl public void cleanup(); /** - * Sets a <tt>SrtpListener</tt> that will listen for security events. + * Gets the default secure/insecure communication status for the supported + * call sessions. * - * @param srtpListener the <tt>SrtpListener</tt> that will receive the - * events + * @return default secure communication status for the supported call + * sessions. */ - public void setSrtpListener(SrtpListener srtpListener); + public boolean getSecureCommunicationStatus(); /** * Returns the <tt>SrtpListener</tt> which listens for security events. @@ -38,55 +39,57 @@ public interface SrtpControl public SrtpListener getSrtpListener(); /** - * Gets the default secure/insecure communication status for the supported - * call sessions. + * Returns the transform engine currently used by this stream. * - * @return default secure communication status for the supported - * call sessions. + * @return the RTP stream transformation engine */ - public boolean getSecureCommunicationStatus(); + public TransformEngine getTransformEngine(); /** - * When in multistream mode, enables the master session. - * @param masterSession whether current control, controls the master session. + * Indicates if the key exchange method is dependent on secure transport of + * the signaling channel. + * + * @return <tt>true</tt> when secure signaling is required to make the + * encryption secure; <tt>false</tt>, otherwise. */ - public void setMasterSession(boolean masterSession); + public boolean requiresSecureSignalingTransport(); /** - * Starts and enables zrtp in the stream holding this control. - * @param mediaType the media type of the stream this control controls. + * Sets the <tt>RTPConnector</tt> which is to use or uses this SRTP engine. + * + * @param connector the <tt>RTPConnector</tt> which is to use or uses this + * SRTP engine */ - public void start(MediaType mediaType); + public void setConnector(AbstractRTPConnector connector); /** - * Sets the multistream data, which means that the master stream - * has successfully started and this will start all other streams - * in this session. - * @param master The security control of the master stream. + * When in multistream mode, enables the master session. + * + * @param masterSession whether current control, controls the master session. */ - public void setMultistream(SrtpControl master); + public void setMasterSession(boolean masterSession); /** - * Returns the transform engine currently used by this stream. + * Sets the multistream data, which means that the master stream has + * successfully started and this will start all other streams in this + * session. * - * @return the RTP stream transformation engine + * @param master The security control of the master stream. */ - public TransformEngine getTransformEngine(); + public void setMultistream(SrtpControl master); /** - * Sets the <tt>RTPConnector</tt> which is to use or uses this SRTP engine. + * Sets a <tt>SrtpListener</tt> that will listen for security events. * - * @param connector the <tt>RTPConnector</tt> which is to use or uses this - * SRTP engine + * @param srtpListener the <tt>SrtpListener</tt> that will receive the + * events */ - public void setConnector(AbstractRTPConnector connector); + public void setSrtpListener(SrtpListener srtpListener); /** - * Indicates if the key exchange method is dependent on secure transport of - * the signaling channel. + * Starts and enables zrtp in the stream holding this control. * - * @return True when secure signaling is required to make the encryption - * secure, false otherwise. + * @param mediaType the media type of the stream this control controls. */ - public boolean requiresSecureSignalingTransport(); + public void start(MediaType mediaType); } diff --git a/src/org/jitsi/service/neomedia/ZrtpControl.java b/src/org/jitsi/service/neomedia/ZrtpControl.java index 01557923..d9173d89 100644 --- a/src/org/jitsi/service/neomedia/ZrtpControl.java +++ b/src/org/jitsi/service/neomedia/ZrtpControl.java @@ -15,114 +15,101 @@ public interface ZrtpControl extends SrtpControl { /** - * Return the zrtp hello hash String. + * Gets the cipher information for the current media stream. * - * @param index - * Hello hash of the Hello packet identfied by index. Index must - * be 0 <= index < SUPPORTED_ZRTP_VERSIONS. - * @return String the zrtp hello hash. + * @return the cipher information string. */ - public String getHelloHash(int index); + public String getCipherString(); /** - * Get the ZRTP Hello Hash data - separate strings. + * Gets the negotiated ZRTP protocol version. * - * @param index - * Hello hash of the Hello packet identfied by index. Index must - * be 0 <= index < SUPPORTED_ZRTP_VERSIONS. - * @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 <code>null</code> - * if ZRTP is not available. + * @return the <tt>int</tt> representation of the negotiated ZRTP protocol + * version. */ - public String[] getHelloHashSep(int index); + public int getCurrentProtocolVersion(); /** - * Get the peer's Hello Hash data. - * - * Use this method to get the peer's Hello Hash data. The method returns the - * data as a string. + * Returns the zrtp hello hash String. * - * @return a String containing the Hello hash value as hex-digits. - * Peer Hello hash is available after we received a Hello packet - * from our peer. If peer's hello hash is not available return null. + * @param index Hello hash of the Hello packet identified by index. Must be + * <code>0 <= index < SUPPORTED_ZRTP_VERSIONS</code>. + * @return String the zrtp hello hash. */ - public String getPeerHelloHash(); + public String getHelloHash(int index); /** - * Gets the SAS for the current media stream. + * Gets the ZRTP Hello Hash data - separate strings. * - * @return the four character ZRTP SAS. + * @param index Hello hash of the Hello packet identified by index. Must be + * <code>0 <= index < SUPPORTED_ZRTP_VERSIONS</code>. + * @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 <tt>null</tt> if ZRTP is not available. */ - public String getSecurityString(); + public String[] getHelloHashSep(int index); /** - * Gets the cipher information for the current media stream. + * Gets the number of supported ZRTP protocol versions. * - * @return the cipher information string. + * @return the number of supported ZRTP protocol versions. */ - public String getCipherString(); + public int getNumberSupportedVersions(); /** - * Gets the status of the SAS verification. + * Gets the peer's Hello Hash data as a <tt>String</tt>. * - * @return true when the SAS has been verified. + * @return a String containing the Hello hash value as hex-digits. Peer + * Hello hash is available after we received a Hello packet from our peer. + * If peer's hello hash is not available, returns <tt>null</tt>. */ - public boolean isSecurityVerified(); + public String getPeerHelloHash(); /** - * Sets the SAS verification + * Gets other party's ZID (ZRTP Identifier) data that was received during + * ZRTP processing. The ZID data can be retrieved after ZRTP receives the + * first Hello packet from the other party. * - * @param verified the new SAS verification status + * @return the ZID data as a <tt>byte</tt> array. */ - public void setSASVerification(boolean verified); + public byte[] getPeerZid(); /** - * Returns the timeout value that will we will wait - * and fire timeout secure event if call is not secured. - * The value is in milliseconds. - * @return the timeout value that will we will wait - * and fire timeout secure event if call is not secured. + * Gets other party's ZID (ZRTP Identifier) data that was received during + * ZRTP processing as a <tt>String</tt>. The ZID data can be retrieved after + * ZRTP receives the first Hello packet from the other party. + * + * @return the ZID data as a <tt>String</tt>. */ - public long getTimeoutValue(); + public String getPeerZidString(); /** - * Get other party's ZID (ZRTP Identifier) data - * - * This functions returns the other party's ZID that was receivied during - * ZRTP processing. - * - * The ZID data can be retrieved after ZRTP receive the first Hello packet - * from the other party. + * Gets the SAS for the current media stream. * - * @return the ZID data as byte array. + * @return the four character ZRTP SAS. */ - public byte[] getPeerZid(); + public String getSecurityString(); /** - * Get other party's ZID (ZRTP Identifier) data as String + * Returns the timeout value in milliseconds that we will wait and fire + * timeout secure event if call is not secured. * - * This functions returns the other party's ZID that was receivied during - * ZRTP processing. - * - * The ZID data can be retrieved after ZRTP receive the first Hello packet - * from the other party. - * - * @return the ZID data as String. + * @return the timeout value in milliseconds that we will wait and fire + * timeout secure event if call is not secured. */ - public String getPeerZidString(); + public long getTimeoutValue(); /** - * Get number of supported ZRTP protocol versions. + * Gets the status of the SAS verification. * - * @return the number of supported ZRTP protocol versions. + * @return <tt>true</tt> when the SAS has been verified. */ - public int getNumberSupportedVersions(); + public boolean isSecurityVerified(); /** - * Get negotiated ZRTP protocol version. + * Sets the SAS verification * - * @return the integer representation of the negotiated ZRTP protocol version. + * @param verified the new SAS verification status */ - public int getCurrentProtocolVersion(); + public void setSASVerification(boolean verified); } -- GitLab