summaryrefslogtreecommitdiff
path: root/gio/src/tlsconnection.hg
blob: c76c5dc1d2f08138d590aa26b14c8661f48eebce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Copyright (C) 2013 The giomm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

_CONFIGINCLUDE(giommconfig.h)

#include <giomm/iostream.h>
#include <giomm/tlscertificate.h>
#include <giomm/asyncresult.h>

_DEFS(giomm,gio)
_PINCLUDE(giomm/private/iostream_p.h)

namespace Gio
{
_WRAP_ENUM(TlsProtocolVersion, GTlsProtocolVersion, decl_prefix GIOMM_API)

class GIOMM_API Cancellable;
class GIOMM_API TlsDatabase;
class GIOMM_API TlsInteraction;

/** TLS connection type.
 * %TlsConnection is the base TLS connection class type, which wraps an IOStream
 * and provides TLS encryption on top of it. Its subclasses that implement
 * TlsClientConnection and TlsServerConnection, implement client-side and
 * server-side TLS, respectively.
 * @newin{2,36}
 */
class GIOMM_API TlsConnection : public IOStream
{
  _CLASS_GOBJECT(TlsConnection, GTlsConnection, G_TLS_CONNECTION, IOStream, GIOStream, , , GIOMM_API)
  _CUSTOM_WRAP_NEW

protected:
  _CTOR_DEFAULT

public:
  _WRAP_METHOD(void set_certificate(const Glib::RefPtr<TlsCertificate>& certificate), g_tls_connection_set_certificate)

  _WRAP_METHOD(Glib::RefPtr<TlsCertificate> get_certificate(), g_tls_connection_get_certificate, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const TlsCertificate> get_certificate() const, g_tls_connection_get_certificate, constversion)

  _WRAP_METHOD(Glib::RefPtr<TlsCertificate> get_peer_certificate(), g_tls_connection_get_peer_certificate, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const TlsCertificate> get_peer_certificate() const, g_tls_connection_get_peer_certificate, constversion)

  _WRAP_METHOD(TlsCertificateFlags get_peer_certificate_errors() const, g_tls_connection_get_peer_certificate_errors)

  _WRAP_METHOD(void set_require_close_notify(bool require_close_notify = true), g_tls_connection_set_require_close_notify)
  _WRAP_METHOD(bool get_require_close_notify() const, g_tls_connection_get_require_close_notify)

  _IGNORE(g_tls_connection_set_use_system_certdb, g_tls_connection_get_use_system_certdb)dnl // deprecated
  _IGNORE(g_tls_connection_set_rehandshake_mode, g_tls_connection_get_rehandshake_mode)dnl // deprecated

  _WRAP_METHOD(Glib::RefPtr<TlsDatabase> get_database(), g_tls_connection_get_database)
  _WRAP_METHOD(Glib::RefPtr<const TlsDatabase> get_database() const, g_tls_connection_get_database, constversion)

  _WRAP_METHOD(void set_database(const Glib::RefPtr<TlsDatabase>& database), g_tls_connection_set_database)

  _WRAP_METHOD(Glib::RefPtr<TlsInteraction> get_interaction(), g_tls_connection_get_interaction)
  _WRAP_METHOD(Glib::RefPtr<const TlsInteraction> get_interaction() const, g_tls_connection_get_interaction, constversion)

  _WRAP_METHOD(void set_interaction(const Glib::RefPtr<TlsInteraction>& interaction), g_tls_connection_set_interaction)

  _WRAP_METHOD(bool handshake(const Glib::RefPtr<Cancellable>& cancellable{?}), g_tls_connection_handshake, errthrow)

  _WRAP_METHOD(void handshake_async(const SlotAsyncReady& slot{callback}, const Glib::RefPtr<Cancellable>& cancellable{.?}, int io_priority{.} = Glib::PRIORITY_DEFAULT), g_tls_connection_handshake_async, slot_name slot, slot_callback SignalProxy_async_callback)
  _WRAP_METHOD(bool handshake_finish(const Glib::RefPtr<AsyncResult>& result), g_tls_connection_handshake_finish, errthrow)

  _WRAP_METHOD(TlsProtocolVersion get_protocol_version() const, g_tls_connection_get_protocol_version)
  _WRAP_METHOD(Glib::ustring get_ciphersuite_name() const, g_tls_connection_get_ciphersuite_name)

  _WRAP_METHOD(bool emit_accept_certificate(const Glib::RefPtr<const TlsCertificate>& peer_cert, TlsCertificateFlags errors), g_tls_connection_emit_accept_certificate)

  _WRAP_PROPERTY("base-io-stream", Glib::RefPtr<IOStream>)
  _WRAP_PROPERTY("certificate", Glib::RefPtr<TlsCertificate>)
  _WRAP_PROPERTY("database", Glib::RefPtr<TlsDatabase>)
  _WRAP_PROPERTY("interaction", Glib::RefPtr<TlsInteraction>)
  _WRAP_PROPERTY("peer-certificate", Glib::RefPtr<TlsCertificate>)
  _WRAP_PROPERTY("peer-certificate-errors", TlsCertificateFlags)
  _WRAP_PROPERTY("require-close-notify", bool)
  _WRAP_PROPERTY("protocol-version", TlsProtocolVersion)
  _WRAP_PROPERTY("ciphersuite-name", Glib::ustring)
  _IGNORE_PROPERTY("use-system-certdb", "rehandshake-mode")dnl // deprecated

#m4 _CONVERSION(`GTlsCertificate*',`const Glib::RefPtr<const TlsCertificate>&',`Glib::wrap($3, true)')
  _WRAP_SIGNAL(bool accept_certificate(const Glib::RefPtr<const TlsCertificate>& peer_cert, TlsCertificateFlags errors), "accept_certificate")

protected:
  _WRAP_VFUNC(bool handshake(const Glib::RefPtr<Cancellable>& cancellable), "handshake", errthrow)
  _WRAP_VFUNC(void handshake_async(const SlotAsyncReady& slot{callback}, const Glib::RefPtr<Cancellable>& cancellable{.}, int io_priority{.} = Glib::PRIORITY_DEFAULT), "handshake_async", slot_name slot, slot_callback SignalProxy_async_callback)

#m4 _CONVERSION(`GAsyncResult*',`const Glib::RefPtr<AsyncResult>&',`Glib::wrap($3, true)')
  _WRAP_VFUNC(bool handshake_finish(const Glib::RefPtr<AsyncResult>& result), "handshake_finish", errthrow)
};

} // namespace Gio