Enable zrtp-hash sending in sdp.

cusax-fix
Damian Minkov 16 years ago
parent e129579693
commit 8365a3cedb

@ -75,10 +75,13 @@ public class AudioMediaStreamImpl
* @param device the <tt>MediaDevice</tt> the new instance is to use for
* both capture and playback of audio exchanged via the specified
* <tt>StreamConnector</tt>
* @param zrtpControl a control which is already created, used to control
* the zrtp operations.
*/
public AudioMediaStreamImpl(StreamConnector connector, MediaDevice device)
public AudioMediaStreamImpl(StreamConnector connector, MediaDevice device,
ZrtpControlImpl zrtpControl)
{
super(connector, device);
super(connector, device, zrtpControl);
}
/**

@ -107,13 +107,39 @@ public class MediaServiceImpl
public MediaStream createMediaStream(
StreamConnector connector,
MediaDevice device)
{
return createMediaStream(connector, device, null);
}
/**
* Creates a new <tt>MediaStream</tt> instance which will use the specified
* <tt>MediaDevice</tt> for both capture and playback of media exchanged
* via the specified <tt>StreamConnector</tt>.
*
* @param connector the <tt>StreamConnector</tt> that the new
* <tt>MediaStream</tt> instance is to use for sending and receiving media
* @param device the <tt>MediaDevice</tt> that the new <tt>MediaStream</tt>
* instance is to use for both capture and playback of media exchanged via
* the specified <tt>connector</tt>
* @param zrtpControl a control which is already created, used to control
* the zrtp operations.
*
* @return a new <tt>MediaStream</tt> instance
* @see MediaService#createMediaStream(StreamConnector, MediaDevice)
*/
public MediaStream createMediaStream(
StreamConnector connector,
MediaDevice device,
ZrtpControl zrtpControl)
{
switch (device.getMediaType())
{
case AUDIO:
return new AudioMediaStreamImpl(connector, device);
return new AudioMediaStreamImpl(connector, device,
(ZrtpControlImpl)zrtpControl);
case VIDEO:
return new VideoMediaStreamImpl(connector, device);
return new VideoMediaStreamImpl(connector, device,
(ZrtpControlImpl)zrtpControl);
default:
return null;
}
@ -431,4 +457,15 @@ void start()
void stop()
{
}
/**
* Creates <tt>ZrtpControl</tt> used to control all zrtp options
* on particular stream.
*
* @return ZrtpControl instance.
*/
public ZrtpControl createZrtpControl()
{
return new ZrtpControlImpl();
}
}

@ -169,12 +169,6 @@ public class MediaStreamImpl
*/
private ZrtpControlImpl zrtpControl = null;
/**
* The zrtp TransformEngine used for the current rtp part of the stream.
*/
private ZRTPTransformEngine zrtpEngine = null;
/**
* The map of currently active <tt>RTPExtension</tt>s and the IDs that they
* have been assigned for the lifetime of this <tt>MediaStream</tt>.
@ -198,10 +192,12 @@ public class MediaStreamImpl
* @param device the <tt>MediaDevice</tt> the new instance is to use for
* both capture and playback of media exchanged via the specified
* <tt>StreamConnector</tt>
* @param zrtpControl a control which is already created, used to control
* the zrtp operations.
*/
public MediaStreamImpl(StreamConnector connector, MediaDevice device)
public MediaStreamImpl(StreamConnector connector, MediaDevice device,
ZrtpControlImpl zrtpControl)
{
/*
* XXX Set the device early in order to make sure that its of the right
* type because we do not support just about any MediaDevice yet.
@ -210,12 +206,20 @@ public MediaStreamImpl(StreamConnector connector, MediaDevice device)
this.rtpConnector = new RTPTransformConnector(connector);
if(zrtpControl != null)
{
this.zrtpControl = zrtpControl;
}
else
this.zrtpControl = new ZrtpControlImpl();
this.zrtpControl.setConnector(rtpConnector);
//register the transform engines that we will be using in this stream.
csrcEngine = new CsrcTransformEngine(this);
zrtpEngine = new ZRTPTransformEngine();
rtpConnector.setEngine(new TransformEngineChain(csrcEngine, zrtpEngine));
rtpConnector.setEngine(new TransformEngineChain(
csrcEngine, this.zrtpControl.getZrtpEngine()));
}
/**
@ -295,8 +299,7 @@ public void close()
stop();
closeSendStreams();
ZRTPTransformEngine engine =
((ZrtpControlImpl)getZrtpControl()).getZrtpEngine();
ZRTPTransformEngine engine = zrtpControl.getZrtpEngine();
if(engine != null)
{
engine.stopZrtp();
@ -394,8 +397,7 @@ else if (dataSource instanceof PullDataSource)
// If a ZRTP engine is availabe then set the SSRC of this stream
// currently ZRTP supports only one SSRC per engine
ZRTPTransformEngine engine =
((ZrtpControlImpl)getZrtpControl()).getZrtpEngine();
ZRTPTransformEngine engine = zrtpControl.getZrtpEngine();
if (engine != null)
{
@ -1568,27 +1570,12 @@ public long[] getRemoteContributingSourceIDs()
return remoteSsrcList;
}
public ZrtpControl getZrtpControl()
{
if(zrtpControl == null)
zrtpControl = new ZrtpControlImpl(this);
return zrtpControl;
}
/**
* Returns the zrtp TransformEngine used for the current stream.
* @return the transform engine.
* The <tt>ZrtpControl</tt> which controlls the zrtp for the current stream.
* @return the <tt>ZrtpControl</tt> for the current stream.
*/
public ZRTPTransformEngine getZrtpEngine()
public ZrtpControl getZrtpControl()
{
return zrtpEngine;
}
/**
* @return the rtpConnector
*/
public RTPTransformConnector getRtpConnector() {
return rtpConnector;
return zrtpControl;
}
}

