Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jitsi.impl.neomedia;
import gnu.java.zrtp.*;
import gnu.java.zrtp.utils.*;
import java.util.*;
import org.jitsi.impl.neomedia.transform.zrtp.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.event.*;
/**
* Controls zrtp in the MediaStream.
*
* @author Damian Minkov
*/
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
* implementation, needing them for various GUI changes.
*/
public static enum ZRTPCustomInfoCodes
{
ZRTPNotEnabledByUser,
ZRTPDisabledByCallEnd,
ZRTPEngineInitFailure,
ZRTPEnabledByDefault
}
/**
* The zrtp engine control by this ZrtpControl.
*/
private ZRTPTransformEngine zrtpEngine = null;
/**
* This is the connector, required to send ZRTP packets
* via the DatagramSocket.
*/
private AbstractRTPConnector zrtpConnector = null;
/**
* Whether current is master session.
*/
private boolean masterSession = false;
/**
* Creates the control.
*/
ZrtpControlImpl()
{
}
/**
* Cleans up the current zrtp control and its engine.
*/
public void cleanup()
{
if(zrtpEngine != null)
{
zrtpEngine.stopZrtp();
zrtpEngine.cleanup();
}
zrtpEngine = null;
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
*
* @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.
*/
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)
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));
}
/**
* 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.
*
* enable auto-start mode (auto-sensing) to the engine.
* @param master master SRTP data
*/
public void setMultistream(SrtpControl master)
{
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 the zrtp hello hash String.
*
* @return String the zrtp hello hash.
*/
public String getHelloHash()
{
return getTransformEngine().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 <code>null</code>
* if ZRTP is not available.
*/
public String[] getHelloHashSep()
{
return getTransformEngine().getHelloHashSep();
}
/**
* Sets the <tt>RTPConnector</tt> which is to use or uses this ZRTP engine.
*
* @param connector the <tt>RTPConnector</tt> which is to use or uses this
* ZRTP engine
*/
public void setConnector(AbstractRTPConnector connector)
{
zrtpConnector = connector;
}
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.neomedia.ZrtpControl#getSecurityString
* ()
*/
public String getSecurityString()
{
return getTransformEngine().getUserCallback().getSecurityString();
}
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.neomedia.ZrtpControl#getCiperString
* ()
*/
public String getCipherString()
{
return getTransformEngine().getUserCallback().getCipherString();
}
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.neomedia.ZrtpControl#isSecurityVerified
* ()
*/
public boolean isSecurityVerified()
{
return getTransformEngine().getUserCallback().isSecurityVerified();
}
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.neomedia.ZrtpControl#getPeerZid
* ()
*/
public byte[] getPeerZid()
{
return getTransformEngine().getPeerZid();
}
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.neomedia.ZrtpControl#getPeerZidString
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
* ()
*/
public String getPeerZidString()
{
byte[] zid = getPeerZid();
String s = new String(ZrtpUtils.bytesToHexString(zid, zid.length));
return s;
}
/**
* Returns false, ZRTP exchanges is keys over the media path.
*
* @return false
*/
public boolean requiresSecureSignalingTransport()
{
return false;
}
/**
* 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;
}
}