1
2 '''
3 [BETA] TURN protocol generator. TURN is an extension of the STUN
4 protocol. TURN packets are generated using the StunPacket top
5 level container with TURN message types and attributes as needed.
6
7 @author: Michael Eddington
8 @version: $Id: Peach.Generators.turn-pysrc.html 1138 2008-08-16 19:39:03Z meddingt $
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 import re, struct, os
39 from Peach import generator
40 from Peach.Generators import *
41 from Peach.Generators.dictionary import *
42 from Peach.Generators.static import *
43 from Peach.Generators.static import Int8, Int16, Int32
44 from Peach.Generators.stun import *
45
46
47
48
49
66
67
83
84
86 '''
87
88 IP Family 1 byte
89 IP Port 2 bytes
90 IP Address 4 bytes
91
92 '''
93
95 '''
96 @type group: Group
97 @param group: Group to use
98 @type family: Generator
99 @param family: Family (defaults to 0x01 IPV4)
100 @type port: Generator
101 @param port: Port number
102 @type address: Generator
103 @param address: 32bit IPv4 address
104 '''
105 StunMappedAddressAttribute.__init__(self, group, port, address, family);
106 self._type = TurnAttribute.NAT_ADDRESS
107
108
110 '''
111 LIFETIME
112
113 The lifetime attribute represents the duration for which the server
114 will maintain a binding in the absence of data traffic either from or
115 to the client. It is a 32 bit value representing the number of
116 seconds remaining until expiration.
117
118 0 1 2 3
119 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
120 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121 | Lifetime |
122 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123
124 '''
125
127 '''
128 @type group: Group
129 @param group: Group to use
130 @type lifetime: Generator
131 @param lifetime: Lifetime in seconds
132 '''
133 self.setGroup(group)
134 if lifetime != None:
135 self._generator = lifetime
136 self._type = TurnAttribute.LIFETIME
137
140
141
143 '''
144 ALTERNATE-SERVER
145
146 The alternate server represents an alternate IP address and port for
147 a different TURN server to try. It is encoded in the same way as
148 MAPPED-ADDRESS.
149 '''
150
151 - def __init__(self, group, port, address, family = 0x01):
152 '''
153 @type group: Group
154 @param group: Group to use
155 @type family: Generator
156 @param family: Family (defaults to 0x01 IPV4)
157 @type port: Generator
158 @param port: Port number
159 @type address: Generator
160 @param address: 32bit IPv4 address
161 '''
162 StunMappedAddressAttribute.__init__(self, group, port, address, family)
163 self._type = TurnAttribute.ALTERNATE_SERVER
164
165
167 '''
168 MAGIC-COOKIE
169
170 The MAGIC-COOKIE is used by TURN clients and servers to disambiguate
171 TURN traffic from data traffic. Its value ix 0x72c64bc6.
172
173 0 1 2 3
174 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
175 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
176 |0|1|1|1|0|0|1|0|1|1|0|0|0|1|1|0|0|1|0|0|1|0|1|1|1|1|0|0|0|1|1|0|
177 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
178 '''
179
180 _magicCookie = 0x72c64bc6
181
182 - def __init__(self, group, magicCookie = None):
183 '''
184 @type group: Group
185 @param group: Group to use
186 @type magicCookie: Generator
187 @param magicCookie: Magic cookie, default is 0x72c64bc6
188 '''
189 self.setGroup(group)
190 if lifetime != None:
191 self._lifetime = lifetime
192 self._type = TurnAttribute.MAGIC_COOKIE
193
199
200
202 '''
203 BANDWIDTH
204
205 The bandwidth attribute represents the peak bandwidth, measured in
206 kbits per second, that the client expects to use on the binding. The
207 value represents the sum in the receive and send directions.
208 [[Editors note: Need to define leaky bucket parameters for this.]]
209
210 0 1 2 3
211 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
212 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
213 | Bandwidth |
214 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
215 '''
216
218 '''
219 @type group: Group
220 @param group: Group to use
221 @type lifetime: Generator
222 @param lifetime: Lifetime in seconds
223 '''
224 self.setGroup(group)
225 if bandwidth != None:
226 self._generator = bandwidth
227 self._type = TurnAttribute.BANDWIDTH
228
231
232
234 '''
235 DESTINATION-ADDRESS
236
237 The DESTINATION-ADDRESS is present in Send Requests and Set Active
238 Destination Requests. It specifies the address and port where the
239 data is to be sent. It is encoded in the same way as MAPPED-ADDRESS.
240 '''
241
242 - def __init__(self, group, port, address, family = 0x01):
243 '''
244 @type group: Group
245 @param group: Group to use
246 @type family: Generator
247 @param family: Family (defaults to 0x01 IPV4)
248 @type port: Generator
249 @param port: Port number
250 @type address: Generator
251 @param address: 32bit IPv4 address
252 '''
253 StunMappedAddressAttribute.__init__(self, group, port, address, family)
254 self._type = TurnAttribute.DESTINATION_ADDRESS
255
256
258 '''
259 REMOTE-ADDRESS
260
261 The REMOTE-ADDRESS is present in Data Indications. It specifies the
262 address and port from which a packet was received. It is encoded in
263 the same way as MAPPED-ADDRESS.
264 '''
265
266 - def __init__(self, group, port, address, family = 0x01):
267 '''
268 @type group: Group
269 @param group: Group to use
270 @type family: Generator
271 @param family: Family (defaults to 0x01 IPV4)
272 @type port: Generator
273 @param port: Port number
274 @type address: Generator
275 @param address: 32bit IPv4 address
276 '''
277 StunMappedAddressAttribute.__init__(self, group, port, address, family)
278 self._type = TurnAttribute.REMOTE_ADDRESS
279
280
282 '''
283 DATA
284
285 The DATA attribute is present in Send Requests and Data Indications.
286 It contains raw payload data that is to be sent (in the case of a
287 Send Request) or was received (in the case of a Data Indication).
288 '''
289
301
304
305
307 '''
308 NONCE
309
310 The NONCE attribute is present in Shared Secret Requests and Shared
311 Secret Error responses. It contains a sequence of qdtext or quoted-
312 pair, which are defined in [6].
313 '''
314
315 _nonce = 0
316
318 '''
319 @type group: Group
320 @param group: Group to use
321 @type nonce: Generator
322 @param nonce: Nonce stuff
323 '''
324 self.setGroup(group)
325 if nonce != None:
326 self._nonce = nonce
327 self._type = TurnAttribute.NONCE
328
331
332
334 '''
335 REALM
336
337 The REALM attribute is present in Shared Secret Requests and Shared
338 Secret Responses. It contains text which meets the grammar for
339 "realm" as described in RFC 3261, and will thus contain a quoted
340 string (including the quotes).
341 '''
342
343 _realm = None
344
346 '''
347 @type group: Group
348 @param group: Group to use
349 @type realm: Generator
350 @param realm: Realm string ("fooyah.com")
351 '''
352 self.setGroup(group)
353 if realm != None:
354 self._realm = realm
355 self._type = TurnAttribute.REALM
356
359
360
361
362