gio: Add DTLS interfaces

Add a new GDtlsConnection interface, plus derived GDtlsClientConnection
and GDtlsServerConnection interfaces, for implementing Datagram TLS
support in glib-networking.

A GDtlsConnection is a GDatagramBased, so may be used as a normal
datagram socket, wrapping all datagrams from a base GDatagramBased in
DTLS segments.

Test cases are included in the implementation in glib-networking.

https://bugzilla.gnome.org/show_bug.cgi?id=752240
This commit is contained in:
Philip Withnall
2015-06-25 12:58:14 +01:00
parent e3ab6ab38a
commit c3d6934f18
17 changed files with 1970 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
/* GIO - GLib Input, Output and Streaming Library
*
* Copyright (C) 2010 Red Hat, Inc.
* Copyright © 2015 Collabora, Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -25,6 +26,9 @@
#include "gasyncresult.h"
#include "gcancellable.h"
#include "ginitable.h"
#include "gdtlsclientconnection.h"
#include "gdtlsconnection.h"
#include "gdtlsserverconnection.h"
#include "gtlsbackend.h"
#include "gtlscertificate.h"
#include "gtlsclientconnection.h"
@@ -39,6 +43,7 @@
static GType _g_dummy_tls_certificate_get_type (void);
static GType _g_dummy_tls_connection_get_type (void);
static GType _g_dummy_dtls_connection_get_type (void);
static GType _g_dummy_tls_database_get_type (void);
struct _GDummyTlsBackend {
@@ -103,6 +108,8 @@ g_dummy_tls_backend_iface_init (GTlsBackendInterface *iface)
iface->get_certificate_type = _g_dummy_tls_certificate_get_type;
iface->get_client_connection_type = _g_dummy_tls_connection_get_type;
iface->get_server_connection_type = _g_dummy_tls_connection_get_type;
iface->get_dtls_client_connection_type = _g_dummy_dtls_connection_get_type;
iface->get_dtls_server_connection_type = _g_dummy_dtls_connection_get_type;
iface->get_file_database_type = _g_dummy_tls_database_get_type;
iface->get_default_database = g_dummy_tls_backend_get_default_database;
}
@@ -317,6 +324,108 @@ g_dummy_tls_connection_initable_iface_init (GInitableIface *iface)
iface->init = g_dummy_tls_connection_initable_init;
}
/* Dummy DTLS connection type; since GDtlsClientConnection and
* GDtlsServerConnection are just interfaces, we can implement them
* both on a single object.
*/
typedef struct _GDummyDtlsConnection GDummyDtlsConnection;
typedef struct _GDummyDtlsConnectionClass GDummyDtlsConnectionClass;
struct _GDummyDtlsConnection {
GObject parent_instance;
};
struct _GDummyDtlsConnectionClass {
GObjectClass parent_class;
};
enum
{
PROP_DTLS_CONN_BASE_SOCKET = 1,
PROP_DTLS_CONN_REQUIRE_CLOSE_NOTIFY,
PROP_DTLS_CONN_REHANDSHAKE_MODE,
PROP_DTLS_CONN_CERTIFICATE,
PROP_DTLS_CONN_DATABASE,
PROP_DTLS_CONN_INTERACTION,
PROP_DTLS_CONN_PEER_CERTIFICATE,
PROP_DTLS_CONN_PEER_CERTIFICATE_ERRORS,
PROP_DTLS_CONN_VALIDATION_FLAGS,
PROP_DTLS_CONN_SERVER_IDENTITY,
PROP_DTLS_CONN_ENABLE_NEGOTIATION,
PROP_DTLS_CONN_ACCEPTED_CAS,
PROP_DTLS_CONN_AUTHENTICATION_MODE,
};
static void g_dummy_dtls_connection_initable_iface_init (GInitableIface *iface);
#define g_dummy_dtls_connection_get_type _g_dummy_dtls_connection_get_type
G_DEFINE_TYPE_WITH_CODE (GDummyDtlsConnection, g_dummy_dtls_connection, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_DTLS_CONNECTION, NULL);
G_IMPLEMENT_INTERFACE (G_TYPE_DTLS_CLIENT_CONNECTION, NULL);
G_IMPLEMENT_INTERFACE (G_TYPE_DTLS_SERVER_CONNECTION, NULL);
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
g_dummy_dtls_connection_initable_iface_init);)
static void
g_dummy_dtls_connection_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
}
static void
g_dummy_dtls_connection_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
}
static void
g_dummy_dtls_connection_class_init (GDummyDtlsConnectionClass *connection_class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (connection_class);
gobject_class->get_property = g_dummy_dtls_connection_get_property;
gobject_class->set_property = g_dummy_dtls_connection_set_property;
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_BASE_SOCKET, "base-socket");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_REQUIRE_CLOSE_NOTIFY, "require-close-notify");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_REHANDSHAKE_MODE, "rehandshake-mode");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_CERTIFICATE, "certificate");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_DATABASE, "database");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_INTERACTION, "interaction");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_PEER_CERTIFICATE, "peer-certificate");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_PEER_CERTIFICATE_ERRORS, "peer-certificate-errors");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_VALIDATION_FLAGS, "validation-flags");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_SERVER_IDENTITY, "server-identity");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_ACCEPTED_CAS, "accepted-cas");
g_object_class_override_property (gobject_class, PROP_DTLS_CONN_AUTHENTICATION_MODE, "authentication-mode");
}
static void
g_dummy_dtls_connection_init (GDummyDtlsConnection *connection)
{
}
static gboolean
g_dummy_dtls_connection_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
_("DTLS support is not available"));
return FALSE;
}
static void
g_dummy_dtls_connection_initable_iface_init (GInitableIface *iface)
{
iface->init = g_dummy_dtls_connection_initable_init;
}
/* Dummy database type.
*/