@ -176,10 +176,13 @@ public int compare(FormatInfo info0, FormatInfo info1)
* @param device the <tt>MediaDevice</tt> the new instance is to use for
* both capture and playback of video exchanged via the specified
* <tt>StreamConnector</tt>
* @param zrtpControl a control which is already created, used to control
* the zrtp operations.
*/
public VideoMediaStreamImpl(StreamConnector connector, MediaDevice device)
public VideoMediaStreamImpl(StreamConnector connector, MediaDevice device,
ZrtpControlImpl zrtpControl)
{
super(connector, device);
super(connector, device, zrtpControl);
}
/**

@ -10,6 +10,7 @@
import java.util.*;
import net.java.sip.communicator.impl.neomedia.transform.*;
import net.java.sip.communicator.impl.neomedia.transform.zrtp.*;
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.neomedia.event.*;
@ -47,17 +48,21 @@ public static enum ZRTPCustomInfoCodes
}
/**
* The stream holding the control.
* The zrtp engine control by this ZrtpControl.
*/
private MediaStreamImpl stream = null;
private ZRTPTransformEngine zrtpEngine = null;
/**
* This is the connector, required to send ZRTP packets
* via the DatagramSocket.
*/
private RTPTransformConnector zrtpConnector = null;
/**
* Creates the control.
* @param stream the stream holding the control.
*/
ZrtpControlImpl(MediaStreamImpl stream)
ZrtpControlImpl()
{
this.stream = stream;
}
/**
@ -115,7 +120,13 @@ public void setSASVerification(boolean verified)
*/
public ZRTPTransformEngine getZrtpEngine()
{
return stream.getZrtpEngine();
if(zrtpEngine == null)
{
zrtpEngine = new ZRTPTransformEngine();
zrtpEngine.initialize("GNUZRTP4J.zid", false);
}
return zrtpEngine;
}
/**
@ -129,7 +140,7 @@ public void start(boolean masterSession)
// Create security user callback for each peer.
SecurityEventManager securityEventManager
= new SecurityEventManager(stream);
= new SecurityEventManager(this);
boolean zrtpAutoStart = false;
@ -159,10 +170,13 @@ public void start(boolean masterSession)
}
// ZRTP engine initialization
ZRTPTransformEngine zrtpEngine = stream.getZrtpEngine();
zrtpEngine.initialize("GNUZRTP4J.zid", zrtpAutoStart);
ZRTPTransformEngine engine = getZrtpEngine();
// tells the engine whether to autostart(enable)
// zrtp communication, if false it just passes packets without
// transformation
engine.setEnableZrtp(zrtpAutoStart);
zrtpEngine.setConnector(stream.getRtpConnector());
zrtpEngine.setConnector(zrtpConnector);
zrtpEngine.setUserCallback(securityEventManager);
@ -191,4 +205,24 @@ public void setMultistream(byte[] multiStreamData)
engine.setEnableZrtp(true);
}
}
/**
* Return the zrtp hello hash String.
*
* @return String the zrtp hello hash.
*/
public String getHelloHash()
{
return getZrtpEngine().getHelloHash();
}
/**
* Sets the RTP connector using this ZRTP engine
*
* @param connector the connector to set
*/
public void setConnector(RTPTransformConnector connector)
{
zrtpConnector = connector;
}
}

