Blame gio/gdtlsconnection.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 *
Packit ae235b
 * Copyright © 2010 Red Hat, Inc
Packit ae235b
 * Copyright © 2015 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
Packit ae235b
#include "config.h"
Packit ae235b
#include "glib.h"
Packit ae235b
Packit ae235b
#include "gdtlsconnection.h"
Packit ae235b
#include "gcancellable.h"
Packit ae235b
#include "gioenumtypes.h"
Packit ae235b
#include "gsocket.h"
Packit ae235b
#include "gtlsbackend.h"
Packit ae235b
#include "gtlscertificate.h"
Packit ae235b
#include "gdtlsclientconnection.h"
Packit ae235b
#include "gtlsdatabase.h"
Packit ae235b
#include "gtlsinteraction.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gdtlsconnection
Packit ae235b
 * @short_description: DTLS connection type
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * #GDtlsConnection is the base DTLS connection class type, which wraps
Packit ae235b
 * a #GDatagramBased and provides DTLS encryption on top of it. Its
Packit ae235b
 * subclasses, #GDtlsClientConnection and #GDtlsServerConnection,
Packit ae235b
 * implement client-side and server-side DTLS, respectively.
Packit ae235b
 *
Packit ae235b
 * For TLS support, see #GTlsConnection.
Packit ae235b
 *
Packit ae235b
 * As DTLS is datagram based, #GDtlsConnection implements #GDatagramBased,
Packit ae235b
 * presenting a datagram-socket-like API for the encrypted connection. This
Packit ae235b
 * operates over a base datagram connection, which is also a #GDatagramBased
Packit ae235b
 * (#GDtlsConnection:base-socket).
Packit ae235b
 *
Packit ae235b
 * To close a DTLS connection, use g_dtls_connection_close().
Packit ae235b
 *
Packit ae235b
 * Neither #GDtlsServerConnection or #GDtlsClientConnection set the peer address
Packit ae235b
 * on their base #GDatagramBased if it is a #GSocket — it is up to the caller to
Packit ae235b
 * do that if they wish. If they do not, and g_socket_close() is called on the
Packit ae235b
 * base socket, the #GDtlsConnection will not raise a %G_IO_ERROR_NOT_CONNECTED
Packit ae235b
 * error on further I/O.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GDtlsConnection:
Packit ae235b
 *
Packit ae235b
 * Abstract base class for the backend-specific #GDtlsClientConnection
Packit ae235b
 * and #GDtlsServerConnection types.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
Packit ae235b
G_DEFINE_INTERFACE (GDtlsConnection, g_dtls_connection, G_TYPE_DATAGRAM_BASED)
Packit ae235b
Packit ae235b
enum {
Packit ae235b
  ACCEPT_CERTIFICATE,
Packit ae235b
  LAST_SIGNAL
Packit ae235b
};
Packit ae235b
Packit ae235b
static guint signals[LAST_SIGNAL] = { 0 };
Packit ae235b
Packit ae235b
enum {
Packit ae235b
  PROP_BASE_SOCKET = 1,
Packit ae235b
  PROP_REQUIRE_CLOSE_NOTIFY,
Packit ae235b
  PROP_REHANDSHAKE_MODE,
Packit ae235b
  PROP_DATABASE,
Packit ae235b
  PROP_INTERACTION,
Packit ae235b
  PROP_CERTIFICATE,
Packit ae235b
  PROP_PEER_CERTIFICATE,
Packit ae235b
  PROP_PEER_CERTIFICATE_ERRORS,
Packit ae235b
};
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dtls_connection_default_init (GDtlsConnectionInterface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:base-socket:
Packit ae235b
   *
Packit ae235b
   * The #GDatagramBased that the connection wraps. Note that this may be any
Packit ae235b
   * implementation of #GDatagramBased, not just a #GSocket.
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_object ("base-socket",
Packit ae235b
                                                            P_("Base Socket"),
Packit ae235b
                                                            P_("The GDatagramBased that the connection wraps"),
Packit ae235b
                                                            G_TYPE_DATAGRAM_BASED,
Packit ae235b
                                                            G_PARAM_READWRITE |
Packit ae235b
                                                            G_PARAM_CONSTRUCT_ONLY |
Packit ae235b
                                                            G_PARAM_STATIC_STRINGS));
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:database:
Packit ae235b
   *
Packit ae235b
   * The certificate database to use when verifying this TLS connection.
Packit ae235b
   * If no certificate database is set, then the default database will be
Packit ae235b
   * used. See g_tls_backend_get_default_database().
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_object ("database",
Packit ae235b
                                                            P_("Database"),
Packit ae235b
                                                            P_("Certificate database to use for looking up or verifying certificates"),
Packit ae235b
                                                            G_TYPE_TLS_DATABASE,
Packit ae235b
                                                            G_PARAM_READWRITE |
Packit ae235b
                                                            G_PARAM_STATIC_STRINGS));
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:interaction:
Packit ae235b
   *
