Improve GTimeZone test coverage
[glib.git] / gio / gtlsdatabase.c
blob9d2b77e4ee39f042f07e874b829ef6d39875406d
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2010 Collabora, Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Stef Walter <stefw@collabora.co.uk>
23 #include "config.h"
25 #include "gtlsdatabase.h"
27 #include "gasyncresult.h"
28 #include "gcancellable.h"
29 #include "glibintl.h"
30 #include "gsimpleasyncresult.h"
31 #include "gsocketconnectable.h"
32 #include "gtlscertificate.h"
33 #include "gtlsinteraction.h"
35 /**
36 * SECTION:gtlsdatabase
37 * @short_description: TLS database type
38 * @include: gio/gio.h
40 * #GTlsDatabase is used to lookup certificates and other information
41 * from a certificate or key store. It is an abstract base class which
42 * TLS library specific subtypes override.
44 * Most common client applications will not directly interact with
45 * #GTlsDatabase. It is used internally by #GTlsConnection.
47 * Since: 2.30
50 /**
51 * GTlsDatabase:
53 * Abstract base class for the backend-specific database types.
55 * Since: 2.30
58 G_DEFINE_ABSTRACT_TYPE (GTlsDatabase, g_tls_database, G_TYPE_OBJECT);
60 enum {
61 UNLOCK_REQUIRED,
63 LAST_SIGNAL
66 /**
67 * G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER:
69 * The purpose used to verify the server certificate in a TLS connection. This
70 * is the most common purpose in use. Used by TLS clients.
73 /**
74 * G_TLS_DATABASE_PURPOSE_AUTHENTICATE_CLIENT:
76 * The purpose used to verify the client certificate in a TLS connection.
77 * Used by TLS servers.
80 static void
81 g_tls_database_init (GTlsDatabase *cert)
86 typedef struct _AsyncVerifyChain {
87 GTlsCertificate *chain;
88 gchar *purpose;
89 GSocketConnectable *identity;
90 GTlsInteraction *interaction;
91 GTlsDatabaseVerifyFlags flags;
92 GTlsCertificateFlags verify_result;
93 } AsyncVerifyChain;
95 static void
96 async_verify_chain_free (gpointer data)
98 AsyncVerifyChain *args = data;
99 g_clear_object (&args->chain);
100 g_free (args->purpose);
101 g_clear_object (&args->identity);
102 g_clear_object (&args->interaction);
103 g_slice_free (AsyncVerifyChain, args);
106 static void
107 async_verify_chain_thread (GSimpleAsyncResult *res,
108 GObject *object,
109 GCancellable *cancellable)
111 AsyncVerifyChain *args = g_simple_async_result_get_op_res_gpointer (res);
112 GError *error = NULL;
114 args->verify_result = g_tls_database_verify_chain (G_TLS_DATABASE (object),
115 args->chain,
116 args->purpose,
117 args->identity,
118 args->interaction,
119 args->flags,
120 cancellable,
121 &error);
123 if (error)
124 g_simple_async_result_take_error (res, error);
127 static void
128 g_tls_database_real_verify_chain_async (GTlsDatabase *self,
129 GTlsCertificate *chain,
130 const gchar *purpose,
131 GSocketConnectable *identity,
132 GTlsInteraction *interaction,
133 GTlsDatabaseVerifyFlags flags,
134 GCancellable *cancellable,
135 GAsyncReadyCallback callback,
136 gpointer user_data)
138 GSimpleAsyncResult *res;
139 AsyncVerifyChain *args;
141 args = g_slice_new0 (AsyncVerifyChain);
142 args->chain = g_object_ref (chain);
143 args->purpose = g_strdup (purpose);
144 args->identity = identity ? g_object_ref (identity) : NULL;
145 args->interaction = interaction ? g_object_ref (interaction) : NULL;
146 args->flags = flags;
148 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
149 g_tls_database_real_verify_chain_async);
150 g_simple_async_result_set_op_res_gpointer (res, args, async_verify_chain_free);
151 g_simple_async_result_run_in_thread (res, async_verify_chain_thread,
152 G_PRIORITY_DEFAULT, cancellable);
153 g_object_unref (res);
156 static GTlsCertificateFlags
157 g_tls_database_real_verify_chain_finish (GTlsDatabase *self,
158 GAsyncResult *result,
159 GError **error)
161 AsyncVerifyChain *args;
163 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), G_TLS_CERTIFICATE_GENERIC_ERROR);
164 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
165 g_tls_database_real_verify_chain_async), FALSE);
167 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
168 return G_TLS_CERTIFICATE_GENERIC_ERROR;
170 args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
171 return args->verify_result;
174 typedef struct {
175 gchar *handle;
176 GTlsInteraction *interaction;
177 GTlsDatabaseLookupFlags flags;
178 GTlsCertificate *result;
179 } AsyncLookupCertificateForHandle;
181 static void
182 async_lookup_certificate_for_handle_free (gpointer data)
184 AsyncLookupCertificateForHandle *args = data;
186 g_free (args->handle);
187 g_clear_object (&args->interaction);
188 g_clear_object (&args->result);
189 g_slice_free (AsyncLookupCertificateForHandle, args);
192 static void
193 async_lookup_certificate_for_handle_thread (GSimpleAsyncResult *res,
194 GObject *object,
195 GCancellable *cancellable)
197 AsyncLookupCertificateForHandle *args = g_simple_async_result_get_op_res_gpointer (res);
198 GError *error = NULL;
200 args->result = g_tls_database_lookup_certificate_for_handle (G_TLS_DATABASE (object),
201 args->handle,
202 args->interaction,
203 args->flags,
204 cancellable,
205 &error);
207 if (error)
208 g_simple_async_result_take_error (res, error);
211 static void
212 g_tls_database_real_lookup_certificate_for_handle_async (GTlsDatabase *self,
213 const gchar *handle,
214 GTlsInteraction *interaction,
215 GTlsDatabaseLookupFlags flags,
216 GCancellable *cancellable,
217 GAsyncReadyCallback callback,
218 gpointer user_data)
220 GSimpleAsyncResult *res;
221 AsyncLookupCertificateForHandle *args;
223 g_return_if_fail (callback != NULL);
225 args = g_slice_new0 (AsyncLookupCertificateForHandle);
226 args->handle = g_strdup (handle);
227 args->interaction = interaction ? g_object_ref (interaction) : NULL;
229 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
230 g_tls_database_real_lookup_certificate_for_handle_async);
231 g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificate_for_handle_free);
232 g_simple_async_result_run_in_thread (res, async_lookup_certificate_for_handle_thread,
233 G_PRIORITY_DEFAULT, cancellable);
234 g_object_unref (res);
237 static GTlsCertificate*
238 g_tls_database_real_lookup_certificate_for_handle_finish (GTlsDatabase *self,
239 GAsyncResult *result,
240 GError **error)
242 AsyncLookupCertificateForHandle *args;
243 GTlsCertificate *certificate;
245 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
246 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
247 g_tls_database_real_lookup_certificate_for_handle_async), FALSE);
249 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
250 return NULL;
252 args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
253 certificate = args->result;
254 args->result = NULL;
255 return certificate;
259 typedef struct {
260 GTlsCertificate *certificate;
261 GTlsInteraction *interaction;
262 GTlsDatabaseLookupFlags flags;
263 GTlsCertificate *issuer;
264 } AsyncLookupCertificateIssuer;
266 static void
267 async_lookup_certificate_issuer_free (gpointer data)
269 AsyncLookupCertificateIssuer *args = data;
271 g_clear_object (&args->certificate);
272 g_clear_object (&args->interaction);
273 g_clear_object (&args->issuer);
274 g_slice_free (AsyncLookupCertificateIssuer, args);
277 static void
278 async_lookup_certificate_issuer_thread (GSimpleAsyncResult *res,
279 GObject *object,
280 GCancellable *cancellable)
282 AsyncLookupCertificateIssuer *args = g_simple_async_result_get_op_res_gpointer (res);
283 GError *error = NULL;
285 args->issuer = g_tls_database_lookup_certificate_issuer (G_TLS_DATABASE (object),
286 args->certificate,
287 args->interaction,
288 args->flags,
289 cancellable,
290 &error);
292 if (error)
293 g_simple_async_result_take_error (res, error);
296 static void
297 g_tls_database_real_lookup_certificate_issuer_async (GTlsDatabase *self,
298 GTlsCertificate *certificate,
299 GTlsInteraction *interaction,
300 GTlsDatabaseLookupFlags flags,
301 GCancellable *cancellable,
302 GAsyncReadyCallback callback,
303 gpointer user_data)
305 GSimpleAsyncResult *res;
306 AsyncLookupCertificateIssuer *args;
308 g_return_if_fail (G_IS_TLS_CERTIFICATE (certificate));
309 g_return_if_fail (callback != NULL);
311 args = g_slice_new0 (AsyncLookupCertificateIssuer);
312 args->certificate = g_object_ref (certificate);
313 args->flags = flags;
314 args->interaction = interaction ? g_object_ref (interaction) : NULL;
316 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
317 g_tls_database_real_lookup_certificate_issuer_async);
318 g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificate_issuer_free);
319 g_simple_async_result_run_in_thread (res, async_lookup_certificate_issuer_thread,
320 G_PRIORITY_DEFAULT, cancellable);
321 g_object_unref (res);
324 static GTlsCertificate*
325 g_tls_database_real_lookup_certificate_issuer_finish (GTlsDatabase *self,
326 GAsyncResult *result,
327 GError **error)
329 AsyncLookupCertificateIssuer *args;
330 GTlsCertificate *issuer;
332 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
333 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
334 g_tls_database_real_lookup_certificate_issuer_async), FALSE);
336 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
337 return NULL;
339 args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
340 issuer = args->issuer;
341 args->issuer = NULL;
342 return issuer;
345 typedef struct {
346 GByteArray *issuer;
347 GTlsInteraction *interaction;
348 GTlsDatabaseLookupFlags flags;
349 GList *results;
350 } AsyncLookupCertificatesIssuedBy;
352 static void
353 async_lookup_certificates_issued_by_free (gpointer data)
355 AsyncLookupCertificatesIssuedBy *args = data;
356 GList *l;
358 g_byte_array_unref (args->issuer);
359 g_clear_object (&args->interaction);
360 for (l = args->results; l; l = g_list_next (l))
361 g_object_unref (l->data);
362 g_list_free (args->results);
363 g_slice_free (AsyncLookupCertificatesIssuedBy, args);
366 static void
367 async_lookup_certificates_issued_by_thread (GSimpleAsyncResult *res,
368 GObject *object,
369 GCancellable *cancellable)
371 AsyncLookupCertificatesIssuedBy *args = g_simple_async_result_get_op_res_gpointer (res);
372 GError *error = NULL;
374 args->results = g_tls_database_lookup_certificates_issued_by (G_TLS_DATABASE (object),
375 args->issuer,
376 args->interaction,
377 args->flags,
378 cancellable,
379 &error);
381 if (error)
382 g_simple_async_result_take_error (res, error);
385 static void
386 g_tls_database_real_lookup_certificates_issued_by_async (GTlsDatabase *self,
387 GByteArray *issuer,
388 GTlsInteraction *interaction,
389 GTlsDatabaseLookupFlags flags,
390 GCancellable *cancellable,
391 GAsyncReadyCallback callback,
392 gpointer user_data)
394 GSimpleAsyncResult *res;
395 AsyncLookupCertificatesIssuedBy *args;
397 g_return_if_fail (callback);
399 args = g_slice_new0 (AsyncLookupCertificatesIssuedBy);
400 args->issuer = g_byte_array_ref (issuer);
401 args->flags = flags;
402 args->interaction = interaction ? g_object_ref (interaction) : NULL;
404 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
405 g_tls_database_real_lookup_certificates_issued_by_async);
406 g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificates_issued_by_free);
407 g_simple_async_result_run_in_thread (res, async_lookup_certificates_issued_by_thread,
408 G_PRIORITY_DEFAULT, cancellable);
409 g_object_unref (res);
412 static GList*
413 g_tls_database_real_lookup_certificates_issued_by_finish (GTlsDatabase *self,
414 GAsyncResult *result,
415 GError **error)
417 AsyncLookupCertificatesIssuedBy *args;
418 GList *results;
420 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
421 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
422 g_tls_database_real_lookup_certificates_issued_by_async), FALSE);
424 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
425 return NULL;
427 args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
428 results = args->results;
429 args->results = NULL;
430 return results;
433 static void
434 g_tls_database_class_init (GTlsDatabaseClass *klass)
436 klass->verify_chain_async = g_tls_database_real_verify_chain_async;
437 klass->verify_chain_finish = g_tls_database_real_verify_chain_finish;
438 klass->lookup_certificate_for_handle_async = g_tls_database_real_lookup_certificate_for_handle_async;
439 klass->lookup_certificate_for_handle_finish = g_tls_database_real_lookup_certificate_for_handle_finish;
440 klass->lookup_certificate_issuer_async = g_tls_database_real_lookup_certificate_issuer_async;
441 klass->lookup_certificate_issuer_finish = g_tls_database_real_lookup_certificate_issuer_finish;
442 klass->lookup_certificates_issued_by_async = g_tls_database_real_lookup_certificates_issued_by_async;
443 klass->lookup_certificates_issued_by_finish = g_tls_database_real_lookup_certificates_issued_by_finish;
447 * g_tls_database_verify_chain:
448 * @self: a #GTlsDatabase
449 * @chain: a #GTlsCertificate chain
450 * @purpose: the purpose that this certificate chain will be used for.
451 * @identity: (allow-none): the expected peer identity
452 * @interaction: (allow-none): used to interact with the user if necessary
453 * @flags: additional verify flags
454 * @cancellable: (allow-none): a #GCancellable, or %NULL
455 * @error: (allow-none): a #GError, or %NULL
457 * Verify's a certificate chain after looking up and adding any missing
458 * certificates to the chain.
460 * @chain is a chain of #GTlsCertificate objects each pointing to the next
461 * certificate in the chain by its %issuer property. The chain may initially
462 * consist of one or more certificates. After the verification process is
463 * complete, @chain may be modified by adding missing certificates, or removing
464 * extra certificates. If a certificate anchor was found, then it is added to
465 * the @chain.
467 * @purpose describes the purpose (or usage) for which the certificate
468 * is being used. Typically @purpose will be set to #G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER
469 * which means that the certificate is being used to authenticate a server
470 * (and we are acting as the client).
472 * The @identity is used to check for pinned certificates (trust exceptions)
473 * in the database. These will override the normal verification process on a
474 * host by host basis.
476 * Currently there are no @flags, and %G_TLS_DATABASE_VERIFY_NONE should be
477 * used.
479 * This function can block, use g_tls_database_verify_chain_async() to perform
480 * the verification operation asynchronously.
482 * Return value: the appropriate #GTlsCertificateFlags which represents the
483 * result of verification.
485 * Since: 2.30
487 GTlsCertificateFlags
488 g_tls_database_verify_chain (GTlsDatabase *self,
489 GTlsCertificate *chain,
490 const gchar *purpose,
491 GSocketConnectable *identity,
492 GTlsInteraction *interaction,
493 GTlsDatabaseVerifyFlags flags,
494 GCancellable *cancellable,
495 GError **error)
497 g_return_val_if_fail (G_IS_TLS_DATABASE (self), G_TLS_CERTIFICATE_GENERIC_ERROR);
498 g_return_val_if_fail (G_IS_TLS_DATABASE (self),
499 G_TLS_CERTIFICATE_GENERIC_ERROR);
500 g_return_val_if_fail (G_IS_TLS_CERTIFICATE (chain),
501 G_TLS_CERTIFICATE_GENERIC_ERROR);
502 g_return_val_if_fail (purpose, G_TLS_CERTIFICATE_GENERIC_ERROR);
503 g_return_val_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction),
504 G_TLS_CERTIFICATE_GENERIC_ERROR);
505 g_return_val_if_fail (identity == NULL || G_IS_SOCKET_CONNECTABLE (identity),
506 G_TLS_CERTIFICATE_GENERIC_ERROR);
507 g_return_val_if_fail (error == NULL || *error == NULL, G_TLS_CERTIFICATE_GENERIC_ERROR);
509 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->verify_chain,
510 G_TLS_CERTIFICATE_GENERIC_ERROR);
512 return G_TLS_DATABASE_GET_CLASS (self)->verify_chain (self,
513 chain,
514 purpose,
515 identity,
516 interaction,
517 flags,
518 cancellable,
519 error);
523 * g_tls_database_verify_chain_async:
524 * @self: a #GTlsDatabase
525 * @chain: a #GTlsCertificate chain
526 * @purpose: the purpose that this certificate chain will be used for.
527 * @identity: (allow-none): the expected peer identity
528 * @interaction: (allow-none): used to interact with the user if necessary
529 * @flags: additional verify flags
530 * @cancellable: (allow-none): a #GCancellable, or %NULL
531 * @callback: callback to call when the operation completes
532 * @user_data: the data to pass to the callback function
534 * Asynchronously verify's a certificate chain after looking up and adding
535 * any missing certificates to the chain. See g_tls_database_verify_chain()
536 * for more information.
538 * Since: 2.30
540 void
541 g_tls_database_verify_chain_async (GTlsDatabase *self,
542 GTlsCertificate *chain,
543 const gchar *purpose,
544 GSocketConnectable *identity,
545 GTlsInteraction *interaction,
546 GTlsDatabaseVerifyFlags flags,
547 GCancellable *cancellable,
548 GAsyncReadyCallback callback,
549 gpointer user_data)
551 g_return_if_fail (G_IS_TLS_DATABASE (self));
552 g_return_if_fail (G_IS_TLS_CERTIFICATE (chain));
553 g_return_if_fail (purpose != NULL);
554 g_return_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction));
555 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
556 g_return_if_fail (identity == NULL || G_IS_SOCKET_CONNECTABLE (identity));
557 g_return_if_fail (callback != NULL);
559 g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->verify_chain_async);
560 G_TLS_DATABASE_GET_CLASS (self)->verify_chain_async (self,
561 chain,
562 purpose,
563 identity,
564 interaction,
565 flags,
566 cancellable,
567 callback,
568 user_data);
572 * g_tls_database_verify_chain_finish:
573 * @self: a #GTlsDatabase
574 * @result: a #GAsyncResult.
575 * @error: a #GError pointer, or %NULL
577 * Finish an asynchronous verify chain operation. See
578 * g_tls_database_verify_chain() for more information. *
579 * Return value: the appropriate #GTlsCertificateFlags which represents the
580 * result of verification.
582 * Since: 2.30
584 GTlsCertificateFlags
585 g_tls_database_verify_chain_finish (GTlsDatabase *self,
586 GAsyncResult *result,
587 GError **error)
589 g_return_val_if_fail (G_IS_TLS_DATABASE (self), G_TLS_CERTIFICATE_GENERIC_ERROR);
590 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), G_TLS_CERTIFICATE_GENERIC_ERROR);
591 g_return_val_if_fail (error == NULL || *error == NULL, G_TLS_CERTIFICATE_GENERIC_ERROR);
592 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->verify_chain_finish,
593 G_TLS_CERTIFICATE_GENERIC_ERROR);
594 return G_TLS_DATABASE_GET_CLASS (self)->verify_chain_finish (self,
595 result,
596 error);
600 * g_tls_database_create_certificate_handle:
601 * @self: a #GTlsDatabase
602 * @certificate: certificate for which to create a handle.
604 * Create a handle string for the certificate. The database will only be able
605 * to create a handle for certificates that originate from the database. In
606 * cases where the database cannot create a handle for a certificate, %NULL
607 * will be returned.
609 * This handle should be stable across various instances of the application,
610 * and between applications. If a certificate is modified in the database,
611 * then it is not guaranteed that this handle will continue to point to it.
613 * Returns: (allow-none): a newly allocated string containing the handle.
614 * Since: 2.30
616 gchar*
617 g_tls_database_create_certificate_handle (GTlsDatabase *self,
618 GTlsCertificate *certificate)
620 g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
621 g_return_val_if_fail (G_IS_TLS_CERTIFICATE (certificate), NULL);
622 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->create_certificate_handle, NULL);
623 return G_TLS_DATABASE_GET_CLASS (self)->create_certificate_handle (self,
624 certificate);
628 * g_tls_database_lookup_certificate_for_handle:
629 * @self: a #GTlsDatabase
630 * @handle: a certificate handle
631 * @interaction: (allow-none): used to interact with the user if necessary
632 * @flags: Flags which affect the lookup.
633 * @cancellable: (allow-none): a #GCancellable, or %NULL
634 * @error: (allow-none): a #GError, or %NULL
636 * Lookup a certificate by its handle.
638 * The handle should have been created by calling
639 * g_tls_database_create_certificate_handle() on a #GTlsDatabase object of
640 * the same TLS backend. The handle is designed to remain valid across
641 * instantiations of the database.
643 * If the handle is no longer valid, or does not point to a certificate in
644 * this database, then %NULL will be returned.
646 * This function can block, use g_tls_database_lookup_certificate_for_handle_async() to perform
647 * the lookup operation asynchronously.
649 * Return value: (transfer full) (allow-none): a newly allocated
650 * #GTlsCertificate, or %NULL. Use g_object_unref() to release the certificate.
652 * Since: 2.30
654 GTlsCertificate*
655 g_tls_database_lookup_certificate_for_handle (GTlsDatabase *self,
656 const gchar *handle,
657 GTlsInteraction *interaction,
658 GTlsDatabaseLookupFlags flags,
659 GCancellable *cancellable,
660 GError **error)
662 g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
663 g_return_val_if_fail (handle != NULL, NULL);
664 g_return_val_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction), NULL);
665 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
666 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
667 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_for_handle, NULL);
668 return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_for_handle (self,
669 handle,
670 interaction,
671 flags,
672 cancellable,
673 error);
678 * g_tls_database_lookup_certificate_for_handle_async:
679 * @self: a #GTlsDatabase
680 * @handle: a certificate handle
681 * @interaction: (allow-none): used to interact with the user if necessary
682 * @flags: Flags which affect the lookup.
683 * @cancellable: (allow-none): a #GCancellable, or %NULL
684 * @callback: callback to call when the operation completes
685 * @user_data: the data to pass to the callback function
687 * Asynchronously lookup a certificate by its handle in the database. See
688 * g_tls_database_lookup_certificate_for_handle() for more information.
690 * Since: 2.30
692 void
693 g_tls_database_lookup_certificate_for_handle_async (GTlsDatabase *self,
694 const gchar *handle,
695 GTlsInteraction *interaction,
696 GTlsDatabaseLookupFlags flags,
697 GCancellable *cancellable,
698 GAsyncReadyCallback callback,
699 gpointer user_data)
701 g_return_if_fail (G_IS_TLS_DATABASE (self));
702 g_return_if_fail (handle != NULL);
703 g_return_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction));
704 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
705 g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_for_handle_async);
706 G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_for_handle_async (self,
707 handle,
708 interaction,
709 flags,
710 cancellable,
711 callback,
712 user_data);
716 * g_tls_database_lookup_certificate_for_handle_finish:
717 * @self: a #GTlsDatabase
718 * @result: a #GAsyncResult.
719 * @error: a #GError pointer, or %NULL
721 * Finish an asynchronous lookup of a certificate by its handle. See
722 * g_tls_database_lookup_certificate_handle() for more information.
724 * If the handle is no longer valid, or does not point to a certificate in
725 * this database, then %NULL will be returned.
727 * Return value: (transfer full): a newly allocated #GTlsCertificate object.
728 * Use g_object_unref() to release the certificate.
730 * Since: 2.30
732 GTlsCertificate*
733 g_tls_database_lookup_certificate_for_handle_finish (GTlsDatabase *self,
734 GAsyncResult *result,
735 GError **error)
737 g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
738 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
739 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
740 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_for_handle_finish, NULL);
741 return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_for_handle_finish (self,
742 result,
743 error);
747 * g_tls_database_lookup_certificate_issuer:
748 * @self: a #GTlsDatabase
749 * @certificate: a #GTlsCertificate
750 * @interaction: (allow-none): used to interact with the user if necessary
751 * @flags: flags which affect the lookup operation
752 * @cancellable: (allow-none): a #GCancellable, or %NULL
753 * @error: (allow-none): a #GError, or %NULL
755 * Lookup the issuer of @certificate in the database.
757 * The %issuer property
758 * of @certificate is not modified, and the two certificates are not hooked
759 * into a chain.
761 * This function can block, use g_tls_database_lookup_certificate_issuer_async() to perform
762 * the lookup operation asynchronously.
764 * Return value: (transfer full): a newly allocated issuer #GTlsCertificate,
765 * or %NULL. Use g_object_unref() to release the certificate.
767 * Since: 2.30
769 GTlsCertificate*
770 g_tls_database_lookup_certificate_issuer (GTlsDatabase *self,
771 GTlsCertificate *certificate,
772 GTlsInteraction *interaction,
773 GTlsDatabaseLookupFlags flags,
774 GCancellable *cancellable,
775 GError **error)
777 g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
778 g_return_val_if_fail (G_IS_TLS_CERTIFICATE (certificate), NULL);
779 g_return_val_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction), NULL);
780 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
781 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
782 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_issuer, NULL);
783 return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_issuer (self,
784 certificate,
785 interaction,
786 flags,
787 cancellable,
788 error);
792 * g_tls_database_lookup_certificate_issuer_async:
793 * @self: a #GTlsDatabase
794 * @certificate: a #GTlsCertificate
795 * @interaction: (allow-none): used to interact with the user if necessary
796 * @flags: flags which affect the lookup operation
797 * @cancellable: (allow-none): a #GCancellable, or %NULL
798 * @callback: callback to call when the operation completes
799 * @user_data: the data to pass to the callback function
801 * Asynchronously lookup the issuer of @certificate in the database. See
802 * g_tls_database_lookup_certificate_issuer() for more information.
804 * Since: 2.30
806 void
807 g_tls_database_lookup_certificate_issuer_async (GTlsDatabase *self,
808 GTlsCertificate *certificate,
809 GTlsInteraction *interaction,
810 GTlsDatabaseLookupFlags flags,
811 GCancellable *cancellable,
812 GAsyncReadyCallback callback,
813 gpointer user_data)
815 g_return_if_fail (G_IS_TLS_DATABASE (self));
816 g_return_if_fail (G_IS_TLS_CERTIFICATE (certificate));
817 g_return_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction));
818 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
819 g_return_if_fail (callback != NULL);
820 g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_issuer_async);
821 G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_issuer_async (self,
822 certificate,
823 interaction,
824 flags,
825 cancellable,
826 callback,
827 user_data);
831 * g_tls_database_lookup_certificate_issuer_finish:
832 * @self: a #GTlsDatabase
833 * @result: a #GAsyncResult.
834 * @error: a #GError pointer, or %NULL
836 * Finish an asynchronous lookup issuer operation. See
837 * g_tls_database_lookup_certificate_issuer() for more information.
839 * Return value: (transfer full): a newly allocated issuer #GTlsCertificate,
840 * or %NULL. Use g_object_unref() to release the certificate.
842 * Since: 2.30
844 GTlsCertificate*
845 g_tls_database_lookup_certificate_issuer_finish (GTlsDatabase *self,
846 GAsyncResult *result,
847 GError **error)
849 g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
850 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
851 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
852 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_issuer_finish, NULL);
853 return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificate_issuer_finish (self,
854 result,
855 error);
859 * g_tls_database_lookup_certificates_issued_by:
860 * @self: a #GTlsDatabase
861 * @issuer_raw_dn: a #GByteArray which holds the DER encoded issuer DN.
862 * @interaction: (allow-none): used to interact with the user if necessary
863 * @flags: Flags which affect the lookup operation.
864 * @cancellable: (allow-none): a #GCancellable, or %NULL
865 * @error: (allow-none): a #GError, or %NULL
867 * Lookup certificates issued by this issuer in the database.
869 * This function can block, use g_tls_database_lookup_certificates_issued_by_async() to perform
870 * the lookup operation asynchronously.
872 * Return value: (transfer full) (element-type GTlsCertificate): a newly allocated list of #GTlsCertificate
873 * objects. Use g_object_unref() on each certificate, and g_list_free() on the release the list.
875 * Since: 2.30
877 GList*
878 g_tls_database_lookup_certificates_issued_by (GTlsDatabase *self,
879 GByteArray *issuer_raw_dn,
880 GTlsInteraction *interaction,
881 GTlsDatabaseLookupFlags flags,
882 GCancellable *cancellable,
883 GError **error)
885 g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
886 g_return_val_if_fail (issuer_raw_dn, NULL);
887 g_return_val_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction), NULL);
888 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
889 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
890 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_issued_by, NULL);
891 return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_issued_by (self,
892 issuer_raw_dn,
893 interaction,
894 flags,
895 cancellable,
896 error);
900 * g_tls_database_lookup_certificates_issued_by_async:
901 * @self: a #GTlsDatabase
902 * @issuer_raw_dn: a #GByteArray which holds the DER encoded issuer DN.
903 * @interaction: (allow-none): used to interact with the user if necessary
904 * @flags: Flags which affect the lookup operation.
905 * @cancellable: (allow-none): a #GCancellable, or %NULL
906 * @callback: callback to call when the operation completes
907 * @user_data: the data to pass to the callback function
909 * Asynchronously lookup certificates issued by this issuer in the database. See
910 * g_tls_database_lookup_certificates_issued_by() for more information.
912 * The database may choose to hold a reference to the issuer byte array for the duration
913 * of of this asynchronous operation. The byte array should not be modified during
914 * this time.
916 * Since: 2.30
918 void
919 g_tls_database_lookup_certificates_issued_by_async (GTlsDatabase *self,
920 GByteArray *issuer_raw_dn,
921 GTlsInteraction *interaction,
922 GTlsDatabaseLookupFlags flags,
923 GCancellable *cancellable,
924 GAsyncReadyCallback callback,
925 gpointer user_data)
927 g_return_if_fail (G_IS_TLS_DATABASE (self));
928 g_return_if_fail (issuer_raw_dn != NULL);
929 g_return_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction));
930 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
931 g_return_if_fail (callback != NULL);
932 g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_issued_by_async);
933 G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_issued_by_async (self,
934 issuer_raw_dn,
935 interaction,
936 flags,
937 cancellable,
938 callback,
939 user_data);
943 * g_tls_database_lookup_certificates_issued_by_finish:
944 * @self: a #GTlsDatabase
945 * @result: a #GAsyncResult.
946 * @error: a #GError pointer, or %NULL
948 * Finish an asynchronous lookup of certificates. See
949 * g_tls_database_lookup_certificates_issued_by() for more information.
951 * Return value: (transfer full): a newly allocated list of #GTlsCertificate objects.
952 * Use g_object_unref() on each certificate, and g_list_free() on the release the list.
954 * Since: 2.30
956 GList*
957 g_tls_database_lookup_certificates_issued_by_finish (GTlsDatabase *self,
958 GAsyncResult *result,
959 GError **error)
961 g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
962 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
963 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
964 g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_issued_by_finish, NULL);
965 return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_issued_by_finish (self,
966 result,
967 error);