2
* tls-certificate.c - Source for IdleTLSCertificate
3
* Copyright (C) 2010 Collabora Ltd.
4
* @author Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
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.1 of the License, or (at your option) any later version.
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.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "tls-certificate.h"
24
#include <telepathy-glib/telepathy-glib.h>
26
#if TP_MAJOR_VERSION > 0 || TP_MINOR_VERSION >= 20
27
# include <telepathy-glib/telepathy-glib-dbus.h>
29
# include <telepathy-glib/gtypes.h>
30
# include <telepathy-glib/interfaces.h>
31
# include <telepathy-glib/svc-tls.h>
34
#define IDLE_DEBUG_FLAG IDLE_DEBUG_TLS
35
#include "idle-debug.h"
38
tls_certificate_iface_init (gpointer g_iface, gpointer iface_data);
40
G_DEFINE_TYPE_WITH_CODE (IdleTLSCertificate,
43
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_AUTHENTICATION_TLS_CERTIFICATE,
44
tls_certificate_iface_init);
45
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
46
tp_dbus_properties_mixin_iface_init);)
48
struct _IdleTLSCertificatePrivate {
52
TpTLSCertificateState cert_state;
54
GPtrArray *rejections;
59
gboolean dispose_has_run;
66
PROP_CERTIFICATE_TYPE,
67
PROP_CERTIFICATE_CHAIN_DATA,
76
idle_tls_certificate_get_property (GObject *object,
81
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
85
case PROP_OBJECT_PATH:
86
g_value_set_string (value, self->priv->object_path);
89
g_value_set_uint (value, self->priv->cert_state);
92
g_value_set_boxed (value, self->priv->rejections);
94
case PROP_CERTIFICATE_TYPE:
95
g_value_set_string (value, self->priv->cert_type);
97
case PROP_CERTIFICATE_CHAIN_DATA:
98
g_value_set_boxed (value, self->priv->cert_data);
101
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
107
idle_tls_certificate_set_property (GObject *object,
112
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
116
case PROP_OBJECT_PATH:
117
self->priv->object_path = g_value_dup_string (value);
119
case PROP_CERTIFICATE_TYPE:
120
self->priv->cert_type = g_value_dup_string (value);
122
case PROP_CERTIFICATE_CHAIN_DATA:
123
self->priv->cert_data = g_value_dup_boxed (value);
125
case PROP_DBUS_DAEMON:
126
self->priv->daemon = g_value_dup_object (value);
129
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, value);
135
idle_tls_certificate_finalize (GObject *object)
137
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
139
tp_clear_boxed (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
140
&self->priv->rejections);
142
g_free (self->priv->object_path);
143
g_free (self->priv->cert_type);
144
g_ptr_array_unref (self->priv->cert_data);
146
G_OBJECT_CLASS (idle_tls_certificate_parent_class)->finalize (object);
150
idle_tls_certificate_dispose (GObject *object)
152
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
154
if (self->priv->dispose_has_run)
157
self->priv->dispose_has_run = TRUE;
159
tp_clear_object (&self->priv->daemon);
161
G_OBJECT_CLASS (idle_tls_certificate_parent_class)->dispose (object);
165
idle_tls_certificate_constructed (GObject *object)
167
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
168
void (*chain_up) (GObject *) =
169
G_OBJECT_CLASS (idle_tls_certificate_parent_class)->constructed;
171
if (chain_up != NULL)
174
/* register the certificate on the bus */
175
tp_dbus_daemon_register_object (self->priv->daemon,
176
self->priv->object_path, self);
180
idle_tls_certificate_init (IdleTLSCertificate *self)
182
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
183
IDLE_TYPE_TLS_CERTIFICATE, IdleTLSCertificatePrivate);
184
self->priv->rejections = g_ptr_array_new ();
188
idle_tls_certificate_class_init (IdleTLSCertificateClass *klass)
190
static TpDBusPropertiesMixinPropImpl object_props[] = {
191
{ "State", "state", NULL },
192
{ "Rejections", "rejections", NULL },
193
{ "CertificateType", "certificate-type", NULL },
194
{ "CertificateChainData", "certificate-chain-data", NULL },
197
static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
198
{ TP_IFACE_AUTHENTICATION_TLS_CERTIFICATE,
199
tp_dbus_properties_mixin_getter_gobject_properties,
205
GObjectClass *oclass = G_OBJECT_CLASS (klass);
208
g_type_class_add_private (klass, sizeof (IdleTLSCertificatePrivate));
210
oclass->finalize = idle_tls_certificate_finalize;
211
oclass->dispose = idle_tls_certificate_dispose;
212
oclass->set_property = idle_tls_certificate_set_property;
213
oclass->get_property = idle_tls_certificate_get_property;
214
oclass->constructed = idle_tls_certificate_constructed;
216
pspec = g_param_spec_string ("object-path",
218
"The D-Bus object path used for this object on the bus.",
220
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
221
g_object_class_install_property (oclass, PROP_OBJECT_PATH, pspec);
223
pspec = g_param_spec_uint ("state",
224
"State of this certificate",
225
"The state of this TLS certificate.",
226
0, NUM_TP_TLS_CERTIFICATE_STATES - 1,
227
TP_TLS_CERTIFICATE_STATE_PENDING,
228
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
229
g_object_class_install_property (oclass, PROP_STATE, pspec);
231
pspec = g_param_spec_boxed ("rejections",
232
"The reject reasons",
233
"The reasons why this TLS certificate has been rejected",
234
TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
235
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
236
g_object_class_install_property (oclass, PROP_REJECTIONS, pspec);
238
pspec = g_param_spec_string ("certificate-type",
239
"The certificate type",
240
"The type of this certificate.",
242
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
243
g_object_class_install_property (oclass, PROP_CERTIFICATE_TYPE, pspec);
245
pspec = g_param_spec_boxed ("certificate-chain-data",
246
"The certificate chain data",
247
"The raw PEM-encoded trust chain of this certificate.",
248
TP_ARRAY_TYPE_UCHAR_ARRAY_LIST,
249
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
250
g_object_class_install_property (oclass, PROP_CERTIFICATE_CHAIN_DATA, pspec);
252
pspec = g_param_spec_object ("dbus-daemon",
253
"The DBus daemon connection",
254
"The connection to the DBus daemon owning the CM",
256
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
257
g_object_class_install_property (oclass, PROP_DBUS_DAEMON, pspec);
259
klass->dbus_props_class.interfaces = prop_interfaces;
260
tp_dbus_properties_mixin_class_init (oclass,
261
G_STRUCT_OFFSET (IdleTLSCertificateClass, dbus_props_class));
265
idle_tls_certificate_accept (TpSvcAuthenticationTLSCertificate *cert,
266
DBusGMethodInvocation *context)
268
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (cert);
270
IDLE_DEBUG ("Accept() called on the TLS certificate; current state %u",
271
self->priv->cert_state);
273
if (self->priv->cert_state != TP_TLS_CERTIFICATE_STATE_PENDING)
277
TP_ERROR_INVALID_ARGUMENT,
278
"Calling Accept() on a certificate with state != PENDING "
279
"doesn't make sense."
282
dbus_g_method_return_error (context, &error);
286
self->priv->cert_state = TP_TLS_CERTIFICATE_STATE_ACCEPTED;
287
tp_svc_authentication_tls_certificate_emit_accepted (self);
289
tp_svc_authentication_tls_certificate_return_from_accept (context);
293
idle_tls_certificate_reject (TpSvcAuthenticationTLSCertificate *cert,
294
const GPtrArray *rejections,
295
DBusGMethodInvocation *context)
297
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (cert);
299
IDLE_DEBUG ("Reject() called on the TLS certificate with rejections %p, "
300
"length %u; current state %u", rejections, rejections->len,
301
self->priv->cert_state);
303
if (rejections->len < 1)
305
GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
306
"Calling Reject() with a zero-length rejection list." };
308
dbus_g_method_return_error (context, &error);
312
if (self->priv->cert_state != TP_TLS_CERTIFICATE_STATE_PENDING)
316
TP_ERROR_INVALID_ARGUMENT,
317
"Calling Reject() on a certificate with state != PENDING "
318
"doesn't make sense."
321
dbus_g_method_return_error (context, &error);
325
tp_clear_boxed (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
326
&self->priv->rejections);
328
self->priv->rejections =
329
g_boxed_copy (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
331
self->priv->cert_state = TP_TLS_CERTIFICATE_STATE_REJECTED;
333
tp_svc_authentication_tls_certificate_emit_rejected (
334
self, self->priv->rejections);
336
tp_svc_authentication_tls_certificate_return_from_reject (context);
340
tls_certificate_iface_init (gpointer g_iface,
343
TpSvcAuthenticationTLSCertificateClass *klass = g_iface;
345
#define IMPLEMENT(x) \
346
tp_svc_authentication_tls_certificate_implement_##x ( \
347
klass, idle_tls_certificate_##x)