Packit ae235b
   * A #GTlsInteraction object to be used when the connection or certificate
Packit ae235b
   * database need to interact with the user. This will be used to prompt the
Packit ae235b
   * user for passwords where necessary.
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_object ("interaction",
Packit ae235b
                                                            P_("Interaction"),
Packit ae235b
                                                            P_("Optional object for user interaction"),
Packit ae235b
                                                            G_TYPE_TLS_INTERACTION,
Packit ae235b
                                                            G_PARAM_READWRITE |
Packit ae235b
                                                            G_PARAM_STATIC_STRINGS));
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:require-close-notify:
Packit ae235b
   *
Packit ae235b
   * Whether or not proper TLS close notification is required.
Packit ae235b
   * See g_dtls_connection_set_require_close_notify().
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_boolean ("require-close-notify",
Packit ae235b
                                                             P_("Require close notify"),
Packit ae235b
                                                             P_("Whether to require proper TLS close notification"),
Packit ae235b
                                                             TRUE,
Packit ae235b
                                                             G_PARAM_READWRITE |
Packit ae235b
                                                             G_PARAM_CONSTRUCT |
Packit ae235b
                                                             G_PARAM_STATIC_STRINGS));
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:rehandshake-mode:
Packit ae235b
   *
Packit ae235b
   * The rehandshaking mode. See
Packit ae235b
   * g_dtls_connection_set_rehandshake_mode().
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_enum ("rehandshake-mode",
Packit ae235b
                                                          P_("Rehandshake mode"),
Packit ae235b
                                                          P_("When to allow rehandshaking"),
Packit ae235b
                                                          G_TYPE_TLS_REHANDSHAKE_MODE,
Packit ae235b
                                                          G_TLS_REHANDSHAKE_NEVER,
Packit ae235b
                                                          G_PARAM_READWRITE |
Packit ae235b
                                                          G_PARAM_CONSTRUCT |
Packit ae235b
                                                          G_PARAM_STATIC_STRINGS));
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:certificate:
Packit ae235b
   *
Packit ae235b
   * The connection's certificate; see
Packit ae235b
   * g_dtls_connection_set_certificate().
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_object ("certificate",
Packit ae235b
                                                            P_("Certificate"),
Packit ae235b
                                                            P_("The connection’s certificate"),
Packit ae235b
                                                            G_TYPE_TLS_CERTIFICATE,
Packit ae235b
                                                            G_PARAM_READWRITE |
Packit ae235b
                                                            G_PARAM_STATIC_STRINGS));
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:peer-certificate:
Packit ae235b
   *
Packit ae235b
   * The connection's peer's certificate, after the TLS handshake has
Packit ae235b
   * completed and the certificate has been accepted. Note in
Packit ae235b
   * particular that this is not yet set during the emission of
Packit ae235b
   * #GDtlsConnection::accept-certificate.
Packit ae235b
   *
Packit ae235b
   * (You can watch for a #GObject::notify signal on this property to
Packit ae235b
   * detect when a handshake has occurred.)
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_object ("peer-certificate",
Packit ae235b
                                                            P_("Peer Certificate"),
Packit ae235b
                                                            P_("The connection’s peer’s certificate"),
Packit ae235b
                                                            G_TYPE_TLS_CERTIFICATE,
Packit ae235b
                                                            G_PARAM_READABLE |
Packit ae235b
                                                            G_PARAM_STATIC_STRINGS));
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection:peer-certificate-errors:
Packit ae235b
   *
Packit ae235b
   * The errors noticed-and-ignored while verifying
Packit ae235b
   * #GDtlsConnection:peer-certificate. Normally this should be 0, but
Packit ae235b
   * it may not be if #GDtlsClientConnection:validation-flags is not
Packit ae235b
   * %G_TLS_CERTIFICATE_VALIDATE_ALL, or if
Packit ae235b
   * #GDtlsConnection::accept-certificate overrode the default
Packit ae235b
   * behavior.
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
                                       g_param_spec_flags ("peer-certificate-errors",
Packit ae235b
                                                           P_("Peer Certificate Errors"),
Packit ae235b
                                                           P_("Errors found with the peer’s certificate"),
Packit ae235b
                                                           G_TYPE_TLS_CERTIFICATE_FLAGS,
Packit ae235b
                                                           0,
Packit ae235b
                                                           G_PARAM_READABLE |
Packit ae235b
                                                           G_PARAM_STATIC_STRINGS));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDtlsConnection::accept-certificate:
Packit ae235b
   * @conn: a #GDtlsConnection
Packit ae235b
   * @peer_cert: the peer's #GTlsCertificate
Packit ae235b
   * @errors: the problems with @peer_cert.
Packit ae235b
   *
Packit ae235b
   * Emitted during the TLS handshake after the peer certificate has
Packit ae235b
   * been received. You can examine @peer_cert's certification path by
