/src/glib/gio/gtlsfiledatabase.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GIO - GLib Input, Output and Streaming Library |
2 | | * |
3 | | * Copyright © 2010 Collabora, Ltd |
4 | | * |
5 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
6 | | * |
7 | | * This library is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * This library is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General |
18 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 | | * |
20 | | * Author: Stef Walter <stefw@collabora.co.uk> |
21 | | */ |
22 | | |
23 | | #include "config.h" |
24 | | |
25 | | #include "gtlsfiledatabase.h" |
26 | | |
27 | | #include "ginitable.h" |
28 | | #include "gtlsbackend.h" |
29 | | #include "gtlsdatabase.h" |
30 | | #include "glibintl.h" |
31 | | |
32 | | /** |
33 | | * SECTION:gtlsfiledatabase |
34 | | * @short_description: TLS file based database type |
35 | | * @include: gio/gio.h |
36 | | * |
37 | | * #GTlsFileDatabase is implemented by #GTlsDatabase objects which load |
38 | | * their certificate information from a file. It is an interface which |
39 | | * TLS library specific subtypes implement. |
40 | | * |
41 | | * Since: 2.30 |
42 | | */ |
43 | | |
44 | | /** |
45 | | * GTlsFileDatabase: |
46 | | * |
47 | | * Implemented by a #GTlsDatabase which allows you to load certificates |
48 | | * from a file. |
49 | | * |
50 | | * Since: 2.30 |
51 | | */ |
52 | | G_DEFINE_INTERFACE (GTlsFileDatabase, g_tls_file_database, G_TYPE_TLS_DATABASE) |
53 | | |
54 | | static void |
55 | | g_tls_file_database_default_init (GTlsFileDatabaseInterface *iface) |
56 | 0 | { |
57 | | /** |
58 | | * GTlsFileDatabase:anchors: |
59 | | * |
60 | | * The path to a file containing PEM encoded certificate authority |
61 | | * root anchors. The certificates in this file will be treated as |
62 | | * root authorities for the purpose of verifying other certificates |
63 | | * via the g_tls_database_verify_chain() operation. |
64 | | * |
65 | | * Since: 2.30 |
66 | | */ |
67 | 0 | g_object_interface_install_property (iface, |
68 | 0 | g_param_spec_string ("anchors", |
69 | 0 | P_("Anchors"), |
70 | 0 | P_("The certificate authority anchor file"), |
71 | 0 | NULL, |
72 | 0 | G_PARAM_READWRITE | |
73 | 0 | G_PARAM_CONSTRUCT | |
74 | 0 | G_PARAM_STATIC_STRINGS)); |
75 | 0 | } |
76 | | |
77 | | /** |
78 | | * g_tls_file_database_new: |
79 | | * @anchors: (type filename): filename of anchor certificate authorities. |
80 | | * @error: #GError for error reporting, or %NULL to ignore. |
81 | | * |
82 | | * Creates a new #GTlsFileDatabase which uses anchor certificate authorities |
83 | | * in @anchors to verify certificate chains. |
84 | | * |
85 | | * The certificates in @anchors must be PEM encoded. |
86 | | * |
87 | | * Returns: (transfer full) (type GTlsFileDatabase): the new |
88 | | * #GTlsFileDatabase, or %NULL on error |
89 | | * |
90 | | * Since: 2.30 |
91 | | */ |
92 | | GTlsDatabase* |
93 | | g_tls_file_database_new (const gchar *anchors, |
94 | | GError **error) |
95 | 0 | { |
96 | 0 | GObject *database; |
97 | 0 | GTlsBackend *backend; |
98 | |
|
99 | 0 | backend = g_tls_backend_get_default (); |
100 | 0 | database = g_initable_new (g_tls_backend_get_file_database_type (backend), |
101 | 0 | NULL, error, |
102 | 0 | "anchors", anchors, |
103 | 0 | NULL); |
104 | 0 | return G_TLS_DATABASE (database); |
105 | 0 | } |