@ -64,9 +64,9 @@ public class SecurityEventManager extends ZrtpUserCallback
CallPeerSecurityStatusEvent.VIDEO_SESSION;
/**
* The stream that this manager is associated with.
* The zrtp control that this manager is associated with.
*/
private final MediaStreamImpl mediaStream;
private final ZrtpControlImpl zrtpControl;
/**
* A callback to the instance that created us.
@ -101,13 +101,12 @@ public class SecurityEventManager extends ZrtpUserCallback
/**
* The class constructor.
*
* @param mediaStream the mediaStream that this manager is to be associated
* with.
* @param zrtpControl that this manager is to be associated with.
*/
public SecurityEventManager(MediaStreamImpl mediaStream)
public SecurityEventManager(ZrtpControlImpl zrtpControl)
{
this.mediaStream = mediaStream;
this.securityListener = mediaStream.getZrtpControl().getZrtpListener();
this.zrtpControl = zrtpControl;
this.securityListener = zrtpControl.getZrtpListener();
}
/**
@ -211,8 +210,7 @@ public void showMessage(ZrtpCodes.MessageSeverity sev,
{
securityListener.securityTurnedOn(
sessionType, cipher, sas, isSasVerified,
((ZrtpControlImpl)mediaStream.getZrtpControl()).
getZrtpEngine().getMultiStrParams());
zrtpControl.getZrtpEngine().getMultiStrParams());
}
else
{

@ -286,11 +286,8 @@ public void run()
protected static final int ZRTP_PACKET_HEADER = 12;
/**
* This is the own ZRTP connector, required to send ZRTP packets
* This is the connector, required to send ZRTP packets
* via the DatagramSocket.
* (Note: in order to further multistream support this should be
* replaced with a connector array; each connector would handle
* a stream)
*/
private RTPTransformConnector zrtpConnector = null;

@ -213,6 +213,12 @@ public void videoRemoved(net.java.sip.communicator.service.neomedia
*/
private Object streamAudioLevelListenerLock = new Object();
/**
* Holds the zrtp controls used for the current call.
*/
private Map<MediaType, ZrtpControl> zrtpControls =
new Hashtable<MediaType, ZrtpControl>();
/**
* Creates a new handler that will be managing media streams for
* <tt>peer</tt>.
@ -432,6 +438,9 @@ private void closeStream(MediaType type)
videoStreamConnector = null;
}
}
// clears the zrtp controls used for current call.
zrtpControls.remove(type);
}
/**
@ -557,20 +566,24 @@ private Vector<MediaDescription> createMediaDescriptions()
if(peer.getCall().isSipZrtpAttribute())
{
// try
// {
// String helloHash =
// SipActivator.getMediaService().createZrtpHelloHash();
// System.out.println("eeeeeeeeeee " + helloHash);
// zrtpHelloHashes.put(mediaType, helloHash);
//
// if(helloHash != null && helloHash.length() > 0)
// md.setAttribute("zrtp-hash", helloHash);
//
// } catch (SdpException ex)
// {
// logger.error("Cannot add zrtp-hash to sdp", ex);
// }
try
{
ZrtpControl control = zrtpControls.get(mediaType);
if(control == null)
{
control = SipActivator.getMediaService()
.createZrtpControl();
zrtpControls.put(mediaType, control);
}
String helloHash = control.getHelloHash();
if(helloHash != null && helloHash.length() > 0)
md.setAttribute("zrtp-hash", helloHash);
} catch (SdpException ex)
{
logger.error("Cannot add zrtp-hash to sdp", ex);
}
}
mediaDescs.add(md);
@ -697,7 +710,13 @@ private MediaStream initStream(StreamConnector connector,
if (stream == null)
{
stream = mediaService.createMediaStream(connector, device);
// check whether a control already exists
ZrtpControl control = zrtpControls.get(format.getMediaType());
if(control == null)
stream = mediaService.createMediaStream(connector, device);
else
stream = mediaService.createMediaStream(
connector, device, control);
}
else
{

@ -9,7 +9,6 @@
import java.util.*;
import net.java.sip.communicator.service.neomedia.device.*;
import net.java.sip.communicator.service.neomedia.event.*;
import net.java.sip.communicator.service.neomedia.format.*;
/**
@ -60,6 +59,24 @@ public interface MediaService
public MediaStream createMediaStream(StreamConnector connector,
MediaDevice device);
/**
* Creates a <tt>MediaStream</tt> that will be using the specified
* <tt>MediaDevice</tt> for both capture and playback of media exchanged
* via the specified <tt>StreamConnector</tt>.
*
* @param connector the connector that the stream should use for sending and
* receiving media.
* @param device the device to be used for both capture and playback of
* media exchanged via the specified <tt>StreamConnector</tt>
* @param zrtpControl a control which is already created, used to control
* the zrtp operations.
*
* @return the newly created <tt>MediaStream</tt>.
*/
public MediaStream createMediaStream(StreamConnector connector,
MediaDevice device,
ZrtpControl zrtpControl);
/**
* Creates a new <tt>MediaDevice</tt> which uses a specific
* <tt>MediaDevice</tt> to capture and play back media and performs mixing
@ -88,4 +105,11 @@ public MediaStream createMediaStream(StreamConnector connector,
* with the <tt>MediaStream</tt>s created by this <tt>MediaService</tt>
*/
public MediaFormatFactory getFormatFactory();
/**
* Creates <tt>ZrtpControl</tt> used to control all zrtp options.
*
* @return ZrtpControl instance.
*/
public ZrtpControl createZrtpControl();
}

@ -61,4 +61,11 @@ public interface ZrtpControl
* needed to start rest of the streams in the session.
*/
public void setMultistream(byte[] multiStreamData);
/**
* Return the zrtp hello hash String.
*
* @return String the zrtp hello hash.
*/
public String getHelloHash();
}

Loading…
Cancel
Save