Packit ae235b
   * calling g_tls_certificate_get_issuer() on it.
Packit ae235b
   *
Packit ae235b
   * For a client-side connection, @peer_cert is the server's
Packit ae235b
   * certificate, and the signal will only be emitted if the
Packit ae235b
   * certificate was not acceptable according to @conn's
Packit ae235b
   * #GDtlsClientConnection:validation_flags. If you would like the
Packit ae235b
   * certificate to be accepted despite @errors, return %TRUE from the
Packit ae235b
   * signal handler. Otherwise, if no handler accepts the certificate,
Packit ae235b
   * the handshake will fail with %G_TLS_ERROR_BAD_CERTIFICATE.
Packit ae235b
   *
Packit ae235b
   * For a server-side connection, @peer_cert is the certificate
Packit ae235b
   * presented by the client, if this was requested via the server's
Packit ae235b
   * #GDtlsServerConnection:authentication_mode. On the server side,
Packit ae235b
   * the signal is always emitted when the client presents a
Packit ae235b
   * certificate, and the certificate will only be accepted if a
Packit ae235b
   * handler returns %TRUE.
Packit ae235b
   *
Packit ae235b
   * Note that if this signal is emitted as part of asynchronous I/O
Packit ae235b
   * in the main thread, then you should not attempt to interact with
Packit ae235b
   * the user before returning from the signal handler. If you want to
Packit ae235b
   * let the user decide whether or not to accept the certificate, you
Packit ae235b
   * would have to return %FALSE from the signal handler on the first
Packit ae235b
   * attempt, and then after the connection attempt returns a
Packit ae235b
   * %G_TLS_ERROR_HANDSHAKE, you can interact with the user, and if
Packit ae235b
   * the user decides to accept the certificate, remember that fact,
Packit ae235b
   * create a new connection, and return %TRUE from the signal handler
Packit ae235b
   * the next time.
Packit ae235b
   *
Packit ae235b
   * If you are doing I/O in another thread, you do not
Packit ae235b
   * need to worry about this, and can simply block in the signal
Packit ae235b
   * handler until the UI thread returns an answer.
Packit ae235b
   *
Packit ae235b
   * Returns: %TRUE to accept @peer_cert (which will also
Packit ae235b
   * immediately end the signal emission). %FALSE to allow the signal
Packit ae235b
   * emission to continue, which will cause the handshake to fail if
Packit ae235b
   * no one else overrides it.
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
Packit ae235b
   */
Packit ae235b
  signals[ACCEPT_CERTIFICATE] =
Packit ae235b
    g_signal_new (I_("accept-certificate"),
Packit ae235b
                  G_TYPE_DTLS_CONNECTION,
Packit ae235b
                  G_SIGNAL_RUN_LAST,
Packit ae235b
                  G_STRUCT_OFFSET (GDtlsConnectionInterface, accept_certificate),
Packit ae235b
                  g_signal_accumulator_true_handled, NULL,
Packit ae235b
                  NULL,
Packit ae235b
                  G_TYPE_BOOLEAN, 2,
Packit ae235b
                  G_TYPE_TLS_CERTIFICATE,
Packit ae235b
                  G_TYPE_TLS_CERTIFICATE_FLAGS);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_set_database:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @database: a #GTlsDatabase
Packit ae235b
 *
Packit ae235b
 * Sets the certificate database that is used to verify peer certificates.
Packit ae235b
 * This is set to the default database by default. See
Packit ae235b
 * g_tls_backend_get_default_database(). If set to %NULL, then
Packit ae235b
 * peer certificate validation will always set the
Packit ae235b
 * %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
Packit ae235b
 * #GDtlsConnection::accept-certificate will always be emitted on
Packit ae235b
 * client-side connections, unless that bit is not set in
Packit ae235b
 * #GDtlsClientConnection:validation-flags).
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_set_database (GDtlsConnection *conn,
Packit ae235b
                                GTlsDatabase    *database)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
  g_return_if_fail (database == NULL || G_IS_TLS_DATABASE (database));
Packit ae235b
Packit ae235b
  g_object_set (G_OBJECT (conn),
Packit ae235b
                "database", database,
Packit ae235b
                NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_get_database:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 *
Packit ae235b
 * Gets the certificate database that @conn uses to verify
Packit ae235b
 * peer certificates. See g_dtls_connection_set_database().
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): the certificate database that @conn uses or %NULL
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
GTlsDatabase*
Packit ae235b
g_dtls_connection_get_database (GDtlsConnection *conn)
Packit ae235b
{
Packit ae235b
  GTlsDatabase *database = NULL;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), NULL);
Packit ae235b
Packit ae235b
  g_object_get (G_OBJECT (conn),
Packit ae235b
                "database", &database,
Packit ae235b
                NULL);
Packit ae235b
  if (database)
Packit ae235b
    g_object_unref (database);
