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 gio.c.functions;
33 public  import gio.c.types;
34 private import glib.ByteArray;
35 private import glib.ErrorG;
36 private import glib.GException;
37 private import glib.MemorySlice;
38 private import glib.Str;
39 private import glib.c.functions;
40 private import gobject.ObjectG;
41 private import gobject.Signals;
42 private import std.algorithm;
43 
44 
45 /**
46  * #GDtlsConnection is the base DTLS connection class type, which wraps
47  * a #GDatagramBased and provides DTLS encryption on top of it. Its
48  * subclasses, #GDtlsClientConnection and #GDtlsServerConnection,
49  * implement client-side and server-side DTLS, respectively.
50  * 
51  * For TLS support, see #GTlsConnection.
52  * 
53  * As DTLS is datagram based, #GDtlsConnection implements #GDatagramBased,
54  * presenting a datagram-socket-like API for the encrypted connection. This
55  * operates over a base datagram connection, which is also a #GDatagramBased
56  * (#GDtlsConnection:base-socket).
57  * 
58  * To close a DTLS connection, use g_dtls_connection_close().
59  * 
60  * Neither #GDtlsServerConnection or #GDtlsClientConnection set the peer address
61  * on their base #GDatagramBased if it is a #GSocket — it is up to the caller to
62  * do that if they wish. If they do not, and g_socket_close() is called on the
63  * base socket, the #GDtlsConnection will not raise a %G_IO_ERROR_NOT_CONNECTED
64  * error on further I/O.
65  *
66  * Since: 2.48
67  */
68 public interface DtlsConnectionIF{
69 	/** Get the main Gtk struct */
70 	public GDtlsConnection* getDtlsConnectionStruct(bool transferOwnership = false);
71 
72 	/** the main Gtk struct as a void* */
73 	protected void* getStruct();
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return g_dtls_connection_get_type();
80 	}
81 
82 	/**
83 	 * Close the DTLS connection. This is equivalent to calling
84 	 * g_dtls_connection_shutdown() to shut down both sides of the connection.
85 	 *
86 	 * Closing a #GDtlsConnection waits for all buffered but untransmitted data to
87 	 * be sent before it completes. It then sends a `close_notify` DTLS alert to the
88 	 * peer and may wait for a `close_notify` to be received from the peer. It does
89 	 * not close the underlying #GDtlsConnection:base-socket; that must be closed
90 	 * separately.
91 	 *
92 	 * Once @conn is closed, all other operations will return %G_IO_ERROR_CLOSED.
93 	 * Closing a #GDtlsConnection multiple times will not return an error.
94 	 *
95 	 * #GDtlsConnections will be automatically closed when the last reference is
96 	 * dropped, but you might want to call this function to make sure resources are
97 	 * released as early as possible.
98 	 *
99 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
100 	 * partially-closed and any pending untransmitted data may be lost. Call
101 	 * g_dtls_connection_close() again to complete closing the #GDtlsConnection.
102 	 *
103 	 * Params:
104 	 *     cancellable = a #GCancellable, or %NULL
105 	 *
106 	 * Returns: %TRUE on success, %FALSE otherwise
107 	 *
108 	 * Since: 2.48
109 	 *
110 	 * Throws: GException on failure.
111 	 */
112 	public bool close(Cancellable cancellable);
113 
114 	/**
115 	 * Asynchronously close the DTLS connection. See g_dtls_connection_close() for
116 	 * more information.
117 	 *
118 	 * Params:
119 	 *     ioPriority = the [I/O priority][io-priority] of the request
120 	 *     cancellable = a #GCancellable, or %NULL
121 	 *     callback = callback to call when the close operation is complete
122 	 *     userData = the data to pass to the callback function
123 	 *
124 	 * Since: 2.48
125 	 */
126 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
127 
128 	/**
129 	 * Finish an asynchronous TLS close operation. See g_dtls_connection_close()
130 	 * for more information.
131 	 *
132 	 * Params:
133 	 *     result = a #GAsyncResult
134 	 *
135 	 * Returns: %TRUE on success, %FALSE on failure, in which
136 	 *     case @error will be set
137 	 *
138 	 * Since: 2.48
139 	 *
140 	 * Throws: GException on failure.
141 	 */
142 	public bool closeFinish(AsyncResultIF result);
143 
144 	/**
145 	 * Used by #GDtlsConnection implementations to emit the
146 	 * #GDtlsConnection::accept-certificate signal.
147 	 *
148 	 * Params:
149 	 *     peerCert = the peer's #GTlsCertificate
150 	 *     errors = the problems with @peer_cert
151 	 *
152 	 * Returns: %TRUE if one of the signal handlers has returned
153 	 *     %TRUE to accept @peer_cert
154 	 *
155 	 * Since: 2.48
156 	 */
157 	public bool emitAcceptCertificate(TlsCertificate peerCert, GTlsCertificateFlags errors);
158 
159 	/**
160 	 * Gets @conn's certificate, as set by
161 	 * g_dtls_connection_set_certificate().
162 	 *
163 	 * Returns: @conn's certificate, or %NULL
164 	 *
165 	 * Since: 2.48
166 	 */
167 	public TlsCertificate getCertificate();
168 
169 	/**
170 	 * Query the TLS backend for TLS channel binding data of @type for @conn.
171 	 *
172 	 * This call retrieves TLS channel binding data as specified in RFC
173 	 * [5056](https://tools.ietf.org/html/rfc5056), RFC
174 	 * [5929](https://tools.ietf.org/html/rfc5929), and related RFCs.  The
175 	 * binding data is returned in @data.  The @data is resized by the callee
176 	 * using #GByteArray buffer management and will be freed when the @data
177 	 * is destroyed by g_byte_array_unref(). If @data is %NULL, it will only
178 	 * check whether TLS backend is able to fetch the data (e.g. whether @type
179 	 * is supported by the TLS backend). It does not guarantee that the data
180 	 * will be available though.  That could happen if TLS connection does not
181 	 * support @type or the binding data is not available yet due to additional
182 	 * negotiation or input required.
183 	 *
184 	 * Params:
185 	 *     type = #GTlsChannelBindingType type of data to fetch
186 	 *     data = #GByteArray is
187 	 *         filled with the binding data, or %NULL
188 	 *
189 	 * Returns: %TRUE on success, %FALSE otherwise
190 	 *
191 	 * Since: 2.66
192 	 *
193 	 * Throws: GException on failure.
194 	 */
195 	public bool getChannelBindingData(GTlsChannelBindingType type, out ByteArray data);
196 
197 	/**
198 	 * Gets the certificate database that @conn uses to verify
199 	 * peer certificates. See g_dtls_connection_set_database().
200 	 *
201 	 * Returns: the certificate database that @conn uses or %NULL
202 	 *
203 	 * Since: 2.48
204 	 */
205 	public TlsDatabase getDatabase();
206 
207 	/**
208 	 * Get the object that will be used to interact with the user. It will be used
209 	 * for things like prompting the user for passwords. If %NULL is returned, then
210 	 * no user interaction will occur for this connection.
211 	 *
212 	 * Returns: The interaction object.
213 	 *
214 	 * Since: 2.48
215 	 */
216 	public TlsInteraction getInteraction();
217 
218 	/**
219 	 * Gets the name of the application-layer protocol negotiated during
220 	 * the handshake.
221 	 *
222 	 * If the peer did not use the ALPN extension, or did not advertise a
223 	 * protocol that matched one of @conn's protocols, or the TLS backend
224 	 * does not support ALPN, then this will be %NULL. See
225 	 * g_dtls_connection_set_advertised_protocols().
226 	 *
227 	 * Returns: the negotiated protocol, or %NULL
228 	 *
229 	 * Since: 2.60
230 	 */
231 	public string getNegotiatedProtocol();
232 
233 	/**
234 	 * Gets @conn's peer's certificate after the handshake has completed
235 	 * or failed. (It is not set during the emission of
236 	 * #GDtlsConnection::accept-certificate.)
237 	 *
238 	 * Returns: @conn's peer's certificate, or %NULL
239 	 *
240 	 * Since: 2.48
241 	 */
242 	public TlsCertificate getPeerCertificate();
243 
244 	/**
245 	 * Gets the errors associated with validating @conn's peer's
246 	 * certificate, after the handshake has completed or failed. (It is
247 	 * not set during the emission of #GDtlsConnection::accept-certificate.)
248 	 *
249 	 * Returns: @conn's peer's certificate errors
250 	 *
251 	 * Since: 2.48
252 	 */
253 	public GTlsCertificateFlags getPeerCertificateErrors();
254 
255 	/**
256 	 * Gets @conn rehandshaking mode. See
257 	 * g_dtls_connection_set_rehandshake_mode() for details.
258 	 *
259 	 * Deprecated: Changing the rehandshake mode is no longer
260 	 * required for compatibility. Also, rehandshaking has been removed
261 	 * from the TLS protocol in TLS 1.3.
262 	 *
263 	 * Returns: %G_TLS_REHANDSHAKE_SAFELY
264 	 *
265 	 * Since: 2.48
266 	 */
267 	public GTlsRehandshakeMode getRehandshakeMode();
268 
269 	/**
270 	 * Tests whether or not @conn expects a proper TLS close notification
271 	 * when the connection is closed. See
272 	 * g_dtls_connection_set_require_close_notify() for details.
273 	 *
274 	 * Returns: %TRUE if @conn requires a proper TLS close notification.
275 	 *
276 	 * Since: 2.48
277 	 */
278 	public bool getRequireCloseNotify();
279 
280 	/**
281 	 * Attempts a TLS handshake on @conn.
282 	 *
283 	 * On the client side, it is never necessary to call this method;
284 	 * although the connection needs to perform a handshake after
285 	 * connecting, #GDtlsConnection will handle this for you automatically
286 	 * when you try to send or receive data on the connection. You can call
287 	 * g_dtls_connection_handshake() manually if you want to know whether
288 	 * the initial handshake succeeded or failed (as opposed to just
289 	 * immediately trying to use @conn to read or write, in which case,
290 	 * if it fails, it may not be possible to tell if it failed before
291 	 * or after completing the handshake), but beware that servers may reject
292 	 * client authentication after the handshake has completed, so a
293 	 * successful handshake does not indicate the connection will be usable.
294 	 *
295 	 * Likewise, on the server side, although a handshake is necessary at
296 	 * the beginning of the communication, you do not need to call this
297 	 * function explicitly unless you want clearer error reporting.
298 	 *
299 	 * Previously, calling g_dtls_connection_handshake() after the initial
300 	 * handshake would trigger a rehandshake; however, this usage was
301 	 * deprecated in GLib 2.60 because rehandshaking was removed from the
302 	 * TLS protocol in TLS 1.3. Since GLib 2.64, calling this function after
303 	 * the initial handshake will no longer do anything.
304 	 *
305 	 * #GDtlsConnection::accept_certificate may be emitted during the
306 	 * handshake.
307 	 *
308 	 * Params:
309 	 *     cancellable = a #GCancellable, or %NULL
310 	 *
311 	 * Returns: success or failure
312 	 *
313 	 * Since: 2.48
314 	 *
315 	 * Throws: GException on failure.
316 	 */
317 	public bool handshake(Cancellable cancellable);
318 
319 	/**
320 	 * Asynchronously performs a TLS handshake on @conn. See
321 	 * g_dtls_connection_handshake() for more information.
322 	 *
323 	 * Params:
324 	 *     ioPriority = the [I/O priority][io-priority] of the request
325 	 *     cancellable = a #GCancellable, or %NULL
326 	 *     callback = callback to call when the handshake is complete
327 	 *     userData = the data to pass to the callback function
328 	 *
329 	 * Since: 2.48
330 	 */
331 	public void handshakeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
332 
333 	/**
334 	 * Finish an asynchronous TLS handshake operation. See
335 	 * g_dtls_connection_handshake() for more information.
336 	 *
337 	 * Params:
338 	 *     result = a #GAsyncResult.
339 	 *
340 	 * Returns: %TRUE on success, %FALSE on failure, in which
341 	 *     case @error will be set.
342 	 *
343 	 * Since: 2.48
344 	 *
345 	 * Throws: GException on failure.
346 	 */
347 	public bool handshakeFinish(AsyncResultIF result);
348 
349 	/**
350 	 * Sets the list of application-layer protocols to advertise that the
351 	 * caller is willing to speak on this connection. The
352 	 * Application-Layer Protocol Negotiation (ALPN) extension will be
353 	 * used to negotiate a compatible protocol with the peer; use
354 	 * g_dtls_connection_get_negotiated_protocol() to find the negotiated
355 	 * protocol after the handshake.  Specifying %NULL for the the value
356 	 * of @protocols will disable ALPN negotiation.
357 	 *
358 	 * See [IANA TLS ALPN Protocol IDs](https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids)
359 	 * for a list of registered protocol IDs.
360 	 *
361 	 * Params:
362 	 *     protocols = a %NULL-terminated
363 	 *         array of ALPN protocol names (eg, "http/1.1", "h2"), or %NULL
364 	 *
365 	 * Since: 2.60
366 	 */
367 	public void setAdvertisedProtocols(string[] protocols);
368 
369 	/**
370 	 * This sets the certificate that @conn will present to its peer
371 	 * during the TLS handshake. For a #GDtlsServerConnection, it is
372 	 * mandatory to set this, and that will normally be done at construct
373 	 * time.
374 	 *
375 	 * For a #GDtlsClientConnection, this is optional. If a handshake fails
376 	 * with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
377 	 * requires a certificate, and if you try connecting again, you should
378 	 * call this method first. You can call
379 	 * g_dtls_client_connection_get_accepted_cas() on the failed connection
380 	 * to get a list of Certificate Authorities that the server will
381 	 * accept certificates from.
382 	 *
383 	 * (It is also possible that a server will allow the connection with
384 	 * or without a certificate; in that case, if you don't provide a
385 	 * certificate, you can tell that the server requested one by the fact
386 	 * that g_dtls_client_connection_get_accepted_cas() will return
387 	 * non-%NULL.)
388 	 *
389 	 * Params:
390 	 *     certificate = the certificate to use for @conn
391 	 *
392 	 * Since: 2.48
393 	 */
394 	public void setCertificate(TlsCertificate certificate);
395 
396 	/**
397 	 * Sets the certificate database that is used to verify peer certificates.
398 	 * This is set to the default database by default. See
399 	 * g_tls_backend_get_default_database(). If set to %NULL, then
400 	 * peer certificate validation will always set the
401 	 * %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
402 	 * #GDtlsConnection::accept-certificate will always be emitted on
403 	 * client-side connections, unless that bit is not set in
404 	 * #GDtlsClientConnection:validation-flags).
405 	 *
406 	 * Params:
407 	 *     database = a #GTlsDatabase
408 	 *
409 	 * Since: 2.48
410 	 */
411 	public void setDatabase(TlsDatabase database);
412 
413 	/**
414 	 * Set the object that will be used to interact with the user. It will be used
415 	 * for things like prompting the user for passwords.
416 	 *
417 	 * The @interaction argument will normally be a derived subclass of
418 	 * #GTlsInteraction. %NULL can also be provided if no user interaction
419 	 * should occur for this connection.
420 	 *
421 	 * Params:
422 	 *     interaction = an interaction object, or %NULL
423 	 *
424 	 * Since: 2.48
425 	 */
426 	public void setInteraction(TlsInteraction interaction);
427 
428 	/**
429 	 * Since GLib 2.64, changing the rehandshake mode is no longer supported
430 	 * and will have no effect. With TLS 1.3, rehandshaking has been removed from
431 	 * the TLS protocol, replaced by separate post-handshake authentication and
432 	 * rekey operations.
433 	 *
434 	 * Deprecated: Changing the rehandshake mode is no longer
435 	 * required for compatibility. Also, rehandshaking has been removed
436 	 * from the TLS protocol in TLS 1.3.
437 	 *
438 	 * Params:
439 	 *     mode = the rehandshaking mode
440 	 *
441 	 * Since: 2.48
442 	 */
443 	public void setRehandshakeMode(GTlsRehandshakeMode mode);
444 
445 	/**
446 	 * Sets whether or not @conn expects a proper TLS close notification
447 	 * before the connection is closed. If this is %TRUE (the default),
448 	 * then @conn will expect to receive a TLS close notification from its
449 	 * peer before the connection is closed, and will return a
450 	 * %G_TLS_ERROR_EOF error if the connection is closed without proper
451 	 * notification (since this may indicate a network error, or
452 	 * man-in-the-middle attack).
453 	 *
454 	 * In some protocols, the application will know whether or not the
455 	 * connection was closed cleanly based on application-level data
456 	 * (because the application-level data includes a length field, or is
457 	 * somehow self-delimiting); in this case, the close notify is
458 	 * redundant and may be omitted. You
459 	 * can use g_dtls_connection_set_require_close_notify() to tell @conn
460 	 * to allow an "unannounced" connection close, in which case the close
461 	 * will show up as a 0-length read, as in a non-TLS
462 	 * #GDatagramBased, and it is up to the application to check that
463 	 * the data has been fully received.
464 	 *
465 	 * Note that this only affects the behavior when the peer closes the
466 	 * connection; when the application calls g_dtls_connection_close_async() on
467 	 * @conn itself, this will send a close notification regardless of the
468 	 * setting of this property. If you explicitly want to do an unclean
469 	 * close, you can close @conn's #GDtlsConnection:base-socket rather
470 	 * than closing @conn itself.
471 	 *
472 	 * Params:
473 	 *     requireCloseNotify = whether or not to require close notification
474 	 *
475 	 * Since: 2.48
476 	 */
477 	public void setRequireCloseNotify(bool requireCloseNotify);
478 
479 	/**
480 	 * Shut down part or all of a DTLS connection.
481 	 *
482 	 * If @shutdown_read is %TRUE then the receiving side of the connection is shut
483 	 * down, and further reading is disallowed. Subsequent calls to
484 	 * g_datagram_based_receive_messages() will return %G_IO_ERROR_CLOSED.
485 	 *
486 	 * If @shutdown_write is %TRUE then the sending side of the connection is shut
487 	 * down, and further writing is disallowed. Subsequent calls to
488 	 * g_datagram_based_send_messages() will return %G_IO_ERROR_CLOSED.
489 	 *
490 	 * It is allowed for both @shutdown_read and @shutdown_write to be TRUE — this
491 	 * is equivalent to calling g_dtls_connection_close().
492 	 *
493 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
494 	 * partially-closed and any pending untransmitted data may be lost. Call
495 	 * g_dtls_connection_shutdown() again to complete closing the #GDtlsConnection.
496 	 *
497 	 * Params:
498 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
499 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
500 	 *     cancellable = a #GCancellable, or %NULL
501 	 *
502 	 * Returns: %TRUE on success, %FALSE otherwise
503 	 *
504 	 * Since: 2.48
505 	 *
506 	 * Throws: GException on failure.
507 	 */
508 	public bool shutdown(bool shutdownRead, bool shutdownWrite, Cancellable cancellable);
509 
510 	/**
511 	 * Asynchronously shut down part or all of the DTLS connection. See
512 	 * g_dtls_connection_shutdown() for more information.
513 	 *
514 	 * Params:
515 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
516 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
517 	 *     ioPriority = the [I/O priority][io-priority] of the request
518 	 *     cancellable = a #GCancellable, or %NULL
519 	 *     callback = callback to call when the shutdown operation is complete
520 	 *     userData = the data to pass to the callback function
521 	 *
522 	 * Since: 2.48
523 	 */
524 	public void shutdownAsync(bool shutdownRead, bool shutdownWrite, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
525 
526 	/**
527 	 * Finish an asynchronous TLS shutdown operation. See
528 	 * g_dtls_connection_shutdown() for more information.
529 	 *
530 	 * Params:
531 	 *     result = a #GAsyncResult
532 	 *
533 	 * Returns: %TRUE on success, %FALSE on failure, in which
534 	 *     case @error will be set
535 	 *
536 	 * Since: 2.48
537 	 *
538 	 * Throws: GException on failure.
539 	 */
540 	public bool shutdownFinish(AsyncResultIF result);
541 
542 	/**
543 	 * Emitted during the TLS handshake after the peer certificate has
544 	 * been received. You can examine @peer_cert's certification path by
545 	 * calling g_tls_certificate_get_issuer() on it.
546 	 *
547 	 * For a client-side connection, @peer_cert is the server's
548 	 * certificate, and the signal will only be emitted if the
549 	 * certificate was not acceptable according to @conn's
550 	 * #GDtlsClientConnection:validation_flags. If you would like the
551 	 * certificate to be accepted despite @errors, return %TRUE from the
552 	 * signal handler. Otherwise, if no handler accepts the certificate,
553 	 * the handshake will fail with %G_TLS_ERROR_BAD_CERTIFICATE.
554 	 *
555 	 * For a server-side connection, @peer_cert is the certificate
556 	 * presented by the client, if this was requested via the server's
557 	 * #GDtlsServerConnection:authentication_mode. On the server side,
558 	 * the signal is always emitted when the client presents a
559 	 * certificate, and the certificate will only be accepted if a
560 	 * handler returns %TRUE.
561 	 *
562 	 * Note that if this signal is emitted as part of asynchronous I/O
563 	 * in the main thread, then you should not attempt to interact with
564 	 * the user before returning from the signal handler. If you want to
565 	 * let the user decide whether or not to accept the certificate, you
566 	 * would have to return %FALSE from the signal handler on the first
567 	 * attempt, and then after the connection attempt returns a
568 	 * %G_TLS_ERROR_BAD_CERTIFICATE, you can interact with the user, and
569 	 * if the user decides to accept the certificate, remember that fact,
570 	 * create a new connection, and return %TRUE from the signal handler
571 	 * the next time.
572 	 *
573 	 * If you are doing I/O in another thread, you do not
574 	 * need to worry about this, and can simply block in the signal
575 	 * handler until the UI thread returns an answer.
576 	 *
577 	 * Params:
578 	 *     peerCert = the peer's #GTlsCertificate
579 	 *     errors = the problems with @peer_cert.
580 	 *
581 	 * Returns: %TRUE to accept @peer_cert (which will also
582 	 *     immediately end the signal emission). %FALSE to allow the signal
583 	 *     emission to continue, which will cause the handshake to fail if
584 	 *     no one else overrides it.
585 	 *
586 	 * Since: 2.48
587 	 */
588 	gulong addOnAcceptCertificate(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
589 }