1 /*
2 * Copyright (c) 2014, Ericsson AB. All rights reserved.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
24 * OF SUCH DAMAGE.
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "gstdtlssrtpbin.h"
32
33 #define gst_dtls_srtp_bin_parent_class parent_class
34 G_DEFINE_ABSTRACT_TYPE (GstDtlsSrtpBin, gst_dtls_srtp_bin, GST_TYPE_BIN);
35
36 enum
37 {
38 PROP_0,
39 PROP_CONNECTION_ID,
40 PROP_KEY,
41 PROP_SRTP_AUTH,
42 PROP_SRTP_CIPHER,
43 PROP_SRTCP_AUTH,
44 PROP_SRTCP_CIPHER,
45 NUM_PROPERTIES
46 };
47
48 static GParamSpec *properties[NUM_PROPERTIES];
49
50 #define DEFAULT_CONNECTION_ID NULL
51 #define DEFAULT_KEY NULL
52 #define DEFAULT_SRTP_AUTH NULL
53 #define DEFAULT_SRTP_CIPHER NULL
54 #define DEFAULT_SRTCP_AUTH NULL
55 #define DEFAULT_SRTCP_CIPHER NULL
56
57 static void gst_dtls_srtp_bin_finalize (GObject *);
58 static void gst_dtls_srtp_bin_set_property (GObject *, guint prop_id,
59 const GValue *, GParamSpec *);
60 static void gst_dtls_srtp_bin_get_property (GObject *, guint prop_id,
61 GValue *, GParamSpec *);
62
63 static void
gst_dtls_srtp_bin_class_init(GstDtlsSrtpBinClass * klass)64 gst_dtls_srtp_bin_class_init (GstDtlsSrtpBinClass * klass)
65 {
66 GObjectClass *gobject_class;
67
68 gobject_class = (GObjectClass *) klass;
69
70 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_dtls_srtp_bin_finalize);
71 gobject_class->set_property =
72 GST_DEBUG_FUNCPTR (gst_dtls_srtp_bin_set_property);
73 gobject_class->get_property =
74 GST_DEBUG_FUNCPTR (gst_dtls_srtp_bin_get_property);
75
76 klass->remove_dtls_element = NULL;
77
78 properties[PROP_CONNECTION_ID] =
79 g_param_spec_string ("connection-id",
80 "Connection id",
81 "Every encoder/decoder pair should have the same, unique, connection-id",
82 DEFAULT_CONNECTION_ID, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
83
84 properties[PROP_KEY] =
85 g_param_spec_boxed ("key",
86 "Key",
87 "SRTP master key, if this property is set, DTLS will be disabled",
88 GST_TYPE_BUFFER,
89 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
90
91 properties[PROP_SRTP_CIPHER] =
92 g_param_spec_string ("srtp-cipher",
93 "SRTP Cipher",
94 "SRTP cipher name, should be 'null' or 'aes-128-icm', "
95 "if this property is set, DTLS will be disabled",
96 DEFAULT_SRTP_CIPHER,
97 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
98
99 properties[PROP_SRTCP_CIPHER] =
100 g_param_spec_string ("srtcp-cipher",
101 "SRTCP Cipher",
102 "SRTCP cipher name, should be 'null' or 'aes-128-icm', "
103 "if this property is set, DTLS will be disabled",
104 DEFAULT_SRTCP_CIPHER,
105 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
106
107 properties[PROP_SRTP_AUTH] =
108 g_param_spec_string ("srtp-auth",
109 "SRTP Auth",
110 "SRTP auth name, should be 'null', 'hmac-sha1-32' or 'hmac-sha1-80', "
111 "if this property is set, DTLS will be disabled",
112 DEFAULT_SRTP_AUTH,
113 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
114
115 properties[PROP_SRTCP_AUTH] =
116 g_param_spec_string ("srtcp-auth",
117 "SRTCP Auth",
118 "SRTCP auth name, should be 'null', 'hmac-sha1-32' or 'hmac-sha1-80', "
119 "if this property is set, DTLS will be disabled",
120 DEFAULT_SRTCP_AUTH,
121 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
122
123 g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
124
125 gst_type_mark_as_plugin_api (GST_TYPE_DTLS_SRTP_BIN, 0);
126 }
127
128 static void
gst_dtls_srtp_bin_init(GstDtlsSrtpBin * self)129 gst_dtls_srtp_bin_init (GstDtlsSrtpBin * self)
130 {
131 self->key = NULL;
132 self->key_is_set = FALSE;
133 self->srtp_auth = NULL;
134 self->srtp_cipher = NULL;
135 self->srtcp_auth = NULL;
136 self->srtcp_cipher = NULL;
137 }
138
139 static void
gst_dtls_srtp_bin_finalize(GObject * object)140 gst_dtls_srtp_bin_finalize (GObject * object)
141 {
142 GstDtlsSrtpBin *self = GST_DTLS_SRTP_BIN (object);
143
144 if (self->key) {
145 gst_buffer_unref (self->key);
146 self->key = NULL;
147 }
148 g_free (self->srtp_auth);
149 self->srtp_auth = NULL;
150 g_free (self->srtp_cipher);
151 self->srtp_cipher = NULL;
152 g_free (self->srtcp_auth);
153 self->srtcp_auth = NULL;
154 g_free (self->srtcp_cipher);
155 self->srtcp_cipher = NULL;
156
157 G_OBJECT_CLASS (parent_class)->finalize (object);
158 }
159
160 static void
gst_dtls_srtp_bin_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)161 gst_dtls_srtp_bin_set_property (GObject * object,
162 guint prop_id, const GValue * value, GParamSpec * pspec)
163 {
164 GstDtlsSrtpBin *self = GST_DTLS_SRTP_BIN (object);
165 GstDtlsSrtpBinClass *klass = GST_DTLS_SRTP_BIN_GET_CLASS (self);
166
167 switch (prop_id) {
168 case PROP_CONNECTION_ID:
169 if (self->dtls_element) {
170 g_object_set_property (G_OBJECT (self->dtls_element), "connection-id",
171 value);
172 } else {
173 g_warning ("tried to set connection-id after disabling DTLS");
174 }
175 break;
176 case PROP_KEY:
177 if (self->key) {
178 gst_buffer_unref (self->key);
179 }
180 self->key = g_value_dup_boxed (value);
181 self->key_is_set = TRUE;
182 klass->remove_dtls_element (self);
183 break;
184 case PROP_SRTP_AUTH:
185 g_free (self->srtp_auth);
186 self->srtp_auth = g_value_dup_string (value);
187 klass->remove_dtls_element (self);
188 break;
189 case PROP_SRTP_CIPHER:
190 g_free (self->srtp_cipher);
191 self->srtp_cipher = g_value_dup_string (value);
192 klass->remove_dtls_element (self);
193 break;
194 case PROP_SRTCP_AUTH:
195 g_free (self->srtcp_auth);
196 self->srtcp_auth = g_value_dup_string (value);
197 klass->remove_dtls_element (self);
198 break;
199 case PROP_SRTCP_CIPHER:
200 g_free (self->srtcp_cipher);
201 self->srtcp_cipher = g_value_dup_string (value);
202 klass->remove_dtls_element (self);
203 break;
204 default:
205 G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
206 }
207 }
208
209 static void
gst_dtls_srtp_bin_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)210 gst_dtls_srtp_bin_get_property (GObject * object,
211 guint prop_id, GValue * value, GParamSpec * pspec)
212 {
213 GstDtlsSrtpBin *self = GST_DTLS_SRTP_BIN (object);
214
215 switch (prop_id) {
216 case PROP_CONNECTION_ID:
217 if (self->dtls_element) {
218 g_object_get_property (G_OBJECT (self->dtls_element), "connection-id",
219 value);
220 } else {
221 GST_WARNING_OBJECT (self,
222 "tried to get connection-id after disabling DTLS");
223 }
224 break;
225 case PROP_KEY:
226 if (self->key) {
227 g_value_set_boxed (value, self->key);
228 }
229 break;
230 case PROP_SRTP_AUTH:
231 g_value_set_string (value, self->srtp_auth);
232 break;
233 case PROP_SRTP_CIPHER:
234 g_value_set_string (value, self->srtp_cipher);
235 break;
236 case PROP_SRTCP_AUTH:
237 g_value_set_string (value, self->srtcp_auth);
238 break;
239 case PROP_SRTCP_CIPHER:
240 g_value_set_string (value, self->srtcp_cipher);
241 break;
242 default:
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
244 }
245 }
246