Packit ae235b
  return database;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_set_certificate:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @certificate: the certificate to use for @conn
Packit ae235b
 *
Packit ae235b
 * This sets the certificate that @conn will present to its peer
Packit ae235b
 * during the TLS handshake. For a #GDtlsServerConnection, it is
Packit ae235b
 * mandatory to set this, and that will normally be done at construct
Packit ae235b
 * time.
Packit ae235b
 *
Packit ae235b
 * For a #GDtlsClientConnection, this is optional. If a handshake fails
Packit ae235b
 * with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
Packit ae235b
 * requires a certificate, and if you try connecting again, you should
Packit ae235b
 * call this method first. You can call
Packit ae235b
 * g_dtls_client_connection_get_accepted_cas() on the failed connection
Packit ae235b
 * to get a list of Certificate Authorities that the server will
Packit ae235b
 * accept certificates from.
Packit ae235b
 *
Packit ae235b
 * (It is also possible that a server will allow the connection with
Packit ae235b
 * or without a certificate; in that case, if you don't provide a
Packit ae235b
 * certificate, you can tell that the server requested one by the fact
Packit ae235b
 * that g_dtls_client_connection_get_accepted_cas() will return
Packit ae235b
 * non-%NULL.)
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_set_certificate (GDtlsConnection *conn,
Packit ae235b
                                   GTlsCertificate *certificate)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
  g_return_if_fail (G_IS_TLS_CERTIFICATE (certificate));
Packit ae235b
Packit ae235b
  g_object_set (G_OBJECT (conn), "certificate", certificate, NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_get_certificate:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 *
Packit ae235b
 * Gets @conn's certificate, as set by
Packit ae235b
 * g_dtls_connection_set_certificate().
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): @conn's certificate, or %NULL
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
GTlsCertificate *
Packit ae235b
g_dtls_connection_get_certificate (GDtlsConnection *conn)
Packit ae235b
{
Packit ae235b
  GTlsCertificate *certificate;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), NULL);
Packit ae235b
Packit ae235b
  g_object_get (G_OBJECT (conn), "certificate", &certificate, NULL);
Packit ae235b
  if (certificate)
Packit ae235b
    g_object_unref (certificate);
Packit ae235b
Packit ae235b
  return certificate;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_set_interaction:
Packit ae235b
 * @conn: a connection
Packit ae235b
 * @interaction: (nullable): an interaction object, or %NULL
Packit ae235b
 *
Packit ae235b
 * Set the object that will be used to interact with the user. It will be used
Packit ae235b
 * for things like prompting the user for passwords.
Packit ae235b
 *
Packit ae235b
 * The @interaction argument will normally be a derived subclass of
Packit ae235b
 * #GTlsInteraction. %NULL can also be provided if no user interaction
Packit ae235b
 * should occur for this connection.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_set_interaction (GDtlsConnection *conn,
Packit ae235b
                                   GTlsInteraction *interaction)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
  g_return_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction));
Packit ae235b
Packit ae235b
  g_object_set (G_OBJECT (conn), "interaction", interaction, NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_get_interaction:
Packit ae235b
 * @conn: a connection
Packit ae235b
 *
Packit ae235b
 * Get the object that will be used to interact with the user. It will be used
Packit ae235b
 * for things like prompting the user for passwords. If %NULL is returned, then
Packit ae235b
 * no user interaction will occur for this connection.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): The interaction object.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
GTlsInteraction *
Packit ae235b
g_dtls_connection_get_interaction (GDtlsConnection       *conn)
Packit ae235b
{
Packit ae235b
  GTlsInteraction *interaction = NULL;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), NULL);
Packit ae235b
Packit ae235b
  g_object_get (G_OBJECT (conn), "interaction", &interaction, NULL);
Packit ae235b
  if (interaction)
Packit ae235b
    g_object_unref (interaction);
Packit ae235b
Packit ae235b
  return interaction;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_get_peer_certificate:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 *
Packit ae235b
 * Gets @conn's peer's certificate after the handshake has completed.
Packit ae235b
 * (It is not set during the emission of
Packit ae235b
 * #GDtlsConnection::accept-certificate.)
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): @conn's peer's certificate, or %NULL
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
GTlsCertificate *
Packit ae235b
g_dtls_connection_get_peer_certificate (GDtlsConnection *conn)
Packit ae235b
{
Packit ae235b
  GTlsCertificate *peer_certificate;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), NULL);
Packit ae235b
Packit ae235b
  g_object_get (G_OBJECT (conn), "peer-certificate", &peer_certificate, NULL);
Packit ae235b
  if (peer_certificate)
Packit ae235b
    g_object_unref (peer_certificate);
Packit ae235b
Packit ae235b
  return peer_certificate;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_get_peer_certificate_errors:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 *
Packit ae235b
 * Gets the errors associated with validating @conn's peer's
