Blame gio/gtlsfiledatabase.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 *
Packit ae235b
 * Copyright © 2010 Collabora, Ltd
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Stef Walter <stefw@collabora.co.uk>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "gtlsfiledatabase.h"
Packit ae235b
Packit ae235b
#include "ginitable.h"
Packit ae235b
#include "gtlsbackend.h"
Packit ae235b
#include "gtlsdatabase.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gtlsfiledatabase
Packit ae235b
 * @short_description: TLS file based database type
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * #GTlsFileDatabase is implemented by #GTlsDatabase objects which load
Packit ae235b
 * their certificate information from a file. It is an interface which
Packit ae235b
 * TLS library specific subtypes implement.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GTlsFileDatabase:
Packit ae235b
 *
Packit ae235b
 * Implemented by a #GTlsDatabase which allows you to load certificates
Packit ae235b
 * from a file.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
G_DEFINE_INTERFACE (GTlsFileDatabase, g_tls_file_database, G_TYPE_TLS_DATABASE)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_tls_file_database_default_init (GTlsFileDatabaseInterface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GTlsFileDatabase:anchors:
Packit ae235b
   *
Packit ae235b
   * The path to a file containing PEM encoded certificate authority
Packit ae235b
   * root anchors. The certificates in this file will be treated as
Packit ae235b
   * root authorities for the purpose of verifying other certificates
Packit ae235b
   * via the g_tls_database_verify_chain() operation.
Packit ae235b
   *
Packit ae235b
   * Since: 2.30
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_string ("anchors",
Packit ae235b
                                                           P_("Anchors"),
Packit ae235b
                                                           P_("The certificate authority anchor file"),
Packit ae235b
                                                           NULL,
Packit ae235b
                                                           G_PARAM_READWRITE |
Packit ae235b
                                                           G_PARAM_CONSTRUCT |
Packit ae235b
                                                           G_PARAM_STATIC_STRINGS));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_tls_file_database_new:
Packit ae235b
 * @anchors: (type filename): filename of anchor certificate authorities.
Packit ae235b
 * @error: #GError for error reporting, or %NULL to ignore.
Packit ae235b
 *
Packit ae235b
 * Creates a new #GTlsFileDatabase which uses anchor certificate authorities
Packit ae235b
 * in @anchors to verify certificate chains.
Packit ae235b
 *
Packit ae235b
 * The certificates in @anchors must be PEM encoded.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (type GTlsFileDatabase): the new
Packit ae235b
 * #GTlsFileDatabase, or %NULL on error
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GTlsDatabase*
Packit ae235b
g_tls_file_database_new (const gchar     *anchors,
Packit ae235b
                         GError         **error)
Packit ae235b
{
Packit ae235b
  GObject *database;
Packit ae235b
  GTlsBackend *backend;
Packit ae235b
Packit ae235b
  backend = g_tls_backend_get_default ();
Packit ae235b
  database = g_initable_new (g_tls_backend_get_file_database_type (backend),
Packit ae235b
                             NULL, error,
Packit ae235b
                             "anchors", anchors,
Packit ae235b
                             NULL);
Packit ae235b
  return G_TLS_DATABASE (database);
Packit ae235b
}