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