Packit ae235b
 * certificate, after the handshake has completed. (It is not set
Packit ae235b
 * during the emission of #GDtlsConnection::accept-certificate.)
Packit ae235b
 *
Packit ae235b
 * Returns: @conn's peer's certificate errors
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
GTlsCertificateFlags
Packit ae235b
g_dtls_connection_get_peer_certificate_errors (GDtlsConnection *conn)
Packit ae235b
{
Packit ae235b
  GTlsCertificateFlags errors;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), 0);
Packit ae235b
Packit ae235b
  g_object_get (G_OBJECT (conn), "peer-certificate-errors", &errors, NULL);
Packit ae235b
  return errors;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_set_require_close_notify:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @require_close_notify: whether or not to require close notification
Packit ae235b
 *
Packit ae235b
 * Sets whether or not @conn expects a proper TLS close notification
Packit ae235b
 * before the connection is closed. If this is %TRUE (the default),
Packit ae235b
 * then @conn will expect to receive a TLS close notification from its
Packit ae235b
 * peer before the connection is closed, and will return a
Packit ae235b
 * %G_TLS_ERROR_EOF error if the connection is closed without proper
Packit ae235b
 * notification (since this may indicate a network error, or
Packit ae235b
 * man-in-the-middle attack).
Packit ae235b
 *
Packit ae235b
 * In some protocols, the application will know whether or not the
Packit ae235b
 * connection was closed cleanly based on application-level data
Packit ae235b
 * (because the application-level data includes a length field, or is
Packit ae235b
 * somehow self-delimiting); in this case, the close notify is
Packit ae235b
 * redundant and may be omitted. You
Packit ae235b
 * can use g_dtls_connection_set_require_close_notify() to tell @conn
Packit ae235b
 * to allow an "unannounced" connection close, in which case the close
Packit ae235b
 * will show up as a 0-length read, as in a non-TLS
Packit ae235b
 * #GDatagramBased, and it is up to the application to check that
Packit ae235b
 * the data has been fully received.
Packit ae235b
 *
Packit ae235b
 * Note that this only affects the behavior when the peer closes the
Packit ae235b
 * connection; when the application calls g_dtls_connection_close_async() on
Packit ae235b
 * @conn itself, this will send a close notification regardless of the
Packit ae235b
 * setting of this property. If you explicitly want to do an unclean
Packit ae235b
 * close, you can close @conn's #GDtlsConnection:base-socket rather
Packit ae235b
 * than closing @conn itself.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_set_require_close_notify (GDtlsConnection *conn,
Packit ae235b
                                            gboolean         require_close_notify)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
Packit ae235b
  g_object_set (G_OBJECT (conn),
Packit ae235b
                "require-close-notify", require_close_notify,
Packit ae235b
                NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_get_require_close_notify:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 *
Packit ae235b
 * Tests whether or not @conn expects a proper TLS close notification
Packit ae235b
 * when the connection is closed. See
Packit ae235b
 * g_dtls_connection_set_require_close_notify() for details.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @conn requires a proper TLS close notification.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_get_require_close_notify (GDtlsConnection *conn)
Packit ae235b
{
Packit ae235b
  gboolean require_close_notify;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), TRUE);
Packit ae235b
Packit ae235b
  g_object_get (G_OBJECT (conn),
Packit ae235b
                "require-close-notify", &require_close_notify,
Packit ae235b
                NULL);
Packit ae235b
  return require_close_notify;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_set_rehandshake_mode:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @mode: the rehandshaking mode
Packit ae235b
 *
Packit ae235b
 * Sets how @conn behaves with respect to rehandshaking requests.
Packit ae235b
 *
Packit ae235b
 * %G_TLS_REHANDSHAKE_NEVER means that it will never agree to
Packit ae235b
 * rehandshake after the initial handshake is complete. (For a client,
Packit ae235b
 * this means it will refuse rehandshake requests from the server, and
Packit ae235b
 * for a server, this means it will close the connection with an error
Packit ae235b
 * if the client attempts to rehandshake.)
Packit ae235b
 *
Packit ae235b
 * %G_TLS_REHANDSHAKE_SAFELY means that the connection will allow a
Packit ae235b
 * rehandshake only if the other end of the connection supports the
Packit ae235b
 * TLS `renegotiation_info` extension. This is the default behavior,
Packit ae235b
 * but means that rehandshaking will not work against older
Packit ae235b
 * implementations that do not support that extension.
Packit ae235b
 *
Packit ae235b
 * %G_TLS_REHANDSHAKE_UNSAFELY means that the connection will allow
Packit ae235b
 * rehandshaking even without the `renegotiation_info` extension. On
Packit ae235b
 * the server side in particular, this is not recommended, since it
Packit ae235b
 * leaves the server open to certain attacks. However, this mode is
Packit ae235b
 * necessary if you need to allow renegotiation with older client
Packit ae235b
 * software.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_set_rehandshake_mode (GDtlsConnection     *conn,
Packit ae235b
                                        GTlsRehandshakeMode  mode)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
