1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.DtlsConnectionIF;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.TlsCertificate;
30 private import gio.TlsDatabase;
31 private import gio.TlsInteraction;
32 private import glib.ErrorG;
33 private import glib.GException;
34 private import gobject.ObjectG;
35 private import gobject.Signals;
36 public  import gtkc.gdktypes;
37 private import gtkc.gio;
38 public  import gtkc.giotypes;
39 private import std.algorithm;
40 
41 
42 /**
43  * #GDtlsConnection is the base DTLS connection class type, which wraps
44  * a #GDatagramBased and provides DTLS encryption on top of it. Its
45  * subclasses, #GDtlsClientConnection and #GDtlsServerConnection,
46  * implement client-side and server-side DTLS, respectively.
47  * 
48  * For TLS support, see #GTlsConnection.
49  * 
50  * As DTLS is datagram based, #GDtlsConnection implements #GDatagramBased,
51  * presenting a datagram-socket-like API for the encrypted connection. This
52  * operates over a base datagram connection, which is also a #GDatagramBased
53  * (#GDtlsConnection:base-socket).
54  * 
55  * To close a DTLS connection, use g_dtls_connection_close().
56  * 
57  * Neither #GDtlsServerConnection or #GDtlsClientConnection set the peer address
58  * on their base #GDatagramBased if it is a #GSocket — it is up to the caller to
59  * do that if they wish. If they do not, and g_socket_close() is called on the
60  * base socket, the #GDtlsConnection will not raise a %G_IO_ERROR_NOT_CONNECTED
61  * error on further I/O.
62  *
63  * Since: 2.48
64  */
65 public interface DtlsConnectionIF{
66 	/** Get the main Gtk struct */
67 	public GDtlsConnection* getDtlsConnectionStruct();
68 
69 	/** the main Gtk struct as a void* */
70 	protected void* getStruct();
71 
72 
73 	/**
74 	 * Close the DTLS connection. This is equivalent to calling
75 	 * g_dtls_connection_shutdown() to shut down both sides of the connection.
76 	 *
77 	 * Closing a #GDtlsConnection waits for all buffered but untransmitted data to
78 	 * be sent before it completes. It then sends a `close_notify` DTLS alert to the
79 	 * peer and may wait for a `close_notify` to be received from the peer. It does
80 	 * not close the underlying #GDtlsConnection:base-socket; that must be closed
81 	 * separately.
82 	 *
83 	 * Once @conn is closed, all other operations will return %G_IO_ERROR_CLOSED.
84 	 * Closing a #GDtlsConnection multiple times will not return an error.
85 	 *
86 	 * #GDtlsConnections will be automatically closed when the last reference is
87 	 * dropped, but you might want to call this function to make sure resources are
88 	 * released as early as possible.
89 	 *
90 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
91 	 * partially-closed and any pending untransmitted data may be lost. Call
92 	 * g_dtls_connection_close() again to complete closing the #GDtlsConnection.
93 	 *
94 	 * Params:
95 	 *     cancellable = a #GCancellable, or %NULL
96 	 *
97 	 * Return: %TRUE on success, %FALSE otherwise
98 	 *
99 	 * Since: 2.48
100 	 *
101 	 * Throws: GException on failure.
102 	 */
103 	public bool close(Cancellable cancellable);
104 
105 	/**
106 	 * Asynchronously close the DTLS connection. See g_dtls_connection_close() for
107 	 * more information.
108 	 *
109 	 * Params:
110 	 *     ioPriority = the [I/O priority][io-priority] of the request
111 	 *     cancellable = a #GCancellable, or %NULL
112 	 *     callback = callback to call when the close operation is complete
113 	 *     userData = the data to pass to the callback function
114 	 *
115 	 * Since: 2.48
116 	 */
117 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
118 
119 	/**
120 	 * Finish an asynchronous TLS close operation. See g_dtls_connection_close()
121 	 * for more information.
122 	 *
123 	 * Params:
124 	 *     result = a #GAsyncResult
125 	 *
126 	 * Return: %TRUE on success, %FALSE on failure, in which
127 	 *     case @error will be set
128 	 *
129 	 * Since: 2.48
130 	 *
131 	 * Throws: GException on failure.
132 	 */
133 	public bool closeFinish(AsyncResultIF result);
134 
135 	/**
136 	 * Used by #GDtlsConnection implementations to emit the
137 	 * #GDtlsConnection::accept-certificate signal.
138 	 *
139 	 * Params:
140 	 *     peerCert = the peer's #GTlsCertificate
141 	 *     errors = the problems with @peer_cert
142 	 *
143 	 * Return: %TRUE if one of the signal handlers has returned
144 	 *     %TRUE to accept @peer_cert
145 	 *
146 	 * Since: 2.48
147 	 */
148 	public bool emitAcceptCertificate(TlsCertificate peerCert, GTlsCertificateFlags errors);
149 
150 	/**
151 	 * Gets @conn's certificate, as set by
152 	 * g_dtls_connection_set_certificate().
153 	 *
154 	 * Return: @conn's certificate, or %NULL
155 	 *
156 	 * Since: 2.48
157 	 */
158 	public TlsCertificate getCertificate();
159 
160 	/**
161 	 * Gets the certificate database that @conn uses to verify
162 	 * peer certificates. See g_dtls_connection_set_database().
163 	 *
164 	 * Return: the certificate database that @conn uses or %NULL
165 	 *
166 	 * Since: 2.48
167 	 */
168 	public TlsDatabase getDatabase();
169 
170 	/**
171 	 * Get the object that will be used to interact with the user. It will be used
172 	 * for things like prompting the user for passwords. If %NULL is returned, then
173 	 * no user interaction will occur for this connection.
174 	 *
175 	 * Return: The interaction object.
176 	 *
177 	 * Since: 2.48
178 	 */
179 	public TlsInteraction getInteraction();
180 
181 	/**
182 	 * Gets @conn's peer's certificate after the handshake has completed.
183 	 * (It is not set during the emission of
184 	 * #GDtlsConnection::accept-certificate.)
185 	 *
186 	 * Return: @conn's peer's certificate, or %NULL
187 	 *
188 	 * Since: 2.48
189 	 */
190 	public TlsCertificate getPeerCertificate();
191 
192 	/**
193 	 * Gets the errors associated with validating @conn's peer's
194 	 * certificate, after the handshake has completed. (It is not set
195 	 * during the emission of #GDtlsConnection::accept-certificate.)
196 	 *
197 	 * Return: @conn's peer's certificate errors
198 	 *
199 	 * Since: 2.48
200 	 */
201 	public GTlsCertificateFlags getPeerCertificateErrors();
202 
203 	/**
204 	 * Gets @conn rehandshaking mode. See
205 	 * g_dtls_connection_set_rehandshake_mode() for details.
206 	 *
207 	 * Return: @conn's rehandshaking mode
208 	 *
209 	 * Since: 2.48
210 	 */
211 	public GTlsRehandshakeMode getRehandshakeMode();
212 
213 	/**
214 	 * Tests whether or not @conn expects a proper TLS close notification
215 	 * when the connection is closed. See
216 	 * g_dtls_connection_set_require_close_notify() for details.
217 	 *
218 	 * Return: %TRUE if @conn requires a proper TLS close notification.
219 	 *
220 	 * Since: 2.48
221 	 */
222 	public bool getRequireCloseNotify();
223 
224 	/**
225 	 * Attempts a TLS handshake on @conn.
226 	 *
227 	 * On the client side, it is never necessary to call this method;
228 	 * although the connection needs to perform a handshake after
229 	 * connecting (or after sending a "STARTTLS"-type command) and may
230 	 * need to rehandshake later if the server requests it,
231 	 * #GDtlsConnection will handle this for you automatically when you try
232 	 * to send or receive data on the connection. However, you can call
233 	 * g_dtls_connection_handshake() manually if you want to know for sure
234 	 * whether the initial handshake succeeded or failed (as opposed to
235 	 * just immediately trying to write to @conn, in which
236 	 * case if it fails, it may not be possible to tell if it failed
237 	 * before or after completing the handshake).
238 	 *
239 	 * Likewise, on the server side, although a handshake is necessary at
240 	 * the beginning of the communication, you do not need to call this
241 	 * function explicitly unless you want clearer error reporting.
242 	 * However, you may call g_dtls_connection_handshake() later on to
243 	 * renegotiate parameters (encryption methods, etc) with the client.
244 	 *
245 	 * #GDtlsConnection::accept_certificate may be emitted during the
246 	 * handshake.
247 	 *
248 	 * Params:
249 	 *     cancellable = a #GCancellable, or %NULL
250 	 *
251 	 * Return: success or failure
252 	 *
253 	 * Since: 2.48
254 	 *
255 	 * Throws: GException on failure.
256 	 */
257 	public bool handshake(Cancellable cancellable);
258 
259 	/**
260 	 * Asynchronously performs a TLS handshake on @conn. See
261 	 * g_dtls_connection_handshake() for more information.
262 	 *
263 	 * Params:
264 	 *     ioPriority = the [I/O priority][io-priority] of the request
265 	 *     cancellable = a #GCancellable, or %NULL
266 	 *     callback = callback to call when the handshake is complete
267 	 *     userData = the data to pass to the callback function
268 	 *
269 	 * Since: 2.48
270 	 */
271 	public void handshakeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
272 
273 	/**
274 	 * Finish an asynchronous TLS handshake operation. See
275 	 * g_dtls_connection_handshake() for more information.
276 	 *
277 	 * Params:
278 	 *     result = a #GAsyncResult.
279 	 *
280 	 * Return: %TRUE on success, %FALSE on failure, in which
281 	 *     case @error will be set.
282 	 *
283 	 * Since: 2.48
284 	 *
285 	 * Throws: GException on failure.
286 	 */
287 	public bool handshakeFinish(AsyncResultIF result);
288 
289 	/**
290 	 * This sets the certificate that @conn will present to its peer
291 	 * during the TLS handshake. For a #GDtlsServerConnection, it is
292 	 * mandatory to set this, and that will normally be done at construct
293 	 * time.
294 	 *
295 	 * For a #GDtlsClientConnection, this is optional. If a handshake fails
296 	 * with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
297 	 * requires a certificate, and if you try connecting again, you should
298 	 * call this method first. You can call
299 	 * g_dtls_client_connection_get_accepted_cas() on the failed connection
300 	 * to get a list of Certificate Authorities that the server will
301 	 * accept certificates from.
302 	 *
303 	 * (It is also possible that a server will allow the connection with
304 	 * or without a certificate; in that case, if you don't provide a
305 	 * certificate, you can tell that the server requested one by the fact
306 	 * that g_dtls_client_connection_get_accepted_cas() will return
307 	 * non-%NULL.)
308 	 *
309 	 * Params:
310 	 *     certificate = the certificate to use for @conn
311 	 *
312 	 * Since: 2.48
313 	 */
314 	public void setCertificate(TlsCertificate certificate);
315 
316 	/**
317 	 * Sets the certificate database that is used to verify peer certificates.
318 	 * This is set to the default database by default. See
319 	 * g_dtls_backend_get_default_database(). If set to %NULL, then
320 	 * peer certificate validation will always set the
321 	 * %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
322 	 * #GDtlsConnection::accept-certificate will always be emitted on
323 	 * client-side connections, unless that bit is not set in
324 	 * #GDtlsClientConnection:validation-flags).
325 	 *
326 	 * Params:
327 	 *     database = a #GTlsDatabase
328 	 *
329 	 * Since: 2.48
330 	 */
331 	public void setDatabase(TlsDatabase database);
332 
333 	/**
334 	 * Set the object that will be used to interact with the user. It will be used
335 	 * for things like prompting the user for passwords.
336 	 *
337 	 * The @interaction argument will normally be a derived subclass of
338 	 * #GTlsInteraction. %NULL can also be provided if no user interaction
339 	 * should occur for this connection.
340 	 *
341 	 * Params:
342 	 *     interaction = an interaction object, or %NULL
343 	 *
344 	 * Since: 2.48
345 	 */
346 	public void setInteraction(TlsInteraction interaction);
347 
348 	/**
349 	 * Sets how @conn behaves with respect to rehandshaking requests.
350 	 *
351 	 * %G_TLS_REHANDSHAKE_NEVER means that it will never agree to
352 	 * rehandshake after the initial handshake is complete. (For a client,
353 	 * this means it will refuse rehandshake requests from the server, and
354 	 * for a server, this means it will close the connection with an error
355 	 * if the client attempts to rehandshake.)
356 	 *
357 	 * %G_TLS_REHANDSHAKE_SAFELY means that the connection will allow a
358 	 * rehandshake only if the other end of the connection supports the
359 	 * TLS `renegotiation_info` extension. This is the default behavior,
360 	 * but means that rehandshaking will not work against older
361 	 * implementations that do not support that extension.
362 	 *
363 	 * %G_TLS_REHANDSHAKE_UNSAFELY means that the connection will allow
364 	 * rehandshaking even without the `renegotiation_info` extension. On
365 	 * the server side in particular, this is not recommended, since it
366 	 * leaves the server open to certain attacks. However, this mode is
367 	 * necessary if you need to allow renegotiation with older client
368 	 * software.
369 	 *
370 	 * Params:
371 	 *     mode = the rehandshaking mode
372 	 *
373 	 * Since: 2.48
374 	 */
375 	public void setRehandshakeMode(GTlsRehandshakeMode mode);
376 
377 	/**
378 	 * Sets whether or not @conn expects a proper TLS close notification
379 	 * before the connection is closed. If this is %TRUE (the default),
380 	 * then @conn will expect to receive a TLS close notification from its
381 	 * peer before the connection is closed, and will return a
382 	 * %G_TLS_ERROR_EOF error if the connection is closed without proper
383 	 * notification (since this may indicate a network error, or
384 	 * man-in-the-middle attack).
385 	 *
386 	 * In some protocols, the application will know whether or not the
387 	 * connection was closed cleanly based on application-level data
388 	 * (because the application-level data includes a length field, or is
389 	 * somehow self-delimiting); in this case, the close notify is
390 	 * redundant and may be omitted. You
391 	 * can use g_dtls_connection_set_require_close_notify() to tell @conn
392 	 * to allow an "unannounced" connection close, in which case the close
393 	 * will show up as a 0-length read, as in a non-TLS
394 	 * #GDatagramBased, and it is up to the application to check that
395 	 * the data has been fully received.
396 	 *
397 	 * Note that this only affects the behavior when the peer closes the
398 	 * connection; when the application calls g_dtls_connection_close_async() on
399 	 * @conn itself, this will send a close notification regardless of the
400 	 * setting of this property. If you explicitly want to do an unclean
401 	 * close, you can close @conn's #GDtlsConnection:base-socket rather
402 	 * than closing @conn itself.
403 	 *
404 	 * Params:
405 	 *     requireCloseNotify = whether or not to require close notification
406 	 *
407 	 * Since: 2.48
408 	 */
409 	public void setRequireCloseNotify(bool requireCloseNotify);
410 
411 	/**
412 	 * Shut down part or all of a DTLS connection.
413 	 *
414 	 * If @shutdown_read is %TRUE then the receiving side of the connection is shut
415 	 * down, and further reading is disallowed. Subsequent calls to
416 	 * g_datagram_based_receive_messages() will return %G_IO_ERROR_CLOSED.
417 	 *
418 	 * If @shutdown_write is %TRUE then the sending side of the connection is shut
419 	 * down, and further writing is disallowed. Subsequent calls to
420 	 * g_datagram_based_send_messages() will return %G_IO_ERROR_CLOSED.
421 	 *
422 	 * It is allowed for both @shutdown_read and @shutdown_write to be TRUE — this
423 	 * is equivalent to calling g_dtls_connection_close().
424 	 *
425 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
426 	 * partially-closed and any pending untransmitted data may be lost. Call
427 	 * g_dtls_connection_shutdown() again to complete closing the #GDtlsConnection.
428 	 *
429 	 * Params:
430 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
431 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
432 	 *     cancellable = a #GCancellable, or %NULL
433 	 *
434 	 * Return: %TRUE on success, %FALSE otherwise
435 	 *
436 	 * Since: 2.48
437 	 *
438 	 * Throws: GException on failure.
439 	 */
440 	public bool shutdown(bool shutdownRead, bool shutdownWrite, Cancellable cancellable);
441 
442 	/**
443 	 * Asynchronously shut down part or all of the DTLS connection. See
444 	 * g_dtls_connection_shutdown() for more information.
445 	 *
446 	 * Params:
447 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
448 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
449 	 *     ioPriority = the [I/O priority][io-priority] of the request
450 	 *     cancellable = a #GCancellable, or %NULL
451 	 *     callback = callback to call when the shutdown operation is complete
452 	 *     userData = the data to pass to the callback function
453 	 *
454 	 * Since: 2.48
455 	 */
456 	public void shutdownAsync(bool shutdownRead, bool shutdownWrite, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
457 
458 	/**
459 	 * Finish an asynchronous TLS shutdown operation. See
460 	 * g_dtls_connection_shutdown() for more information.
461 	 *
462 	 * Params:
463 	 *     result = a #GAsyncResult
464 	 *
465 	 * Return: %TRUE on success, %FALSE on failure, in which
466 	 *     case @error will be set
467 	 *
468 	 * Since: 2.48
469 	 *
470 	 * Throws: GException on failure.
471 	 */
472 	public bool shutdownFinish(AsyncResultIF result);
473 	/**
474 	 * Emitted during the TLS handshake after the peer certificate has
475 	 * been received. You can examine @peer_cert's certification path by
476 	 * calling g_tls_certificate_get_issuer() on it.
477 	 *
478 	 * For a client-side connection, @peer_cert is the server's
479 	 * certificate, and the signal will only be emitted if the
480 	 * certificate was not acceptable according to @conn's
481 	 * #GDtlsClientConnection:validation_flags. If you would like the
482 	 * certificate to be accepted despite @errors, return %TRUE from the
483 	 * signal handler. Otherwise, if no handler accepts the certificate,
484 	 * the handshake will fail with %G_TLS_ERROR_BAD_CERTIFICATE.
485 	 *
486 	 * For a server-side connection, @peer_cert is the certificate
487 	 * presented by the client, if this was requested via the server's
488 	 * #GDtlsServerConnection:authentication_mode. On the server side,
489 	 * the signal is always emitted when the client presents a
490 	 * certificate, and the certificate will only be accepted if a
491 	 * handler returns %TRUE.
492 	 *
493 	 * Note that if this signal is emitted as part of asynchronous I/O
494 	 * in the main thread, then you should not attempt to interact with
495 	 * the user before returning from the signal handler. If you want to
496 	 * let the user decide whether or not to accept the certificate, you
497 	 * would have to return %FALSE from the signal handler on the first
498 	 * attempt, and then after the connection attempt returns a
499 	 * %G_TLS_ERROR_HANDSHAKE, you can interact with the user, and if
500 	 * the user decides to accept the certificate, remember that fact,
501 	 * create a new connection, and return %TRUE from the signal handler
502 	 * the next time.
503 	 *
504 	 * If you are doing I/O in another thread, you do not
505 	 * need to worry about this, and can simply block in the signal
506 	 * handler until the UI thread returns an answer.
507 	 *
508 	 * Params:
509 	 *     peerCert = the peer's #GTlsCertificate
510 	 *     errors = the problems with @peer_cert.
511 	 *
512 	 * Return: %TRUE to accept @peer_cert (which will also
513 	 *     immediately end the signal emission). %FALSE to allow the signal
514 	 *     emission to continue, which will cause the handshake to fail if
515 	 *     no one else overrides it.
516 	 *
517 	 * Since: 2.48
518 	 */
519 	gulong addOnAcceptCertificate(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
520 	;
521 
522 }