1 /* GStreamer
2 * Copyright (C) <2014> Wim Taymans <wim.taymans@gmail.com>
3 *
4 * gstmikey.h: various helper functions to manipulate mikey messages
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #ifndef __GST_MIKEY_H__
23 #define __GST_MIKEY_H__
24
25 #include <gst/gst.h>
26 #include <gst/sdp/sdp-prelude.h>
27
28 G_BEGIN_DECLS
29
30 GST_SDP_API
31 GType gst_mikey_message_get_type(void);
32 #define GST_TYPE_MIKEY_MESSAGE (gst_mikey_message_get_type())
33
34 typedef struct _GstMIKEYMessage GstMIKEYMessage;
35 typedef struct _GstMIKEYEncryptInfo GstMIKEYEncryptInfo;
36 typedef struct _GstMIKEYDecryptInfo GstMIKEYDecryptInfo;
37
38 /**
39 * GST_MIKEY_VERSION:
40 *
41 * The supported MIKEY version 1.
42 */
43 #define GST_MIKEY_VERSION 1
44
45 /**
46 * GstMIKEYType:
47 * @GST_MIKEY_TYPE_INVALID: Invalid type
48 * @GST_MIKEY_TYPE_PSK_INIT: Initiator's pre-shared key message
49 * @GST_MIKEY_TYPE_PSK_VERIFY: Verification message of a Pre-shared key message
50 * @GST_MIKEY_TYPE_PK_INIT: Initiator's public-key transport message
51 * @GST_MIKEY_TYPE_PK_VERIFY: Verification message of a public-key message
52 * @GST_MIKEY_TYPE_DH_INIT: Initiator's DH exchange message
53 * @GST_MIKEY_TYPE_DH_RESP: Responder's DH exchange message
54 * @GST_MIKEY_TYPE_ERROR: Error message
55 *
56 * Different MIKEY data types.
57 */
58 typedef enum
59 {
60 GST_MIKEY_TYPE_INVALID = -1,
61 GST_MIKEY_TYPE_PSK_INIT = 0,
62 GST_MIKEY_TYPE_PSK_VERIFY = 1,
63 GST_MIKEY_TYPE_PK_INIT = 2,
64 GST_MIKEY_TYPE_PK_VERIFY = 3,
65 GST_MIKEY_TYPE_DH_INIT = 4,
66 GST_MIKEY_TYPE_DH_RESP = 5,
67 GST_MIKEY_TYPE_ERROR = 6
68 } GstMIKEYType;
69
70 /**
71 * GstMIKEYPayloadType:
72 * @GST_MIKEY_PT_LAST: Last payload
73 * @GST_MIKEY_PT_KEMAC: Key data transport payload
74 * @GST_MIKEY_PT_PKE: Envelope data payload
75 * @GST_MIKEY_PT_DH: DH data payload
76 * @GST_MIKEY_PT_SIGN: Signature payload
77 * @GST_MIKEY_PT_T: Timestamp payload
78 * @GST_MIKEY_PT_ID: ID payload
79 * @GST_MIKEY_PT_CERT: Certificate Payload
80 * @GST_MIKEY_PT_CHASH: Cert hash payload
81 * @GST_MIKEY_PT_V: Verification message payload
82 * @GST_MIKEY_PT_SP: Security Policy payload
83 * @GST_MIKEY_PT_RAND: RAND payload
84 * @GST_MIKEY_PT_ERR: Error payload
85 * @GST_MIKEY_PT_KEY_DATA: Key data sub-payload
86 * @GST_MIKEY_PT_GEN_EXT: General Extension Payload
87
88 * Different MIKEY Payload types.
89 */
90 typedef enum
91 {
92 GST_MIKEY_PT_LAST = 0,
93 GST_MIKEY_PT_KEMAC = 1,
94 GST_MIKEY_PT_PKE = 2,
95 GST_MIKEY_PT_DH = 3,
96 GST_MIKEY_PT_SIGN = 4,
97 GST_MIKEY_PT_T = 5,
98 GST_MIKEY_PT_ID = 6,
99 GST_MIKEY_PT_CERT = 7,
100 GST_MIKEY_PT_CHASH = 8,
101 GST_MIKEY_PT_V = 9,
102 GST_MIKEY_PT_SP = 10,
103 GST_MIKEY_PT_RAND = 11,
104 GST_MIKEY_PT_ERR = 12,
105 GST_MIKEY_PT_KEY_DATA = 20,
106 GST_MIKEY_PT_GEN_EXT = 21
107 } GstMIKEYPayloadType;
108
109 /**
110 * GstMIKEYPRFFunc:
111 * @GST_MIKEY_PRF_MIKEY_1: MIKEY-1 PRF function
112 *
113 * The PRF function that has been/will be used for key derivation
114 */
115 typedef enum
116 {
117 GST_MIKEY_PRF_MIKEY_1 = 0
118 } GstMIKEYPRFFunc;
119
120 /**
121 * GstMIKEYMapType:
122 * @GST_MIKEY_MAP_TYPE_SRTP: SRTP
123 *
124 * Specifies the method of uniquely mapping Crypto Sessions to the security
125 * protocol sessions.
126 */
127 typedef enum
128 {
129 GST_MIKEY_MAP_TYPE_SRTP = 0
130 } GstMIKEYMapType;
131
132 /**
133 * GstMIKEYMapSRTP:
134 * @policy: The security policy applied for the stream with @ssrc
135 * @ssrc: the SSRC that must be used for the stream
136 * @roc: current rollover counter
137 *
138 * The Security policy Map item for SRTP
139 */
140 typedef struct {
141 guint8 policy;
142 guint32 ssrc;
143 guint32 roc;
144 } GstMIKEYMapSRTP;
145
146 typedef struct _GstMIKEYPayload GstMIKEYPayload;
147
148 GST_SDP_API
149 GType gst_mikey_payload_get_type(void);
150 #define GST_TYPE_MIKEY_PAYLOAD (gst_mikey_payload_get_type())
151
152 /**
153 * GstMIKEYPayload:
154 * @type: the payload type
155 * @len: length of the payload
156 *
157 * Hold the common fields for all payloads
158 */
159 struct _GstMIKEYPayload {
160 /* < private > */
161 GstMiniObject mini_object;
162
163 /* < public > */
164 GstMIKEYPayloadType type;
165 guint len;
166 };
167
168 GST_SDP_API
169 GstMIKEYPayload * gst_mikey_payload_new (GstMIKEYPayloadType type);
170
171 /**
172 * gst_mikey_payload_ref:
173 * @payload: The payload to refcount
174 *
175 * Increase the refcount of this payload.
176 *
177 * Returns: (transfer full): @payload (for convenience when doing assignments)
178 *
179 * Since: 1.4
180 */
181 static inline GstMIKEYPayload *
gst_mikey_payload_ref(GstMIKEYPayload * payload)182 gst_mikey_payload_ref (GstMIKEYPayload * payload)
183 {
184 return (GstMIKEYPayload *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (payload));
185 }
186
187 /**
188 * gst_mikey_payload_unref:
189 * @payload: (transfer full): the payload to refcount
190 *
191 * Decrease the refcount of an payload, freeing it if the refcount reaches 0.
192 *
193 * Since: 1.4
194 */
195 static inline void
gst_mikey_payload_unref(GstMIKEYPayload * payload)196 gst_mikey_payload_unref (GstMIKEYPayload * payload)
197 {
198 gst_mini_object_unref (GST_MINI_OBJECT_CAST (payload));
199 }
200
201 /**
202 * gst_mikey_payload_copy:
203 * @payload: a #GstMIKEYPayload.
204 *
205 * Create a copy of the given payload.
206 *
207 * Returns: (transfer full): a new copy of @payload.
208 *
209 * Since: 1.4
210 */
211 static inline GstMIKEYPayload *
gst_mikey_payload_copy(const GstMIKEYPayload * payload)212 gst_mikey_payload_copy (const GstMIKEYPayload * payload)
213 {
214 return (GstMIKEYPayload *) gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (payload));
215 }
216
217 /**
218 * GstMIKEYEncAlg:
219 * @GST_MIKEY_ENC_NULL: no encryption
220 * @GST_MIKEY_ENC_AES_CM_128: AES-CM using a 128-bit key
221 * @GST_MIKEY_ENC_AES_KW_128: AES Key Wrap using a 128-bit key
222 * @GST_MIKEY_ENC_AES_GCM_128: AES-GCM using a 128-bit key (Since: 1.16)
223 *
224 * The encryption algorithm used to encrypt the Encr data field
225 */
226 typedef enum
227 {
228 GST_MIKEY_ENC_NULL = 0,
229 GST_MIKEY_ENC_AES_CM_128 = 1,
230 GST_MIKEY_ENC_AES_KW_128 = 2,
231 GST_MIKEY_ENC_AES_GCM_128 = 6
232 } GstMIKEYEncAlg;
233
234 /**
235 * GstMIKEYMacAlg:
236 * @GST_MIKEY_MAC_NULL: no authentication
237 * @GST_MIKEY_MAC_HMAC_SHA_1_160: HMAC-SHA-1-160
238 *
239 * Specifies the authentication algorithm used
240 */
241 typedef enum
242 {
243 GST_MIKEY_MAC_NULL = 0,
244 GST_MIKEY_MAC_HMAC_SHA_1_160 = 1
245 } GstMIKEYMacAlg;
246
247 /**
248 * GstMIKEYPayloadKEMAC:
249 * @pt: the common #GstMIKEYPayload
250 * @enc_alg: the #GstMIKEYEncAlg
251 * @mac_alg: the #GstMIKEYMacAlg
252 * @subpayloads: the subpayloads
253 *
254 * A structure holding the KEMAC payload
255 */
256 typedef struct {
257 GstMIKEYPayload pt;
258
259 GstMIKEYEncAlg enc_alg;
260 GstMIKEYMacAlg mac_alg;
261 GArray *subpayloads;
262 } GstMIKEYPayloadKEMAC;
263
264 GST_SDP_API
265 gboolean gst_mikey_payload_kemac_set (GstMIKEYPayload *payload,
266 GstMIKEYEncAlg enc_alg,
267 GstMIKEYMacAlg mac_alg);
268
269 GST_SDP_API
270 guint gst_mikey_payload_kemac_get_n_sub (const GstMIKEYPayload *payload);
271
272 GST_SDP_API
273 const GstMIKEYPayload * gst_mikey_payload_kemac_get_sub (const GstMIKEYPayload *payload, guint idx);
274
275 GST_SDP_API
276 gboolean gst_mikey_payload_kemac_remove_sub (GstMIKEYPayload *payload, guint idx);
277
278 GST_SDP_API
279 gboolean gst_mikey_payload_kemac_add_sub (GstMIKEYPayload *payload,
280 GstMIKEYPayload *newpay);
281
282 /**
283 * GstMIKEYCacheType:
284 * @GST_MIKEY_CACHE_NONE: The envelope key MUST NOT be cached
285 * @GST_MIKEY_CACHE_ALWAYS: The envelope key MUST be cached
286 * @GST_MIKEY_CACHE_FOR_CSB: The envelope key MUST be cached, but only
287 * to be used for the specific CSB.
288 *
289 * The different cache types
290 */
291 typedef enum
292 {
293 GST_MIKEY_CACHE_NONE = 0,
294 GST_MIKEY_CACHE_ALWAYS = 1,
295 GST_MIKEY_CACHE_FOR_CSB = 2
296 } GstMIKEYCacheType;
297
298 /**
299 * GstMIKEYPayloadPKE:
300 * @pt: the common #GstMIKEYPayload
301 * @C: envelope key cache indicator
302 * @data_len: length of @data
303 * @data: the encrypted envelope key
304 *
305 * The Envelope data payload contains the encrypted envelope key that is
306 * used in the public-key transport to protect the data in the Key data
307 * transport payload. The encryption algorithm used is implicit from
308 * the certificate/public key used.
309 */
310 typedef struct {
311 GstMIKEYPayload pt;
312
313 GstMIKEYCacheType C;
314 guint16 data_len;
315 guint8 *data;
316 } GstMIKEYPayloadPKE;
317
318 GST_SDP_API
319 gboolean gst_mikey_payload_pke_set (GstMIKEYPayload *payload,
320 GstMIKEYCacheType C,
321 guint16 data_len, const guint8 *data);
322
323
324 /**
325 * GstMIKEYTSType:
326 * @GST_MIKEY_TS_TYPE_NTP_UTC: an NTP time in UTC timezone
327 * @GST_MIKEY_TS_TYPE_NTP: an NTP time
328 * @GST_MIKEY_TS_TYPE_COUNTER: a counter
329 *
330 * Specifies the timestamp type.
331 */
332 typedef enum
333 {
334 GST_MIKEY_TS_TYPE_NTP_UTC = 0,
335 GST_MIKEY_TS_TYPE_NTP = 1,
336 GST_MIKEY_TS_TYPE_COUNTER = 2
337 } GstMIKEYTSType;
338
339 /**
340 * GstMIKEYPayloadT:
341 * @pt: the payload header
342 * @type: a #GstMIKEYTSType
343 * @ts_value: the timestamp value
344 *
345 * The timestamp payload carries the timestamp information
346 */
347 typedef struct {
348 GstMIKEYPayload pt;
349
350 GstMIKEYTSType type;
351 guint8 *ts_value;
352 } GstMIKEYPayloadT;
353
354 GST_SDP_API
355 gboolean gst_mikey_payload_t_set (GstMIKEYPayload *payload,
356 GstMIKEYTSType type, const guint8 *ts_value);
357
358 /**
359 * GstMIKEYPayloadSPParam:
360 * @type: specifies the type of the parameter
361 * @len: specifies the length of @val
362 * @val: specifies the value of the parameter
363 *
364 * A Type/Length/Value field for security parameters
365 */
366 typedef struct {
367 guint8 type;
368 guint8 len;
369 guint8 *val;
370 } GstMIKEYPayloadSPParam;
371
372 /**
373 * GstMIKEYSecProto:
374 * @GST_MIKEY_SEC_PROTO_SRTP: SRTP
375 *
376 * Specifies the security protocol
377 */
378 typedef enum
379 {
380 GST_MIKEY_SEC_PROTO_SRTP = 0
381 } GstMIKEYSecProto;
382
383 /**
384 * GstMIKEYSecSRTP:
385 * @GST_MIKEY_SP_SRTP_ENC_ALG: Encryption algorithm
386 * @GST_MIKEY_SP_SRTP_ENC_KEY_LEN: Session Encr. key length
387 * @GST_MIKEY_SP_SRTP_AUTH_ALG: Authentication algorithm
388 * @GST_MIKEY_SP_SRTP_AUTH_KEY_LEN: Session Auth. key length
389 * @GST_MIKEY_SP_SRTP_SALT_KEY_LEN: Session Salt key length
390 * @GST_MIKEY_SP_SRTP_PRF: SRTP Pseudo Random Function
391 * @GST_MIKEY_SP_SRTP_KEY_DERIV_RATE: Key derivation rate
392 * @GST_MIKEY_SP_SRTP_SRTP_ENC: SRTP encryption off/on, 0 if off, 1 if on
393 * @GST_MIKEY_SP_SRTP_SRTCP_ENC: SRTCP encryption off/on, 0 if off, 1 if on
394 * @GST_MIKEY_SP_SRTP_FEC_ORDER: sender's FEC order
395 * @GST_MIKEY_SP_SRTP_SRTP_AUTH: SRTP authentication off/on, 0 if off, 1 if on
396 * @GST_MIKEY_SP_SRTP_AUTH_TAG_LEN: Authentication tag length
397 * @GST_MIKEY_SP_SRTP_SRTP_PREFIX_LEN: SRTP prefix length
398 * @GST_MIKEY_SP_SRTP_AEAD_AUTH_TAG_LEN: AEAD authentication tag length (Since: 1.16)
399 *
400 * This policy specifies the parameters for SRTP and SRTCP
401 */
402 typedef enum
403 {
404 GST_MIKEY_SP_SRTP_ENC_ALG = 0,
405 GST_MIKEY_SP_SRTP_ENC_KEY_LEN = 1,
406 GST_MIKEY_SP_SRTP_AUTH_ALG = 2,
407 GST_MIKEY_SP_SRTP_AUTH_KEY_LEN = 3,
408 GST_MIKEY_SP_SRTP_SALT_KEY_LEN = 4,
409 GST_MIKEY_SP_SRTP_PRF = 5,
410 GST_MIKEY_SP_SRTP_KEY_DERIV_RATE = 6,
411 GST_MIKEY_SP_SRTP_SRTP_ENC = 7,
412 GST_MIKEY_SP_SRTP_SRTCP_ENC = 8,
413 GST_MIKEY_SP_SRTP_FEC_ORDER = 9,
414 GST_MIKEY_SP_SRTP_SRTP_AUTH = 10,
415 GST_MIKEY_SP_SRTP_AUTH_TAG_LEN = 11,
416 GST_MIKEY_SP_SRTP_SRTP_PREFIX_LEN = 12,
417 GST_MIKEY_SP_SRTP_AEAD_AUTH_TAG_LEN = 20
418 } GstMIKEYSecSRTP;
419
420 /**
421 * GstMIKEYPayloadSP:
422 * @pt: the payload header
423 * @policy: the policy number
424 * @proto: the security protocol
425 * @params: array of #GstMIKEYPayloadSPParam
426 *
427 * The Security Policy payload defines a set of policies that apply to a
428 * specific security protocol
429 */
430 typedef struct {
431 GstMIKEYPayload pt;
432
433 guint policy;
434 GstMIKEYSecProto proto;
435 GArray *params;
436 } GstMIKEYPayloadSP;
437
438 GST_SDP_API
439 gboolean gst_mikey_payload_sp_set (GstMIKEYPayload *payload,
440 guint policy, GstMIKEYSecProto proto);
441 GST_SDP_API
442 guint gst_mikey_payload_sp_get_n_params (const GstMIKEYPayload *payload);
443
444 GST_SDP_API
445 const GstMIKEYPayloadSPParam *
446 gst_mikey_payload_sp_get_param (const GstMIKEYPayload *payload, guint idx);
447
448 GST_SDP_API
449 gboolean gst_mikey_payload_sp_remove_param (GstMIKEYPayload *payload, guint idx);
450
451 GST_SDP_API
452 gboolean gst_mikey_payload_sp_add_param (GstMIKEYPayload *payload,
453 guint8 type, guint8 len, const guint8 *val);
454
455 /**
456 * GstMIKEYPayloadRAND:
457 * @pt: the payload header
458 * @len: the length of @rand
459 * @rand: random values
460 *
461 * The RAND payload consists of a (pseudo-)random bit-string
462 */
463 typedef struct {
464 GstMIKEYPayload pt;
465
466 guint8 len;
467 guint8 *rand;
468 } GstMIKEYPayloadRAND;
469
470 GST_SDP_API
471 gboolean gst_mikey_payload_rand_set (GstMIKEYPayload *payload,
472 guint8 len, const guint8 *rand);
473
474 /**
475 * GstMIKEYKeyDataType:
476 * @GST_MIKEY_KD_TGK: a TEK Generation Key
477 * @GST_MIKEY_KD_TEK: Traffic-Encrypting Key
478 *
479 * The type of key.
480 */
481 typedef enum
482 {
483 GST_MIKEY_KD_TGK = 0,
484 GST_MIKEY_KD_TEK = 2,
485 } GstMIKEYKeyDataType;
486
487 /**
488 * GstMIKEYKVType:
489 * @GST_MIKEY_KV_NULL: No specific usage rule
490 * @GST_MIKEY_KV_SPI: The key is associated with the SPI/MKI
491 * @GST_MIKEY_KV_INTERVAL: The key has a start and expiration time
492 *
493 * The key validity type
494 */
495 typedef enum
496 {
497 GST_MIKEY_KV_NULL = 0,
498 GST_MIKEY_KV_SPI = 1,
499 GST_MIKEY_KV_INTERVAL = 2,
500 } GstMIKEYKVType;
501
502 /**
503 * GstMIKEYPayloadKeyData:
504 * @pt: the payload header
505 * @key_type: the #GstMIKEYKeyDataType of @key_data
506 * @key_len: length of @key_data
507 * @key_data: the key data
508 * @salt_len: the length of @salt_data, can be 0
509 * @salt_data: salt data
510 * @kv_type: the Key Validity type
511 * @kv_len: length of @kv_data
512 * @kv_data: key validity data
513 *
514 * The Key data payload contains key material. It should be added as sub
515 * payload to the KEMAC.
516 */
517 typedef struct {
518 GstMIKEYPayload pt;
519
520 GstMIKEYKeyDataType key_type;
521 guint16 key_len;
522 guint8 *key_data;
523 guint16 salt_len;
524 guint8 *salt_data;
525 GstMIKEYKVType kv_type;
526 guint8 kv_len[2];
527 guint8 *kv_data[2];
528 } GstMIKEYPayloadKeyData;
529
530 GST_SDP_API
531 gboolean gst_mikey_payload_key_data_set_key (GstMIKEYPayload *payload,
532 GstMIKEYKeyDataType key_type,
533 guint16 key_len, const guint8 *key_data);
534
535 GST_SDP_API
536 gboolean gst_mikey_payload_key_data_set_salt (GstMIKEYPayload *payload,
537 guint16 salt_len, const guint8 *salt_data);
538
539 GST_SDP_API
540 gboolean gst_mikey_payload_key_data_set_spi (GstMIKEYPayload *payload,
541 guint8 spi_len, const guint8 *spi_data);
542
543 GST_SDP_API
544 gboolean gst_mikey_payload_key_data_set_interval (GstMIKEYPayload *payload,
545 guint8 vf_len, const guint8 *vf_data,
546 guint8 vt_len, const guint8 *vt_data);
547
548 /**
549 * GstMIKEYMessage:
550 * @version: the version
551 * @type: the #GstMIKEYType message type
552 * @V: verify flag
553 * @prf_func: a #GstMIKEYPRFFunc
554 * @CSB_id: Identifies the Crypto Session Bundle
555 * @map_type: a #GstMIKEYMapType
556 * @map_info: map info array of type depending on @map_type
557 * @payloads: the payload array of #GstMIKEYPayload
558 *
559 * Structure holding the information of the MIKEY message
560 */
561 struct _GstMIKEYMessage
562 {
563 /* < private > */
564 GstMiniObject mini_object;
565
566 /* < public > */
567 guint8 version;
568 GstMIKEYType type;
569 gboolean V;
570 GstMIKEYPRFFunc prf_func;
571 guint32 CSB_id;
572 GstMIKEYMapType map_type;
573 GArray *map_info;
574 GArray *payloads;
575 };
576
577
578 GST_SDP_API
579 GstMIKEYMessage * gst_mikey_message_new (void);
580
581 GST_SDP_API
582 GstMIKEYMessage * gst_mikey_message_new_from_data (gconstpointer data, gsize size,
583 GstMIKEYDecryptInfo *info, GError **error);
584
585 GST_SDP_API
586 GstMIKEYMessage * gst_mikey_message_new_from_bytes (GBytes *bytes, GstMIKEYDecryptInfo *info,
587 GError **error);
588
589 GST_SDP_API
590 GBytes * gst_mikey_message_to_bytes (GstMIKEYMessage *msg, GstMIKEYEncryptInfo *info,
591 GError **error);
592
593 GST_SDP_API
594 GstMIKEYMessage * gst_mikey_message_new_from_caps (GstCaps *caps);
595
596 GST_SDP_API
597 gboolean gst_mikey_message_to_caps (const GstMIKEYMessage *msg, GstCaps *caps);
598
599 GST_SDP_API
600 gchar * gst_mikey_message_base64_encode (GstMIKEYMessage* msg);
601
602 /**
603 * gst_mikey_message_ref:
604 * @message: The message to refcount
605 *
606 * Increase the refcount of this message.
607 *
608 * Returns: (transfer full): @message (for convenience when doing assignments)
609 *
610 * Since: 1.4
611 */
612 static inline GstMIKEYMessage *
gst_mikey_message_ref(GstMIKEYMessage * message)613 gst_mikey_message_ref (GstMIKEYMessage * message)
614 {
615 return (GstMIKEYMessage *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (message));
616 }
617
618 /**
619 * gst_mikey_message_unref:
620 * @message: (transfer full): the message to refcount
621 *
622 * Decrease the refcount of an message, freeing it if the refcount reaches 0.
623 *
624 * Since: 1.4
625 */
626 static inline void
gst_mikey_message_unref(GstMIKEYMessage * message)627 gst_mikey_message_unref (GstMIKEYMessage * message)
628 {
629 gst_mini_object_unref (GST_MINI_OBJECT_CAST (message));
630 }
631
632 /**
633 * gst_mikey_message_copy:
634 * @message: a #GstMIKEYMessage.
635 *
636 * Create a copy of the given message.
637 *
638 * Returns: (transfer full): a new copy of @message.
639 *
640 * Since: 1.4
641 */
642 static inline GstMIKEYMessage *
gst_mikey_message_copy(const GstMIKEYMessage * message)643 gst_mikey_message_copy (const GstMIKEYMessage * message)
644 {
645 return (GstMIKEYMessage *) gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (message));
646 }
647
648
649 GST_SDP_API
650 gboolean gst_mikey_message_set_info (GstMIKEYMessage *msg,
651 guint8 version, GstMIKEYType type, gboolean V,
652 GstMIKEYPRFFunc prf_func, guint32 CSB_id,
653 GstMIKEYMapType map_type);
654
655 GST_SDP_API
656 guint gst_mikey_message_get_n_cs (const GstMIKEYMessage *msg);
657
658 /* SRTP crypto sessions */
659
660 GST_SDP_API
661 const GstMIKEYMapSRTP * gst_mikey_message_get_cs_srtp (const GstMIKEYMessage *msg, guint idx);
662
663 GST_SDP_API
664 gboolean gst_mikey_message_insert_cs_srtp (GstMIKEYMessage *msg, gint idx,
665 const GstMIKEYMapSRTP *map);
666
667 GST_SDP_API
668 gboolean gst_mikey_message_replace_cs_srtp (GstMIKEYMessage *msg, gint idx,
669 const GstMIKEYMapSRTP *map);
670
671 GST_SDP_API
672 gboolean gst_mikey_message_remove_cs_srtp (GstMIKEYMessage *msg, gint idx);
673
674 GST_SDP_API
675 gboolean gst_mikey_message_add_cs_srtp (GstMIKEYMessage *msg,
676 guint8 policy, guint32 ssrc, guint32 roc);
677
678 /* adding/retrieving payloads */
679
680 GST_SDP_API
681 guint gst_mikey_message_get_n_payloads (const GstMIKEYMessage *msg);
682
683 GST_SDP_API
684 const GstMIKEYPayload * gst_mikey_message_get_payload (const GstMIKEYMessage *msg, guint idx);
685
686 GST_SDP_API
687 const GstMIKEYPayload * gst_mikey_message_find_payload (const GstMIKEYMessage *msg,
688 GstMIKEYPayloadType type, guint nth);
689
690 GST_SDP_API
691 gboolean gst_mikey_message_remove_payload (GstMIKEYMessage *msg, guint idx);
692
693 GST_SDP_API
694 gboolean gst_mikey_message_insert_payload (GstMIKEYMessage *msg, guint idx,
695 GstMIKEYPayload *payload);
696
697 GST_SDP_API
698 gboolean gst_mikey_message_add_payload (GstMIKEYMessage *msg,
699 GstMIKEYPayload *payload);
700
701 GST_SDP_API
702 gboolean gst_mikey_message_replace_payload (GstMIKEYMessage *msg, guint idx,
703 GstMIKEYPayload *payload);
704
705
706 /* Key data transport payload (KEMAC) */
707 /* Envelope data payload (PKE) */
708
709 GST_SDP_API
710 gboolean gst_mikey_message_add_pke (GstMIKEYMessage *msg,
711 GstMIKEYCacheType C,
712 guint16 data_len, const guint8 *data);
713 /* DH data payload (DH) */
714 /* Signature payload (SIGN) */
715
716 /* Timestamp payload (T) */
717
718 GST_SDP_API
719 gboolean gst_mikey_message_add_t (GstMIKEYMessage *msg,
720 GstMIKEYTSType type, const guint8 *ts_value);
721
722 GST_SDP_API
723 gboolean gst_mikey_message_add_t_now_ntp_utc (GstMIKEYMessage *msg);
724 /* ID payload (ID) */
725 /* Certificate Payload (CERT) */
726 /* Cert hash payload (CHASH)*/
727 /* Ver msg payload (V) */
728 /* Security Policy payload (SP)*/
729 /* RAND payload (RAND) */
730
731 GST_SDP_API
732 gboolean gst_mikey_message_add_rand (GstMIKEYMessage *msg,
733 guint8 len, const guint8 *rand);
734
735 GST_SDP_API
736 gboolean gst_mikey_message_add_rand_len (GstMIKEYMessage *msg, guint8 len);
737
738 /* Error payload (ERR) */
739 /* Key data sub-payload */
740 /* General Extension Payload */
741
742
743 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstMIKEYMessage, gst_mikey_message_unref)
744
745 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstMIKEYPayload, gst_mikey_payload_unref)
746
747 G_END_DECLS
748
749 #endif /* __GST_MIKEY_H__ */
750