Packit ae235b
  g_object_set (G_OBJECT (conn),
Packit ae235b
                "rehandshake-mode", mode,
Packit ae235b
                NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_get_rehandshake_mode:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 *
Packit ae235b
 * Gets @conn rehandshaking mode. See
Packit ae235b
 * g_dtls_connection_set_rehandshake_mode() for details.
Packit ae235b
 *
Packit ae235b
 * Returns: @conn's rehandshaking mode
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
GTlsRehandshakeMode
Packit ae235b
g_dtls_connection_get_rehandshake_mode (GDtlsConnection       *conn)
Packit ae235b
{
Packit ae235b
  GTlsRehandshakeMode mode;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), G_TLS_REHANDSHAKE_NEVER);
Packit ae235b
Packit ae235b
  g_object_get (G_OBJECT (conn),
Packit ae235b
                "rehandshake-mode", &mode,
Packit ae235b
                NULL);
Packit ae235b
  return mode;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_handshake:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @cancellable: (nullable): a #GCancellable, or %NULL
Packit ae235b
 * @error: a #GError, or %NULL
Packit ae235b
 *
Packit ae235b
 * Attempts a TLS handshake on @conn.
Packit ae235b
 *
Packit ae235b
 * On the client side, it is never necessary to call this method;
Packit ae235b
 * although the connection needs to perform a handshake after
Packit ae235b
 * connecting (or after sending a "STARTTLS"-type command) and may
Packit ae235b
 * need to rehandshake later if the server requests it,
Packit ae235b
 * #GDtlsConnection will handle this for you automatically when you try
Packit ae235b
 * to send or receive data on the connection. However, you can call
Packit ae235b
 * g_dtls_connection_handshake() manually if you want to know for sure
Packit ae235b
 * whether the initial handshake succeeded or failed (as opposed to
Packit ae235b
 * just immediately trying to write to @conn, in which
Packit ae235b
 * case if it fails, it may not be possible to tell if it failed
Packit ae235b
 * before or after completing the handshake).
Packit ae235b
 *
Packit ae235b
 * Likewise, on the server side, although a handshake is necessary at
Packit ae235b
 * the beginning of the communication, you do not need to call this
Packit ae235b
 * function explicitly unless you want clearer error reporting.
Packit ae235b
 * However, you may call g_dtls_connection_handshake() later on to
Packit ae235b
 * renegotiate parameters (encryption methods, etc) with the client.
Packit ae235b
 *
Packit ae235b
 * #GDtlsConnection::accept_certificate may be emitted during the
Packit ae235b
 * handshake.
Packit ae235b
 *
Packit ae235b
 * Returns: success or failure
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_handshake (GDtlsConnection  *conn,
Packit ae235b
                             GCancellable     *cancellable,
Packit ae235b
                             GError          **error)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), FALSE);
Packit ae235b
Packit ae235b
  return G_DTLS_CONNECTION_GET_INTERFACE (conn)->handshake (conn, cancellable,
Packit ae235b
                                                            error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_handshake_async:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @io_priority: the [I/O priority][io-priority] of the request
Packit ae235b
 * @cancellable: (nullable): a #GCancellable, or %NULL
Packit ae235b
 * @callback: callback to call when the handshake is complete
Packit ae235b
 * @user_data: the data to pass to the callback function
Packit ae235b
 *
Packit ae235b
 * Asynchronously performs a TLS handshake on @conn. See
Packit ae235b
 * g_dtls_connection_handshake() for more information.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_handshake_async (GDtlsConnection      *conn,
Packit ae235b
                                   int                   io_priority,
Packit ae235b
                                   GCancellable         *cancellable,
Packit ae235b
                                   GAsyncReadyCallback   callback,
Packit ae235b
                                   gpointer              user_data)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
Packit ae235b
  G_DTLS_CONNECTION_GET_INTERFACE (conn)->handshake_async (conn, io_priority,
Packit ae235b
                                                           cancellable,
Packit ae235b
                                                           callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_handshake_finish:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @result: a #GAsyncResult.
Packit ae235b
 * @error: a #GError pointer, or %NULL
Packit ae235b
 *
Packit ae235b
 * Finish an asynchronous TLS handshake operation. See
Packit ae235b
 * g_dtls_connection_handshake() for more information.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE on failure, in which
Packit ae235b
 * case @error will be set.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_handshake_finish (GDtlsConnection  *conn,
Packit ae235b
                                    GAsyncResult     *result,
Packit ae235b
                                    GError          **error)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), FALSE);
