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.DtlsConnectionT;
26 
27 public  import gio.AsyncResultIF;
28 public  import gio.Cancellable;
29 public  import gio.TlsCertificate;
30 public  import gio.TlsDatabase;
31 public  import gio.TlsInteraction;
32 public  import glib.ErrorG;
33 public  import glib.GException;
34 public  import gobject.ObjectG;
35 public  import gobject.Signals;
36 public  import gtkc.gdktypes;
37 public  import gtkc.gio;
38 public  import gtkc.giotypes;
39 public  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 template DtlsConnectionT(TStruct)
66 {
67 	/** Get the main Gtk struct */
68 	public GDtlsConnection* getDtlsConnectionStruct()
69 	{
70 		return cast(GDtlsConnection*)getStruct();
71 	}
72 
73 
74 	/**
75 	 * Close the DTLS connection. This is equivalent to calling
76 	 * g_dtls_connection_shutdown() to shut down both sides of the connection.
77 	 *
78 	 * Closing a #GDtlsConnection waits for all buffered but untransmitted data to
79 	 * be sent before it completes. It then sends a `close_notify` DTLS alert to the
80 	 * peer and may wait for a `close_notify` to be received from the peer. It does
81 	 * not close the underlying #GDtlsConnection:base-socket; that must be closed
82 	 * separately.
83 	 *
84 	 * Once @conn is closed, all other operations will return %G_IO_ERROR_CLOSED.
85 	 * Closing a #GDtlsConnection multiple times will not return an error.
86 	 *
87 	 * #GDtlsConnections will be automatically closed when the last reference is
88 	 * dropped, but you might want to call this function to make sure resources are
89 	 * released as early as possible.
90 	 *
91 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
92 	 * partially-closed and any pending untransmitted data may be lost. Call
93 	 * g_dtls_connection_close() again to complete closing the #GDtlsConnection.
94 	 *
95 	 * Params:
96 	 *     cancellable = a #GCancellable, or %NULL
97 	 *
98 	 * Return: %TRUE on success, %FALSE otherwise
99 	 *
100 	 * Since: 2.48
101 	 *
102 	 * Throws: GException on failure.
103 	 */
104 	public bool close(Cancellable cancellable)
105 	{
106 		GError* err = null;
107 		
108 		auto p = g_dtls_connection_close(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
109 		
110 		if (err !is null)
111 		{
112 			throw new GException( new ErrorG(err) );
113 		}
114 		
115 		return p;
116 	}
117 
118 	/**
119 	 * Asynchronously close the DTLS connection. See g_dtls_connection_close() for
120 	 * more information.
121 	 *
122 	 * Params:
123 	 *     ioPriority = the [I/O priority][io-priority] of the request
124 	 *     cancellable = a #GCancellable, or %NULL
125 	 *     callback = callback to call when the close operation is complete
126 	 *     userData = the data to pass to the callback function
127 	 *
128 	 * Since: 2.48
129 	 */
130 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
131 	{
132 		g_dtls_connection_close_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
133 	}
134 
135 	/**
136 	 * Finish an asynchronous TLS close operation. See g_dtls_connection_close()
137 	 * for more information.
138 	 *
139 	 * Params:
140 	 *     result = a #GAsyncResult
141 	 *
142 	 * Return: %TRUE on success, %FALSE on failure, in which
143 	 *     case @error will be set
144 	 *
145 	 * Since: 2.48
146 	 *
147 	 * Throws: GException on failure.
148 	 */
149 	public bool closeFinish(AsyncResultIF result)
150 	{
151 		GError* err = null;
152 		
153 		auto p = g_dtls_connection_close_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
154 		
155 		if (err !is null)
156 		{
157 			throw new GException( new ErrorG(err) );
158 		}
159 		
160 		return p;
161 	}
162 
163 	/**
164 	 * Used by #GDtlsConnection implementations to emit the
165 	 * #GDtlsConnection::accept-certificate signal.
166 	 *
167 	 * Params:
168 	 *     peerCert = the peer's #GTlsCertificate
169 	 *     errors = the problems with @peer_cert
170 	 *
171 	 * Return: %TRUE if one of the signal handlers has returned
172 	 *     %TRUE to accept @peer_cert
173 	 *
174 	 * Since: 2.48
175 	 */
176 	public bool emitAcceptCertificate(TlsCertificate peerCert, GTlsCertificateFlags errors)
177 	{
178 		return g_dtls_connection_emit_accept_certificate(getDtlsConnectionStruct(), (peerCert is null) ? null : peerCert.getTlsCertificateStruct(), errors) != 0;
179 	}
180 
181 	/**
182 	 * Gets @conn's certificate, as set by
183 	 * g_dtls_connection_set_certificate().
184 	 *
185 	 * Return: @conn's certificate, or %NULL
186 	 *
187 	 * Since: 2.48
188 	 */
189 	public TlsCertificate getCertificate()
190 	{
191 		auto p = g_dtls_connection_get_certificate(getDtlsConnectionStruct());
192 		
193 		if(p is null)
194 		{
195 			return null;
196 		}
197 		
198 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
199 	}
200 
201 	/**
202 	 * Gets the certificate database that @conn uses to verify
203 	 * peer certificates. See g_dtls_connection_set_database().
204 	 *
205 	 * Return: the certificate database that @conn uses or %NULL
206 	 *
207 	 * Since: 2.48
208 	 */
209 	public TlsDatabase getDatabase()
210 	{
211 		auto p = g_dtls_connection_get_database(getDtlsConnectionStruct());
212 		
213 		if(p is null)
214 		{
215 			return null;
216 		}
217 		
218 		return ObjectG.getDObject!(TlsDatabase)(cast(GTlsDatabase*) p);
219 	}
220 
221 	/**
222 	 * Get the object that will be used to interact with the user. It will be used
223 	 * for things like prompting the user for passwords. If %NULL is returned, then
224 	 * no user interaction will occur for this connection.
225 	 *
226 	 * Return: The interaction object.
227 	 *
228 	 * Since: 2.48
229 	 */
230 	public TlsInteraction getInteraction()
231 	{
232 		auto p = g_dtls_connection_get_interaction(getDtlsConnectionStruct());
233 		
234 		if(p is null)
235 		{
236 			return null;
237 		}
238 		
239 		return ObjectG.getDObject!(TlsInteraction)(cast(GTlsInteraction*) p);
240 	}
241 
242 	/**
243 	 * Gets @conn's peer's certificate after the handshake has completed.
244 	 * (It is not set during the emission of
245 	 * #GDtlsConnection::accept-certificate.)
246 	 *
247 	 * Return: @conn's peer's certificate, or %NULL
248 	 *
249 	 * Since: 2.48
250 	 */
251 	public TlsCertificate getPeerCertificate()
252 	{
253 		auto p = g_dtls_connection_get_peer_certificate(getDtlsConnectionStruct());
254 		
255 		if(p is null)
256 		{
257 			return null;
258 		}
259 		
260 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
261 	}
262 
263 	/**
264 	 * Gets the errors associated with validating @conn's peer's
265 	 * certificate, after the handshake has completed. (It is not set
266 	 * during the emission of #GDtlsConnection::accept-certificate.)
267 	 *
268 	 * Return: @conn's peer's certificate errors
269 	 *
270 	 * Since: 2.48
271 	 */
272 	public GTlsCertificateFlags getPeerCertificateErrors()
273 	{
274 		return g_dtls_connection_get_peer_certificate_errors(getDtlsConnectionStruct());
275 	}
276 
277 	/**
278 	 * Gets @conn rehandshaking mode. See
279 	 * g_dtls_connection_set_rehandshake_mode() for details.
280 	 *
281 	 * Return: @conn's rehandshaking mode
282 	 *
283 	 * Since: 2.48
284 	 */
285 	public GTlsRehandshakeMode getRehandshakeMode()
286 	{
287 		return g_dtls_connection_get_rehandshake_mode(getDtlsConnectionStruct());
288 	}
289 
290 	/**
291 	 * Tests whether or not @conn expects a proper TLS close notification
292 	 * when the connection is closed. See
293 	 * g_dtls_connection_set_require_close_notify() for details.
294 	 *
295 	 * Return: %TRUE if @conn requires a proper TLS close notification.
296 	 *
297 	 * Since: 2.48
298 	 */
299 	public bool getRequireCloseNotify()
300 	{
301 		return g_dtls_connection_get_require_close_notify(getDtlsConnectionStruct()) != 0;
302 	}
303 
304 	/**
305 	 * Attempts a TLS handshake on @conn.
306 	 *
307 	 * On the client side, it is never necessary to call this method;
308 	 * although the connection needs to perform a handshake after
309 	 * connecting (or after sending a "STARTTLS"-type command) and may
310 	 * need to rehandshake later if the server requests it,
311 	 * #GDtlsConnection will handle this for you automatically when you try
312 	 * to send or receive data on the connection. However, you can call
313 	 * g_dtls_connection_handshake() manually if you want to know for sure
314 	 * whether the initial handshake succeeded or failed (as opposed to
315 	 * just immediately trying to write to @conn, in which
316 	 * case if it fails, it may not be possible to tell if it failed
317 	 * before or after completing the handshake).
318 	 *
319 	 * Likewise, on the server side, although a handshake is necessary at
320 	 * the beginning of the communication, you do not need to call this
321 	 * function explicitly unless you want clearer error reporting.
322 	 * However, you may call g_dtls_connection_handshake() later on to
323 	 * renegotiate parameters (encryption methods, etc) with the client.
324 	 *
325 	 * #GDtlsConnection::accept_certificate may be emitted during the
326 	 * handshake.
327 	 *
328 	 * Params:
329 	 *     cancellable = a #GCancellable, or %NULL
330 	 *
331 	 * Return: success or failure
332 	 *
333 	 * Since: 2.48
334 	 *
335 	 * Throws: GException on failure.
336 	 */
337 	public bool handshake(Cancellable cancellable)
338 	{
339 		GError* err = null;
340 		
341 		auto p = g_dtls_connection_handshake(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
342 		
343 		if (err !is null)
344 		{
345 			throw new GException( new ErrorG(err) );
346 		}
347 		
348 		return p;
349 	}
350 
351 	/**
352 	 * Asynchronously performs a TLS handshake on @conn. See
353 	 * g_dtls_connection_handshake() for more information.
354 	 *
355 	 * Params:
356 	 *     ioPriority = the [I/O priority][io-priority] of the request
357 	 *     cancellable = a #GCancellable, or %NULL
358 	 *     callback = callback to call when the handshake is complete
359 	 *     userData = the data to pass to the callback function
360 	 *
361 	 * Since: 2.48
362 	 */
363 	public void handshakeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
364 	{
365 		g_dtls_connection_handshake_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
366 	}
367 
368 	/**
369 	 * Finish an asynchronous TLS handshake operation. See
370 	 * g_dtls_connection_handshake() for more information.
371 	 *
372 	 * Params:
373 	 *     result = a #GAsyncResult.
374 	 *
375 	 * Return: %TRUE on success, %FALSE on failure, in which
376 	 *     case @error will be set.
377 	 *
378 	 * Since: 2.48
379 	 *
380 	 * Throws: GException on failure.
381 	 */
382 	public bool handshakeFinish(AsyncResultIF result)
383 	{
384 		GError* err = null;
385 		
386 		auto p = g_dtls_connection_handshake_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
387 		
388 		if (err !is null)
389 		{
390 			throw new GException( new ErrorG(err) );
391 		}
392 		
393 		return p;
394 	}
395 
396 	/**
397 	 * This sets the certificate that @conn will present to its peer
398 	 * during the TLS handshake. For a #GDtlsServerConnection, it is
399 	 * mandatory to set this, and that will normally be done at construct
400 	 * time.
401 	 *
402 	 * For a #GDtlsClientConnection, this is optional. If a handshake fails
403 	 * with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
404 	 * requires a certificate, and if you try connecting again, you should
405 	 * call this method first. You can call
406 	 * g_dtls_client_connection_get_accepted_cas() on the failed connection
407 	 * to get a list of Certificate Authorities that the server will
408 	 * accept certificates from.
409 	 *
410 	 * (It is also possible that a server will allow the connection with
411 	 * or without a certificate; in that case, if you don't provide a
412 	 * certificate, you can tell that the server requested one by the fact
413 	 * that g_dtls_client_connection_get_accepted_cas() will return
414 	 * non-%NULL.)
415 	 *
416 	 * Params:
417 	 *     certificate = the certificate to use for @conn
418 	 *
419 	 * Since: 2.48
420 	 */
421 	public void setCertificate(TlsCertificate certificate)
422 	{
423 		g_dtls_connection_set_certificate(getDtlsConnectionStruct(), (certificate is null) ? null : certificate.getTlsCertificateStruct());
424 	}
425 
426 	/**
427 	 * Sets the certificate database that is used to verify peer certificates.
428 	 * This is set to the default database by default. See
429 	 * g_dtls_backend_get_default_database(). If set to %NULL, then
430 	 * peer certificate validation will always set the
431 	 * %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
432 	 * #GDtlsConnection::accept-certificate will always be emitted on
433 	 * client-side connections, unless that bit is not set in
434 	 * #GDtlsClientConnection:validation-flags).
435 	 *
436 	 * Params:
437 	 *     database = a #GTlsDatabase
438 	 *
439 	 * Since: 2.48
440 	 */
441 	public void setDatabase(TlsDatabase database)
442 	{
443 		g_dtls_connection_set_database(getDtlsConnectionStruct(), (database is null) ? null : database.getTlsDatabaseStruct());
444 	}
445 
446 	/**
447 	 * Set the object that will be used to interact with the user. It will be used
448 	 * for things like prompting the user for passwords.
449 	 *
450 	 * The @interaction argument will normally be a derived subclass of
451 	 * #GTlsInteraction. %NULL can also be provided if no user interaction
452 	 * should occur for this connection.
453 	 *
454 	 * Params:
455 	 *     interaction = an interaction object, or %NULL
456 	 *
457 	 * Since: 2.48
458 	 */
459 	public void setInteraction(TlsInteraction interaction)
460 	{
461 		g_dtls_connection_set_interaction(getDtlsConnectionStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct());
462 	}
463 
464 	/**
465 	 * Sets how @conn behaves with respect to rehandshaking requests.
466 	 *
467 	 * %G_TLS_REHANDSHAKE_NEVER means that it will never agree to
468 	 * rehandshake after the initial handshake is complete. (For a client,
469 	 * this means it will refuse rehandshake requests from the server, and
470 	 * for a server, this means it will close the connection with an error
471 	 * if the client attempts to rehandshake.)
472 	 *
473 	 * %G_TLS_REHANDSHAKE_SAFELY means that the connection will allow a
474 	 * rehandshake only if the other end of the connection supports the
475 	 * TLS `renegotiation_info` extension. This is the default behavior,
476 	 * but means that rehandshaking will not work against older
477 	 * implementations that do not support that extension.
478 	 *
479 	 * %G_TLS_REHANDSHAKE_UNSAFELY means that the connection will allow
480 	 * rehandshaking even without the `renegotiation_info` extension. On
481 	 * the server side in particular, this is not recommended, since it
482 	 * leaves the server open to certain attacks. However, this mode is
483 	 * necessary if you need to allow renegotiation with older client
484 	 * software.
485 	 *
486 	 * Params:
487 	 *     mode = the rehandshaking mode
488 	 *
489 	 * Since: 2.48
490 	 */
491 	public void setRehandshakeMode(GTlsRehandshakeMode mode)
492 	{
493 		g_dtls_connection_set_rehandshake_mode(getDtlsConnectionStruct(), mode);
494 	}
495 
496 	/**
497 	 * Sets whether or not @conn expects a proper TLS close notification
498 	 * before the connection is closed. If this is %TRUE (the default),
499 	 * then @conn will expect to receive a TLS close notification from its
500 	 * peer before the connection is closed, and will return a
501 	 * %G_TLS_ERROR_EOF error if the connection is closed without proper
502 	 * notification (since this may indicate a network error, or
503 	 * man-in-the-middle attack).
504 	 *
505 	 * In some protocols, the application will know whether or not the
506 	 * connection was closed cleanly based on application-level data
507 	 * (because the application-level data includes a length field, or is
508 	 * somehow self-delimiting); in this case, the close notify is
509 	 * redundant and may be omitted. You
510 	 * can use g_dtls_connection_set_require_close_notify() to tell @conn
511 	 * to allow an "unannounced" connection close, in which case the close
512 	 * will show up as a 0-length read, as in a non-TLS
513 	 * #GDatagramBased, and it is up to the application to check that
514 	 * the data has been fully received.
515 	 *
516 	 * Note that this only affects the behavior when the peer closes the
517 	 * connection; when the application calls g_dtls_connection_close_async() on
518 	 * @conn itself, this will send a close notification regardless of the
519 	 * setting of this property. If you explicitly want to do an unclean
520 	 * close, you can close @conn's #GDtlsConnection:base-socket rather
521 	 * than closing @conn itself.
522 	 *
523 	 * Params:
524 	 *     requireCloseNotify = whether or not to require close notification
525 	 *
526 	 * Since: 2.48
527 	 */
528 	public void setRequireCloseNotify(bool requireCloseNotify)
529 	{
530 		g_dtls_connection_set_require_close_notify(getDtlsConnectionStruct(), requireCloseNotify);
531 	}
532 
533 	/**
534 	 * Shut down part or all of a DTLS connection.
535 	 *
536 	 * If @shutdown_read is %TRUE then the receiving side of the connection is shut
537 	 * down, and further reading is disallowed. Subsequent calls to
538 	 * g_datagram_based_receive_messages() will return %G_IO_ERROR_CLOSED.
539 	 *
540 	 * If @shutdown_write is %TRUE then the sending side of the connection is shut
541 	 * down, and further writing is disallowed. Subsequent calls to
542 	 * g_datagram_based_send_messages() will return %G_IO_ERROR_CLOSED.
543 	 *
544 	 * It is allowed for both @shutdown_read and @shutdown_write to be TRUE — this
545 	 * is equivalent to calling g_dtls_connection_close().
546 	 *
547 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
548 	 * partially-closed and any pending untransmitted data may be lost. Call
549 	 * g_dtls_connection_shutdown() again to complete closing the #GDtlsConnection.
550 	 *
551 	 * Params:
552 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
553 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
554 	 *     cancellable = a #GCancellable, or %NULL
555 	 *
556 	 * Return: %TRUE on success, %FALSE otherwise
557 	 *
558 	 * Since: 2.48
559 	 *
560 	 * Throws: GException on failure.
561 	 */
562 	public bool shutdown(bool shutdownRead, bool shutdownWrite, Cancellable cancellable)
563 	{
564 		GError* err = null;
565 		
566 		auto p = g_dtls_connection_shutdown(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
567 		
568 		if (err !is null)
569 		{
570 			throw new GException( new ErrorG(err) );
571 		}
572 		
573 		return p;
574 	}
575 
576 	/**
577 	 * Asynchronously shut down part or all of the DTLS connection. See
578 	 * g_dtls_connection_shutdown() for more information.
579 	 *
580 	 * Params:
581 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
582 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
583 	 *     ioPriority = the [I/O priority][io-priority] of the request
584 	 *     cancellable = a #GCancellable, or %NULL
585 	 *     callback = callback to call when the shutdown operation is complete
586 	 *     userData = the data to pass to the callback function
587 	 *
588 	 * Since: 2.48
589 	 */
590 	public void shutdownAsync(bool shutdownRead, bool shutdownWrite, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
591 	{
592 		g_dtls_connection_shutdown_async(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
593 	}
594 
595 	/**
596 	 * Finish an asynchronous TLS shutdown operation. See
597 	 * g_dtls_connection_shutdown() for more information.
598 	 *
599 	 * Params:
600 	 *     result = a #GAsyncResult
601 	 *
602 	 * Return: %TRUE on success, %FALSE on failure, in which
603 	 *     case @error will be set
604 	 *
605 	 * Since: 2.48
606 	 *
607 	 * Throws: GException on failure.
608 	 */
609 	public bool shutdownFinish(AsyncResultIF result)
610 	{
611 		GError* err = null;
612 		
613 		auto p = g_dtls_connection_shutdown_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
614 		
615 		if (err !is null)
616 		{
617 			throw new GException( new ErrorG(err) );
618 		}
619 		
620 		return p;
621 	}
622 
623 	protected class OnAcceptCertificateDelegateWrapper
624 	{
625 		bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg;
626 		gulong handlerId;
627 		ConnectFlags flags;
628 		this(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg, gulong handlerId, ConnectFlags flags)
629 		{
630 			this.dlg = dlg;
631 			this.handlerId = handlerId;
632 			this.flags = flags;
633 		}
634 	}
635 	protected OnAcceptCertificateDelegateWrapper[] onAcceptCertificateListeners;
636 
637 	/**
638 	 * Emitted during the TLS handshake after the peer certificate has
639 	 * been received. You can examine @peer_cert's certification path by
640 	 * calling g_tls_certificate_get_issuer() on it.
641 	 *
642 	 * For a client-side connection, @peer_cert is the server's
643 	 * certificate, and the signal will only be emitted if the
644 	 * certificate was not acceptable according to @conn's
645 	 * #GDtlsClientConnection:validation_flags. If you would like the
646 	 * certificate to be accepted despite @errors, return %TRUE from the
647 	 * signal handler. Otherwise, if no handler accepts the certificate,
648 	 * the handshake will fail with %G_TLS_ERROR_BAD_CERTIFICATE.
649 	 *
650 	 * For a server-side connection, @peer_cert is the certificate
651 	 * presented by the client, if this was requested via the server's
652 	 * #GDtlsServerConnection:authentication_mode. On the server side,
653 	 * the signal is always emitted when the client presents a
654 	 * certificate, and the certificate will only be accepted if a
655 	 * handler returns %TRUE.
656 	 *
657 	 * Note that if this signal is emitted as part of asynchronous I/O
658 	 * in the main thread, then you should not attempt to interact with
659 	 * the user before returning from the signal handler. If you want to
660 	 * let the user decide whether or not to accept the certificate, you
661 	 * would have to return %FALSE from the signal handler on the first
662 	 * attempt, and then after the connection attempt returns a
663 	 * %G_TLS_ERROR_HANDSHAKE, you can interact with the user, and if
664 	 * the user decides to accept the certificate, remember that fact,
665 	 * create a new connection, and return %TRUE from the signal handler
666 	 * the next time.
667 	 *
668 	 * If you are doing I/O in another thread, you do not
669 	 * need to worry about this, and can simply block in the signal
670 	 * handler until the UI thread returns an answer.
671 	 *
672 	 * Params:
673 	 *     peerCert = the peer's #GTlsCertificate
674 	 *     errors = the problems with @peer_cert.
675 	 *
676 	 * Return: %TRUE to accept @peer_cert (which will also
677 	 *     immediately end the signal emission). %FALSE to allow the signal
678 	 *     emission to continue, which will cause the handshake to fail if
679 	 *     no one else overrides it.
680 	 *
681 	 * Since: 2.48
682 	 */
683 	gulong addOnAcceptCertificate(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
684 	{
685 		onAcceptCertificateListeners ~= new OnAcceptCertificateDelegateWrapper(dlg, 0, connectFlags);
686 		onAcceptCertificateListeners[onAcceptCertificateListeners.length - 1].handlerId = Signals.connectData(
687 			this,
688 			"accept-certificate",
689 			cast(GCallback)&callBackAcceptCertificate,
690 			cast(void*)onAcceptCertificateListeners[onAcceptCertificateListeners.length - 1],
691 			cast(GClosureNotify)&callBackAcceptCertificateDestroy,
692 			connectFlags);
693 		return onAcceptCertificateListeners[onAcceptCertificateListeners.length - 1].handlerId;
694 	}
695 	
696 	extern(C) static int callBackAcceptCertificate(GDtlsConnection* dtlsconnectionStruct, GTlsCertificate* peerCert, GTlsCertificateFlags errors,OnAcceptCertificateDelegateWrapper wrapper)
697 	{
698 		return wrapper.dlg(ObjectG.getDObject!(TlsCertificate)(peerCert), errors, wrapper.outer);
699 	}
700 	
701 	extern(C) static void callBackAcceptCertificateDestroy(OnAcceptCertificateDelegateWrapper wrapper, GClosure* closure)
702 	{
703 		wrapper.outer.internalRemoveOnAcceptCertificate(wrapper);
704 	}
705 
706 	protected void internalRemoveOnAcceptCertificate(OnAcceptCertificateDelegateWrapper source)
707 	{
708 		foreach(index, wrapper; onAcceptCertificateListeners)
709 		{
710 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
711 			{
712 				onAcceptCertificateListeners[index] = null;
713 				onAcceptCertificateListeners = std.algorithm.remove(onAcceptCertificateListeners, index);
714 				break;
715 			}
716 		}
717 	}
718 	
719 }