nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright (C) 2010 Red Hat, Inc.
4 * Copyright © 2015 Collabora, Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19  
20 #include "config.h"
21  
22 #include "gdummytlsbackend.h"
23  
24 #include <glib.h>
25  
26 #include "gasyncresult.h"
27 #include "gcancellable.h"
28 #include "ginitable.h"
29 #include "gdtlsclientconnection.h"
30 #include "gdtlsconnection.h"
31 #include "gdtlsserverconnection.h"
32 #include "gtlsbackend.h"
33 #include "gtlscertificate.h"
34 #include "gtlsclientconnection.h"
35 #include "gtlsdatabase.h"
36 #include "gtlsfiledatabase.h"
37 #include "gtlsserverconnection.h"
38  
39 #include "giomodule.h"
40 #include "giomodule-priv.h"
41  
42 #include "glibintl.h"
43  
44 static GType _g_dummy_tls_certificate_get_type (void);
45 static GType _g_dummy_tls_connection_get_type (void);
46 static GType _g_dummy_dtls_connection_get_type (void);
47 static GType _g_dummy_tls_database_get_type (void);
48  
49 struct _GDummyTlsBackend {
50 GObject parent_instance;
51 GTlsDatabase *database;
52 };
53  
54 static void g_dummy_tls_backend_iface_init (GTlsBackendInterface *iface);
55  
56 #define g_dummy_tls_backend_get_type _g_dummy_tls_backend_get_type
57 G_DEFINE_TYPE_WITH_CODE (GDummyTlsBackend, g_dummy_tls_backend, G_TYPE_OBJECT,
58 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_BACKEND,
59 g_dummy_tls_backend_iface_init)
60 _g_io_modules_ensure_extension_points_registered ();
61 g_io_extension_point_implement (G_TLS_BACKEND_EXTENSION_POINT_NAME,
62 g_define_type_id,
63 "dummy",
64 -100))
65  
66 static void
67 g_dummy_tls_backend_init (GDummyTlsBackend *dummy)
68 {
69 }
70  
71 static void
72 g_dummy_tls_backend_finalize (GObject *object)
73 {
74 GDummyTlsBackend *dummy = G_DUMMY_TLS_BACKEND (object);
75  
76 g_clear_object (&dummy->database);
77  
78 G_OBJECT_CLASS (g_dummy_tls_backend_parent_class)->finalize (object);
79 }
80  
81 static void
82 g_dummy_tls_backend_class_init (GDummyTlsBackendClass *backend_class)
83 {
84 GObjectClass *object_class = G_OBJECT_CLASS (backend_class);
85  
86 object_class->finalize = g_dummy_tls_backend_finalize;
87 }
88  
89 static GTlsDatabase *
90 g_dummy_tls_backend_get_default_database (GTlsBackend *backend)
91 {
92 GDummyTlsBackend *dummy = G_DUMMY_TLS_BACKEND (backend);
93  
94 if (g_once_init_enter (&dummy->database))
95 {
96 GTlsDatabase *tlsdb;
97  
98 tlsdb = g_object_new (_g_dummy_tls_database_get_type (), NULL);
99 g_once_init_leave (&dummy->database, tlsdb);
100 }
101  
102 return g_object_ref (dummy->database);
103 }
104  
105 static void
106 g_dummy_tls_backend_iface_init (GTlsBackendInterface *iface)
107 {
108 iface->get_certificate_type = _g_dummy_tls_certificate_get_type;
109 iface->get_client_connection_type = _g_dummy_tls_connection_get_type;
110 iface->get_server_connection_type = _g_dummy_tls_connection_get_type;
111 iface->get_dtls_client_connection_type = _g_dummy_dtls_connection_get_type;
112 iface->get_dtls_server_connection_type = _g_dummy_dtls_connection_get_type;
113 iface->get_file_database_type = _g_dummy_tls_database_get_type;
114 iface->get_default_database = g_dummy_tls_backend_get_default_database;
115 }
116  
117 /* Dummy certificate type */
118  
119 typedef struct _GDummyTlsCertificate GDummyTlsCertificate;
120 typedef struct _GDummyTlsCertificateClass GDummyTlsCertificateClass;
121  
122 struct _GDummyTlsCertificate {
123 GTlsCertificate parent_instance;
124 };
125  
126 struct _GDummyTlsCertificateClass {
127 GTlsCertificateClass parent_class;
128 };
129  
130 enum
131 {
132 PROP_CERTIFICATE_0,
133  
134 PROP_CERT_CERTIFICATE,
135 PROP_CERT_CERTIFICATE_PEM,
136 PROP_CERT_PRIVATE_KEY,
137 PROP_CERT_PRIVATE_KEY_PEM,
138 PROP_CERT_ISSUER
139 };
140  
141 static void g_dummy_tls_certificate_initable_iface_init (GInitableIface *iface);
142  
143 #define g_dummy_tls_certificate_get_type _g_dummy_tls_certificate_get_type
144 G_DEFINE_TYPE_WITH_CODE (GDummyTlsCertificate, g_dummy_tls_certificate, G_TYPE_TLS_CERTIFICATE,
145 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
146 g_dummy_tls_certificate_initable_iface_init);)
147  
148 static void
149 g_dummy_tls_certificate_get_property (GObject *object,
150 guint prop_id,
151 GValue *value,
152 GParamSpec *pspec)
153 {
154 /* We need to define this method to make GObject happy, but it will
155 * never be possible to construct a working GDummyTlsCertificate, so
156 * it doesn't have to do anything useful.
157 */
158 }
159  
160 static void
161 g_dummy_tls_certificate_set_property (GObject *object,
162 guint prop_id,
163 const GValue *value,
164 GParamSpec *pspec)
165 {
166 /* Just ignore all attempts to set properties. */
167 }
168  
169 static void
170 g_dummy_tls_certificate_class_init (GDummyTlsCertificateClass *certificate_class)
171 {
172 GObjectClass *gobject_class = G_OBJECT_CLASS (certificate_class);
173  
174 gobject_class->get_property = g_dummy_tls_certificate_get_property;
175 gobject_class->set_property = g_dummy_tls_certificate_set_property;
176  
177 g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE, "certificate");
178 g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_PEM, "certificate-pem");
179 g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY, "private-key");
180 g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_PEM, "private-key-pem");
181 g_object_class_override_property (gobject_class, PROP_CERT_ISSUER, "issuer");
182 }
183  
184 static void
185 g_dummy_tls_certificate_init (GDummyTlsCertificate *certificate)
186 {
187 }
188  
189 static gboolean
190 g_dummy_tls_certificate_initable_init (GInitable *initable,
191 GCancellable *cancellable,
192 GError **error)
193 {
194 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
195 _("TLS support is not available"));
196 return FALSE;
197 }
198  
199 static void
200 g_dummy_tls_certificate_initable_iface_init (GInitableIface *iface)
201 {
202 iface->init = g_dummy_tls_certificate_initable_init;
203 }
204  
205 /* Dummy connection type; since GTlsClientConnection and
206 * GTlsServerConnection are just interfaces, we can implement them
207 * both on a single object.
208 */
209  
210 typedef struct _GDummyTlsConnection GDummyTlsConnection;
211 typedef struct _GDummyTlsConnectionClass GDummyTlsConnectionClass;
212  
213 struct _GDummyTlsConnection {
214 GTlsConnection parent_instance;
215 };
216  
217 struct _GDummyTlsConnectionClass {
218 GTlsConnectionClass parent_class;
219 };
220  
221 enum
222 {
223 PROP_CONNECTION_0,
224  
225 PROP_CONN_BASE_IO_STREAM,
226 PROP_CONN_USE_SYSTEM_CERTDB,
227 PROP_CONN_REQUIRE_CLOSE_NOTIFY,
228 PROP_CONN_REHANDSHAKE_MODE,
229 PROP_CONN_CERTIFICATE,
230 PROP_CONN_DATABASE,
231 PROP_CONN_INTERACTION,
232 PROP_CONN_PEER_CERTIFICATE,
233 PROP_CONN_PEER_CERTIFICATE_ERRORS,
234 PROP_CONN_VALIDATION_FLAGS,
235 PROP_CONN_SERVER_IDENTITY,
236 PROP_CONN_USE_SSL3,
237 PROP_CONN_ACCEPTED_CAS,
238 PROP_CONN_AUTHENTICATION_MODE
239 };
240  
241 static void g_dummy_tls_connection_initable_iface_init (GInitableIface *iface);
242  
243 #define g_dummy_tls_connection_get_type _g_dummy_tls_connection_get_type
244 G_DEFINE_TYPE_WITH_CODE (GDummyTlsConnection, g_dummy_tls_connection, G_TYPE_TLS_CONNECTION,
245 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_CLIENT_CONNECTION, NULL);
246 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_SERVER_CONNECTION, NULL);
247 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
248 g_dummy_tls_connection_initable_iface_init);)
249  
250 static void
251 g_dummy_tls_connection_get_property (GObject *object,
252 guint prop_id,
253 GValue *value,
254 GParamSpec *pspec)
255 {
256 }
257  
258 static void
259 g_dummy_tls_connection_set_property (GObject *object,
260 guint prop_id,
261 const GValue *value,
262 GParamSpec *pspec)
263 {
264 }
265  
266 static gboolean
267 g_dummy_tls_connection_close (GIOStream *stream,
268 GCancellable *cancellable,
269 GError **error)
270 {
271 return TRUE;
272 }
273  
274 static void
275 g_dummy_tls_connection_class_init (GDummyTlsConnectionClass *connection_class)
276 {
277 GObjectClass *gobject_class = G_OBJECT_CLASS (connection_class);
278 GIOStreamClass *io_stream_class = G_IO_STREAM_CLASS (connection_class);
279  
280 gobject_class->get_property = g_dummy_tls_connection_get_property;
281 gobject_class->set_property = g_dummy_tls_connection_set_property;
282  
283 /* Need to override this because when initable_init fails it will
284 * dispose the connection, which will close it, which would
285 * otherwise try to close its input/output streams, which don't
286 * exist.
287 */
288 io_stream_class->close_fn = g_dummy_tls_connection_close;
289  
290 g_object_class_override_property (gobject_class, PROP_CONN_BASE_IO_STREAM, "base-io-stream");
291 g_object_class_override_property (gobject_class, PROP_CONN_USE_SYSTEM_CERTDB, "use-system-certdb");
292 g_object_class_override_property (gobject_class, PROP_CONN_REQUIRE_CLOSE_NOTIFY, "require-close-notify");
293 g_object_class_override_property (gobject_class, PROP_CONN_REHANDSHAKE_MODE, "rehandshake-mode");
294 g_object_class_override_property (gobject_class, PROP_CONN_CERTIFICATE, "certificate");
295 g_object_class_override_property (gobject_class, PROP_CONN_DATABASE, "database");
296 g_object_class_override_property (gobject_class, PROP_CONN_INTERACTION, "interaction");
297 g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE, "peer-certificate");
298 g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE_ERRORS, "peer-certificate-errors");
299 g_object_class_override_property (gobject_class, PROP_CONN_VALIDATION_FLAGS, "validation-flags");
300 g_object_class_override_property (gobject_class, PROP_CONN_SERVER_IDENTITY, "server-identity");
301 g_object_class_override_property (gobject_class, PROP_CONN_USE_SSL3, "use-ssl3");
302 g_object_class_override_property (gobject_class, PROP_CONN_ACCEPTED_CAS, "accepted-cas");
303 g_object_class_override_property (gobject_class, PROP_CONN_AUTHENTICATION_MODE, "authentication-mode");
304 }
305  
306 static void
307 g_dummy_tls_connection_init (GDummyTlsConnection *connection)
308 {
309 }
310  
311 static gboolean
312 g_dummy_tls_connection_initable_init (GInitable *initable,
313 GCancellable *cancellable,
314 GError **error)
315 {
316 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
317 _("TLS support is not available"));
318 return FALSE;
319 }
320  
321 static void
322 g_dummy_tls_connection_initable_iface_init (GInitableIface *iface)
323 {
324 iface->init = g_dummy_tls_connection_initable_init;
325 }
326  
327 /* Dummy DTLS connection type; since GDtlsClientConnection and
328 * GDtlsServerConnection are just interfaces, we can implement them
329 * both on a single object.
330 */
331  
332 typedef struct _GDummyDtlsConnection GDummyDtlsConnection;
333 typedef struct _GDummyDtlsConnectionClass GDummyDtlsConnectionClass;
334  
335 struct _GDummyDtlsConnection {
336 GObject parent_instance;
337 };
338  
339 struct _GDummyDtlsConnectionClass {
340 GObjectClass parent_class;
341 };
342  
343 enum
344 {
345 PROP_DTLS_CONN_BASE_SOCKET = 1,
346 PROP_DTLS_CONN_REQUIRE_CLOSE_NOTIFY,
347 PROP_DTLS_CONN_REHANDSHAKE_MODE,
348 PROP_DTLS_CONN_CERTIFICATE,
349 PROP_DTLS_CONN_DATABASE,
350 PROP_DTLS_CONN_INTERACTION,
351 PROP_DTLS_CONN_PEER_CERTIFICATE,
352 PROP_DTLS_CONN_PEER_CERTIFICATE_ERRORS,
353 PROP_DTLS_CONN_VALIDATION_FLAGS,
354 PROP_DTLS_CONN_SERVER_IDENTITY,
355 PROP_DTLS_CONN_ENABLE_NEGOTIATION,
356 PROP_DTLS_CONN_ACCEPTED_CAS,
357 PROP_DTLS_CONN_AUTHENTICATION_MODE,
358 };
359  
360 static void g_dummy_dtls_connection_initable_iface_init (GInitableIface *iface);
361  
362 #define g_dummy_dtls_connection_get_type _g_dummy_dtls_connection_get_type
363 G_DEFINE_TYPE_WITH_CODE (GDummyDtlsConnection, g_dummy_dtls_connection, G_TYPE_OBJECT,
364 G_IMPLEMENT_INTERFACE (G_TYPE_DTLS_CONNECTION, NULL);
365 G_IMPLEMENT_INTERFACE (G_TYPE_DTLS_CLIENT_CONNECTION, NULL);
366 G_IMPLEMENT_INTERFACE (G_TYPE_DTLS_SERVER_CONNECTION, NULL);
367 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
368 g_dummy_dtls_connection_initable_iface_init);)
369  
370 static void
371 g_dummy_dtls_connection_get_property (GObject *object,
372 guint prop_id,
373 GValue *value,
374 GParamSpec *pspec)
375 {
376 }
377  
378 static void
379 g_dummy_dtls_connection_set_property (GObject *object,
380 guint prop_id,
381 const GValue *value,
382 GParamSpec *pspec)
383 {
384 }
385  
386 static void
387 g_dummy_dtls_connection_class_init (GDummyDtlsConnectionClass *connection_class)
388 {
389 GObjectClass *gobject_class = G_OBJECT_CLASS (connection_class);
390  
391 gobject_class->get_property = g_dummy_dtls_connection_get_property;
392 gobject_class->set_property = g_dummy_dtls_connection_set_property;
393  
394 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_BASE_SOCKET, "base-socket");
395 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_REQUIRE_CLOSE_NOTIFY, "require-close-notify");
396 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_REHANDSHAKE_MODE, "rehandshake-mode");
397 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_CERTIFICATE, "certificate");
398 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_DATABASE, "database");
399 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_INTERACTION, "interaction");
400 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_PEER_CERTIFICATE, "peer-certificate");
401 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_PEER_CERTIFICATE_ERRORS, "peer-certificate-errors");
402 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_VALIDATION_FLAGS, "validation-flags");
403 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_SERVER_IDENTITY, "server-identity");
404 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_ACCEPTED_CAS, "accepted-cas");
405 g_object_class_override_property (gobject_class, PROP_DTLS_CONN_AUTHENTICATION_MODE, "authentication-mode");
406 }
407  
408 static void
409 g_dummy_dtls_connection_init (GDummyDtlsConnection *connection)
410 {
411 }
412  
413 static gboolean
414 g_dummy_dtls_connection_initable_init (GInitable *initable,
415 GCancellable *cancellable,
416 GError **error)
417 {
418 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
419 _("DTLS support is not available"));
420 return FALSE;
421 }
422  
423 static void
424 g_dummy_dtls_connection_initable_iface_init (GInitableIface *iface)
425 {
426 iface->init = g_dummy_dtls_connection_initable_init;
427 }
428  
429 /* Dummy database type.
430 */
431  
432 typedef struct _GDummyTlsDatabase GDummyTlsDatabase;
433 typedef struct _GDummyTlsDatabaseClass GDummyTlsDatabaseClass;
434  
435 struct _GDummyTlsDatabase {
436 GTlsDatabase parent_instance;
437 };
438  
439 struct _GDummyTlsDatabaseClass {
440 GTlsDatabaseClass parent_class;
441 };
442  
443 enum
444 {
445 PROP_DATABASE_0,
446  
447 PROP_ANCHORS,
448 };
449  
450 static void g_dummy_tls_database_file_database_iface_init (GTlsFileDatabaseInterface *iface);
451 static void g_dummy_tls_database_initable_iface_init (GInitableIface *iface);
452  
453 #define g_dummy_tls_database_get_type _g_dummy_tls_database_get_type
454 G_DEFINE_TYPE_WITH_CODE (GDummyTlsDatabase, g_dummy_tls_database, G_TYPE_TLS_DATABASE,
455 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_FILE_DATABASE,
456 g_dummy_tls_database_file_database_iface_init);
457 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
458 g_dummy_tls_database_initable_iface_init);)
459  
460  
461 static void
462 g_dummy_tls_database_get_property (GObject *object,
463 guint prop_id,
464 GValue *value,
465 GParamSpec *pspec)
466 {
467 /* We need to define this method to make GObject happy, but it will
468 * never be possible to construct a working GDummyTlsDatabase, so
469 * it doesn't have to do anything useful.
470 */
471 }
472  
473 static void
474 g_dummy_tls_database_set_property (GObject *object,
475 guint prop_id,
476 const GValue *value,
477 GParamSpec *pspec)
478 {
479 /* Just ignore all attempts to set properties. */
480 }
481  
482 static void
483 g_dummy_tls_database_class_init (GDummyTlsDatabaseClass *database_class)
484 {
485 GObjectClass *gobject_class = G_OBJECT_CLASS (database_class);
486  
487 gobject_class->get_property = g_dummy_tls_database_get_property;
488 gobject_class->set_property = g_dummy_tls_database_set_property;
489  
490 g_object_class_override_property (gobject_class, PROP_ANCHORS, "anchors");
491 }
492  
493 static void
494 g_dummy_tls_database_init (GDummyTlsDatabase *database)
495 {
496 }
497  
498 static void
499 g_dummy_tls_database_file_database_iface_init (GTlsFileDatabaseInterface *iface)
500 {
501 }
502  
503 static gboolean
504 g_dummy_tls_database_initable_init (GInitable *initable,
505 GCancellable *cancellable,
506 GError **error)
507 {
508 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
509 _("TLS support is not available"));
510 return FALSE;
511 }
512  
513 static void
514 g_dummy_tls_database_initable_iface_init (GInitableIface *iface)
515 {
516 iface->init = g_dummy_tls_database_initable_init;
517 }