Packit ae235b
Packit ae235b
  return G_DTLS_CONNECTION_GET_INTERFACE (conn)->handshake_finish (conn,
Packit ae235b
                                                                   result,
Packit ae235b
                                                                   error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_shutdown:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @shutdown_read: %TRUE to stop reception of incoming datagrams
Packit ae235b
 * @shutdown_write: %TRUE to stop sending outgoing datagrams
Packit ae235b
 * @cancellable: (nullable): a #GCancellable, or %NULL
Packit ae235b
 * @error: a #GError, or %NULL
Packit ae235b
 *
Packit ae235b
 * Shut down part or all of a DTLS connection.
Packit ae235b
 *
Packit ae235b
 * If @shutdown_read is %TRUE then the receiving side of the connection is shut
Packit ae235b
 * down, and further reading is disallowed. Subsequent calls to
Packit ae235b
 * g_datagram_based_receive_messages() will return %G_IO_ERROR_CLOSED.
Packit ae235b
 *
Packit ae235b
 * If @shutdown_write is %TRUE then the sending side of the connection is shut
Packit ae235b
 * down, and further writing is disallowed. Subsequent calls to
Packit ae235b
 * g_datagram_based_send_messages() will return %G_IO_ERROR_CLOSED.
Packit ae235b
 *
Packit ae235b
 * It is allowed for both @shutdown_read and @shutdown_write to be TRUE — this
Packit ae235b
 * is equivalent to calling g_dtls_connection_close().
Packit ae235b
 *
Packit ae235b
 * If @cancellable is cancelled, the #GDtlsConnection may be left
Packit ae235b
 * partially-closed and any pending untransmitted data may be lost. Call
Packit ae235b
 * g_dtls_connection_shutdown() again to complete closing the #GDtlsConnection.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE otherwise
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_shutdown (GDtlsConnection  *conn,
Packit ae235b
                            gboolean          shutdown_read,
Packit ae235b
                            gboolean          shutdown_write,
Packit ae235b
                            GCancellable     *cancellable,
Packit ae235b
                            GError          **error)
Packit ae235b
{
Packit ae235b
  GDtlsConnectionInterface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), FALSE);
Packit ae235b
  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable),
Packit ae235b
                        FALSE);
Packit ae235b
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
Packit ae235b
Packit ae235b
  if (!shutdown_read && !shutdown_write)
Packit ae235b
    return TRUE;
Packit ae235b
Packit ae235b
  iface = G_DTLS_CONNECTION_GET_INTERFACE (conn);
Packit ae235b
  g_assert (iface->shutdown != NULL);
Packit ae235b
Packit ae235b
  return iface->shutdown (conn, shutdown_read, shutdown_write,
Packit ae235b
                          cancellable, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_shutdown_async:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @shutdown_read: %TRUE to stop reception of incoming datagrams
Packit ae235b
 * @shutdown_write: %TRUE to stop sending outgoing datagrams
Packit ae235b
 * @io_priority: the [I/O priority][io-priority] of the request
Packit ae235b
 * @cancellable: (nullable): a #GCancellable, or %NULL
Packit ae235b
 * @callback: callback to call when the shutdown operation is complete
Packit ae235b
 * @user_data: the data to pass to the callback function
Packit ae235b
 *
Packit ae235b
 * Asynchronously shut down part or all of the DTLS connection. See
Packit ae235b
 * g_dtls_connection_shutdown() for more information.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_shutdown_async (GDtlsConnection      *conn,
Packit ae235b
                                  gboolean              shutdown_read,
Packit ae235b
                                  gboolean              shutdown_write,
Packit ae235b
                                  int                   io_priority,
Packit ae235b
                                  GCancellable         *cancellable,
Packit ae235b
                                  GAsyncReadyCallback   callback,
Packit ae235b
                                  gpointer              user_data)
Packit ae235b
{
Packit ae235b
  GDtlsConnectionInterface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
Packit ae235b
Packit ae235b
  iface = G_DTLS_CONNECTION_GET_INTERFACE (conn);
Packit ae235b
  g_assert (iface->shutdown_async != NULL);
Packit ae235b
Packit ae235b
  iface->shutdown_async (conn, TRUE, TRUE, io_priority, cancellable,
Packit ae235b
                         callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_shutdown_finish:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @result: a #GAsyncResult
Packit ae235b
 * @error: a #GError pointer, or %NULL
Packit ae235b
 *
Packit ae235b
 * Finish an asynchronous TLS shutdown operation. See
Packit ae235b
 * g_dtls_connection_shutdown() for more information.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE on failure, in which
Packit ae235b
 * case @error will be set
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_shutdown_finish (GDtlsConnection  *conn,
Packit ae235b
                                   GAsyncResult     *result,
Packit ae235b
                                   GError          **error)
Packit ae235b
{
Packit ae235b
  GDtlsConnectionInterface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), FALSE);
Packit ae235b
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
Packit ae235b
Packit ae235b
  iface = G_DTLS_CONNECTION_GET_INTERFACE (conn);
Packit ae235b
  g_assert (iface->shutdown_finish != NULL);
Packit ae235b
Packit ae235b
  return iface->shutdown_finish (conn, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_close:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @cancellable: (nullable): a #GCancellable, or %NULL
Packit ae235b
 * @error: a #GError, or %NULL
Packit ae235b
 *
Packit ae235b
 * Close the DTLS connection. This is equivalent to calling
Packit ae235b
 * g_dtls_connection_shutdown() to shut down both sides of the connection.
Packit ae235b
 *
Packit ae235b
 * Closing a #GDtlsConnection waits for all buffered but untransmitted data to
Packit ae235b
 * be sent before it completes. It then sends a `close_notify` DTLS alert to the
Packit ae235b
 * peer and may wait for a `close_notify` to be received from the peer. It does
Packit ae235b
 * not close the underlying #GDtlsConnection:base-socket; that must be closed
Packit ae235b
 * separately.
Packit ae235b
 *
Packit ae235b
 * Once @conn is closed, all other operations will return %G_IO_ERROR_CLOSED.
Packit ae235b
 * Closing a #GDtlsConnection multiple times will not return an error.
Packit ae235b
 *
Packit ae235b
 * #GDtlsConnections will be automatically closed when the last reference is
Packit ae235b
 * dropped, but you might want to call this function to make sure resources are
Packit ae235b
 * released as early as possible.
Packit ae235b
 *
Packit ae235b
 * If @cancellable is cancelled, the #GDtlsConnection may be left
Packit ae235b
 * partially-closed and any pending untransmitted data may be lost. Call
Packit ae235b
 * g_dtls_connection_close() again to complete closing the #GDtlsConnection.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE otherwise
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_close (GDtlsConnection  *conn,
Packit ae235b
                         GCancellable     *cancellable,
Packit ae235b
                         GError          **error)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), FALSE);
Packit ae235b
  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable),
Packit ae235b
                        FALSE);
Packit ae235b
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
Packit ae235b
Packit ae235b
  return G_DTLS_CONNECTION_GET_INTERFACE (conn)->shutdown (conn, TRUE, TRUE,
Packit ae235b
                                                           cancellable, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_close_async:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @io_priority: the [I/O priority][io-priority] of the request
Packit ae235b
 * @cancellable: (nullable): a #GCancellable, or %NULL
Packit ae235b
 * @callback: callback to call when the close operation is complete
Packit ae235b
 * @user_data: the data to pass to the callback function
Packit ae235b
 *
Packit ae235b
 * Asynchronously close the DTLS connection. See g_dtls_connection_close() for
Packit ae235b
 * more information.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dtls_connection_close_async (GDtlsConnection      *conn,
Packit ae235b
                               int                   io_priority,
Packit ae235b
                               GCancellable         *cancellable,
Packit ae235b
                               GAsyncReadyCallback   callback,
Packit ae235b
                               gpointer              user_data)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DTLS_CONNECTION (conn));
Packit ae235b
  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
Packit ae235b
Packit ae235b
  G_DTLS_CONNECTION_GET_INTERFACE (conn)->shutdown_async (conn, TRUE, TRUE,
Packit ae235b
                                                          io_priority,
Packit ae235b
                                                          cancellable,
Packit ae235b
                                                          callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_close_finish:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @result: a #GAsyncResult
Packit ae235b
 * @error: a #GError pointer, or %NULL
Packit ae235b
 *
Packit ae235b
 * Finish an asynchronous TLS close operation. See g_dtls_connection_close()
Packit ae235b
 * for more information.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE on failure, in which
Packit ae235b
 * case @error will be set
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_close_finish (GDtlsConnection  *conn,
Packit ae235b
                                GAsyncResult     *result,
Packit ae235b
                                GError          **error)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), FALSE);
Packit ae235b
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
Packit ae235b
Packit ae235b
  return G_DTLS_CONNECTION_GET_INTERFACE (conn)->shutdown_finish (conn, result,
Packit ae235b
                                                                  error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dtls_connection_emit_accept_certificate:
Packit ae235b
 * @conn: a #GDtlsConnection
Packit ae235b
 * @peer_cert: the peer's #GTlsCertificate
Packit ae235b
 * @errors: the problems with @peer_cert
Packit ae235b
 *
Packit ae235b
 * Used by #GDtlsConnection implementations to emit the
Packit ae235b
 * #GDtlsConnection::accept-certificate signal.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if one of the signal handlers has returned
Packit ae235b
 *     %TRUE to accept @peer_cert
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dtls_connection_emit_accept_certificate (GDtlsConnection      *conn,
Packit ae235b
                                           GTlsCertificate      *peer_cert,
Packit ae235b
                                           GTlsCertificateFlags  errors)
Packit ae235b
{
Packit ae235b
  gboolean accept = FALSE;
Packit ae235b
Packit ae235b
  g_signal_emit (conn, signals[ACCEPT_CERTIFICATE], 0,
Packit ae235b
                 peer_cert, errors, &accept);
Packit ae235b
  return accept;
Packit ae235b
}