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.TlsDatabase; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.SocketConnectableIF; 30 private import gio.TlsCertificate; 31 private import gio.TlsInteraction; 32 private import glib.ByteArray; 33 private import glib.ErrorG; 34 private import glib.GException; 35 private import glib.ListG; 36 private import glib.Str; 37 private import gobject.ObjectG; 38 private import gtkc.gio; 39 public import gtkc.giotypes; 40 41 42 /** 43 * #GTlsDatabase is used to lookup certificates and other information 44 * from a certificate or key store. It is an abstract base class which 45 * TLS library specific subtypes override. 46 * 47 * Most common client applications will not directly interact with 48 * #GTlsDatabase. It is used internally by #GTlsConnection. 49 * 50 * Since: 2.30 51 */ 52 public class TlsDatabase : ObjectG 53 { 54 /** the main Gtk struct */ 55 protected GTlsDatabase* gTlsDatabase; 56 57 /** Get the main Gtk struct */ 58 public GTlsDatabase* getTlsDatabaseStruct(bool transferOwnership = false) 59 { 60 if (transferOwnership) 61 ownedRef = false; 62 return gTlsDatabase; 63 } 64 65 /** the main Gtk struct as a void* */ 66 protected override void* getStruct() 67 { 68 return cast(void*)gTlsDatabase; 69 } 70 71 protected override void setStruct(GObject* obj) 72 { 73 gTlsDatabase = cast(GTlsDatabase*)obj; 74 super.setStruct(obj); 75 } 76 77 /** 78 * Sets our main struct and passes it to the parent class. 79 */ 80 public this (GTlsDatabase* gTlsDatabase, bool ownedRef = false) 81 { 82 this.gTlsDatabase = gTlsDatabase; 83 super(cast(GObject*)gTlsDatabase, ownedRef); 84 } 85 86 87 /** */ 88 public static GType getType() 89 { 90 return g_tls_database_get_type(); 91 } 92 93 /** 94 * Create a handle string for the certificate. The database will only be able 95 * to create a handle for certificates that originate from the database. In 96 * cases where the database cannot create a handle for a certificate, %NULL 97 * will be returned. 98 * 99 * This handle should be stable across various instances of the application, 100 * and between applications. If a certificate is modified in the database, 101 * then it is not guaranteed that this handle will continue to point to it. 102 * 103 * Params: 104 * certificate = certificate for which to create a handle. 105 * 106 * Returns: a newly allocated string containing the 107 * handle. 108 * 109 * Since: 2.30 110 */ 111 public string createCertificateHandle(TlsCertificate certificate) 112 { 113 auto retStr = g_tls_database_create_certificate_handle(gTlsDatabase, (certificate is null) ? null : certificate.getTlsCertificateStruct()); 114 115 scope(exit) Str.freeString(retStr); 116 return Str.toString(retStr); 117 } 118 119 /** 120 * Lookup a certificate by its handle. 121 * 122 * The handle should have been created by calling 123 * g_tls_database_create_certificate_handle() on a #GTlsDatabase object of 124 * the same TLS backend. The handle is designed to remain valid across 125 * instantiations of the database. 126 * 127 * If the handle is no longer valid, or does not point to a certificate in 128 * this database, then %NULL will be returned. 129 * 130 * This function can block, use g_tls_database_lookup_certificate_for_handle_async() to perform 131 * the lookup operation asynchronously. 132 * 133 * Params: 134 * handle = a certificate handle 135 * interaction = used to interact with the user if necessary 136 * flags = Flags which affect the lookup. 137 * cancellable = a #GCancellable, or %NULL 138 * 139 * Returns: a newly allocated 140 * #GTlsCertificate, or %NULL. Use g_object_unref() to release the certificate. 141 * 142 * Since: 2.30 143 * 144 * Throws: GException on failure. 145 */ 146 public TlsCertificate lookupCertificateForHandle(string handle, TlsInteraction interaction, GTlsDatabaseLookupFlags flags, Cancellable cancellable) 147 { 148 GError* err = null; 149 150 auto p = g_tls_database_lookup_certificate_for_handle(gTlsDatabase, Str.toStringz(handle), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 151 152 if (err !is null) 153 { 154 throw new GException( new ErrorG(err) ); 155 } 156 157 if(p is null) 158 { 159 return null; 160 } 161 162 return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p, true); 163 } 164 165 /** 166 * Asynchronously lookup a certificate by its handle in the database. See 167 * g_tls_database_lookup_certificate_for_handle() for more information. 168 * 169 * Params: 170 * handle = a certificate handle 171 * interaction = used to interact with the user if necessary 172 * flags = Flags which affect the lookup. 173 * cancellable = a #GCancellable, or %NULL 174 * callback = callback to call when the operation completes 175 * userData = the data to pass to the callback function 176 * 177 * Since: 2.30 178 */ 179 public void lookupCertificateForHandleAsync(string handle, TlsInteraction interaction, GTlsDatabaseLookupFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 180 { 181 g_tls_database_lookup_certificate_for_handle_async(gTlsDatabase, Str.toStringz(handle), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 182 } 183 184 /** 185 * Finish an asynchronous lookup of a certificate by its handle. See 186 * g_tls_database_lookup_certificate_handle() for more information. 187 * 188 * If the handle is no longer valid, or does not point to a certificate in 189 * this database, then %NULL will be returned. 190 * 191 * Params: 192 * result = a #GAsyncResult. 193 * 194 * Returns: a newly allocated #GTlsCertificate object. 195 * Use g_object_unref() to release the certificate. 196 * 197 * Since: 2.30 198 * 199 * Throws: GException on failure. 200 */ 201 public TlsCertificate lookupCertificateForHandleFinish(AsyncResultIF result) 202 { 203 GError* err = null; 204 205 auto p = g_tls_database_lookup_certificate_for_handle_finish(gTlsDatabase, (result is null) ? null : result.getAsyncResultStruct(), &err); 206 207 if (err !is null) 208 { 209 throw new GException( new ErrorG(err) ); 210 } 211 212 if(p is null) 213 { 214 return null; 215 } 216 217 return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p, true); 218 } 219 220 /** 221 * Lookup the issuer of @certificate in the database. 222 * 223 * The %issuer property 224 * of @certificate is not modified, and the two certificates are not hooked 225 * into a chain. 226 * 227 * This function can block, use g_tls_database_lookup_certificate_issuer_async() to perform 228 * the lookup operation asynchronously. 229 * 230 * Params: 231 * certificate = a #GTlsCertificate 232 * interaction = used to interact with the user if necessary 233 * flags = flags which affect the lookup operation 234 * cancellable = a #GCancellable, or %NULL 235 * 236 * Returns: a newly allocated issuer #GTlsCertificate, 237 * or %NULL. Use g_object_unref() to release the certificate. 238 * 239 * Since: 2.30 240 * 241 * Throws: GException on failure. 242 */ 243 public TlsCertificate lookupCertificateIssuer(TlsCertificate certificate, TlsInteraction interaction, GTlsDatabaseLookupFlags flags, Cancellable cancellable) 244 { 245 GError* err = null; 246 247 auto p = g_tls_database_lookup_certificate_issuer(gTlsDatabase, (certificate is null) ? null : certificate.getTlsCertificateStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 248 249 if (err !is null) 250 { 251 throw new GException( new ErrorG(err) ); 252 } 253 254 if(p is null) 255 { 256 return null; 257 } 258 259 return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p, true); 260 } 261 262 /** 263 * Asynchronously lookup the issuer of @certificate in the database. See 264 * g_tls_database_lookup_certificate_issuer() for more information. 265 * 266 * Params: 267 * certificate = a #GTlsCertificate 268 * interaction = used to interact with the user if necessary 269 * flags = flags which affect the lookup operation 270 * cancellable = a #GCancellable, or %NULL 271 * callback = callback to call when the operation completes 272 * userData = the data to pass to the callback function 273 * 274 * Since: 2.30 275 */ 276 public void lookupCertificateIssuerAsync(TlsCertificate certificate, TlsInteraction interaction, GTlsDatabaseLookupFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 277 { 278 g_tls_database_lookup_certificate_issuer_async(gTlsDatabase, (certificate is null) ? null : certificate.getTlsCertificateStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 279 } 280 281 /** 282 * Finish an asynchronous lookup issuer operation. See 283 * g_tls_database_lookup_certificate_issuer() for more information. 284 * 285 * Params: 286 * result = a #GAsyncResult. 287 * 288 * Returns: a newly allocated issuer #GTlsCertificate, 289 * or %NULL. Use g_object_unref() to release the certificate. 290 * 291 * Since: 2.30 292 * 293 * Throws: GException on failure. 294 */ 295 public TlsCertificate lookupCertificateIssuerFinish(AsyncResultIF result) 296 { 297 GError* err = null; 298 299 auto p = g_tls_database_lookup_certificate_issuer_finish(gTlsDatabase, (result is null) ? null : result.getAsyncResultStruct(), &err); 300 301 if (err !is null) 302 { 303 throw new GException( new ErrorG(err) ); 304 } 305 306 if(p is null) 307 { 308 return null; 309 } 310 311 return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p, true); 312 } 313 314 /** 315 * Lookup certificates issued by this issuer in the database. 316 * 317 * This function can block, use g_tls_database_lookup_certificates_issued_by_async() to perform 318 * the lookup operation asynchronously. 319 * 320 * Params: 321 * issuerRawDn = a #GByteArray which holds the DER encoded issuer DN. 322 * interaction = used to interact with the user if necessary 323 * flags = Flags which affect the lookup operation. 324 * cancellable = a #GCancellable, or %NULL 325 * 326 * Returns: a newly allocated list of #GTlsCertificate 327 * objects. Use g_object_unref() on each certificate, and g_list_free() on the release the list. 328 * 329 * Since: 2.30 330 * 331 * Throws: GException on failure. 332 */ 333 public ListG lookupCertificatesIssuedBy(ByteArray issuerRawDn, TlsInteraction interaction, GTlsDatabaseLookupFlags flags, Cancellable cancellable) 334 { 335 GError* err = null; 336 337 auto p = g_tls_database_lookup_certificates_issued_by(gTlsDatabase, (issuerRawDn is null) ? null : issuerRawDn.getByteArrayStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 338 339 if (err !is null) 340 { 341 throw new GException( new ErrorG(err) ); 342 } 343 344 if(p is null) 345 { 346 return null; 347 } 348 349 return new ListG(cast(GList*) p, true); 350 } 351 352 /** 353 * Asynchronously lookup certificates issued by this issuer in the database. See 354 * g_tls_database_lookup_certificates_issued_by() for more information. 355 * 356 * The database may choose to hold a reference to the issuer byte array for the duration 357 * of of this asynchronous operation. The byte array should not be modified during 358 * this time. 359 * 360 * Params: 361 * issuerRawDn = a #GByteArray which holds the DER encoded issuer DN. 362 * interaction = used to interact with the user if necessary 363 * flags = Flags which affect the lookup operation. 364 * cancellable = a #GCancellable, or %NULL 365 * callback = callback to call when the operation completes 366 * userData = the data to pass to the callback function 367 * 368 * Since: 2.30 369 */ 370 public void lookupCertificatesIssuedByAsync(ByteArray issuerRawDn, TlsInteraction interaction, GTlsDatabaseLookupFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 371 { 372 g_tls_database_lookup_certificates_issued_by_async(gTlsDatabase, (issuerRawDn is null) ? null : issuerRawDn.getByteArrayStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 373 } 374 375 /** 376 * Finish an asynchronous lookup of certificates. See 377 * g_tls_database_lookup_certificates_issued_by() for more information. 378 * 379 * Params: 380 * result = a #GAsyncResult. 381 * 382 * Returns: a newly allocated list of #GTlsCertificate 383 * objects. Use g_object_unref() on each certificate, and g_list_free() on the release the list. 384 * 385 * Since: 2.30 386 * 387 * Throws: GException on failure. 388 */ 389 public ListG lookupCertificatesIssuedByFinish(AsyncResultIF result) 390 { 391 GError* err = null; 392 393 auto p = g_tls_database_lookup_certificates_issued_by_finish(gTlsDatabase, (result is null) ? null : result.getAsyncResultStruct(), &err); 394 395 if (err !is null) 396 { 397 throw new GException( new ErrorG(err) ); 398 } 399 400 if(p is null) 401 { 402 return null; 403 } 404 405 return new ListG(cast(GList*) p, true); 406 } 407 408 /** 409 * Determines the validity of a certificate chain after looking up and 410 * adding any missing certificates to the chain. 411 * 412 * @chain is a chain of #GTlsCertificate objects each pointing to the next 413 * certificate in the chain by its %issuer property. The chain may initially 414 * consist of one or more certificates. After the verification process is 415 * complete, @chain may be modified by adding missing certificates, or removing 416 * extra certificates. If a certificate anchor was found, then it is added to 417 * the @chain. 418 * 419 * @purpose describes the purpose (or usage) for which the certificate 420 * is being used. Typically @purpose will be set to #G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER 421 * which means that the certificate is being used to authenticate a server 422 * (and we are acting as the client). 423 * 424 * The @identity is used to check for pinned certificates (trust exceptions) 425 * in the database. These will override the normal verification process on a 426 * host by host basis. 427 * 428 * Currently there are no @flags, and %G_TLS_DATABASE_VERIFY_NONE should be 429 * used. 430 * 431 * If @chain is found to be valid, then the return value will be 0. If 432 * @chain is found to be invalid, then the return value will indicate 433 * the problems found. If the function is unable to determine whether 434 * @chain is valid or not (eg, because @cancellable is triggered 435 * before it completes) then the return value will be 436 * %G_TLS_CERTIFICATE_GENERIC_ERROR and @error will be set 437 * accordingly. @error is not set when @chain is successfully analyzed 438 * but found to be invalid. 439 * 440 * This function can block, use g_tls_database_verify_chain_async() to perform 441 * the verification operation asynchronously. 442 * 443 * Params: 444 * chain = a #GTlsCertificate chain 445 * purpose = the purpose that this certificate chain will be used for. 446 * identity = the expected peer identity 447 * interaction = used to interact with the user if necessary 448 * flags = additional verify flags 449 * cancellable = a #GCancellable, or %NULL 450 * 451 * Returns: the appropriate #GTlsCertificateFlags which represents the 452 * result of verification. 453 * 454 * Since: 2.30 455 * 456 * Throws: GException on failure. 457 */ 458 public GTlsCertificateFlags verifyChain(TlsCertificate chain, string purpose, SocketConnectableIF identity, TlsInteraction interaction, GTlsDatabaseVerifyFlags flags, Cancellable cancellable) 459 { 460 GError* err = null; 461 462 auto p = g_tls_database_verify_chain(gTlsDatabase, (chain is null) ? null : chain.getTlsCertificateStruct(), Str.toStringz(purpose), (identity is null) ? null : identity.getSocketConnectableStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 463 464 if (err !is null) 465 { 466 throw new GException( new ErrorG(err) ); 467 } 468 469 return p; 470 } 471 472 /** 473 * Asynchronously determines the validity of a certificate chain after 474 * looking up and adding any missing certificates to the chain. See 475 * g_tls_database_verify_chain() for more information. 476 * 477 * Params: 478 * chain = a #GTlsCertificate chain 479 * purpose = the purpose that this certificate chain will be used for. 480 * identity = the expected peer identity 481 * interaction = used to interact with the user if necessary 482 * flags = additional verify flags 483 * cancellable = a #GCancellable, or %NULL 484 * callback = callback to call when the operation completes 485 * userData = the data to pass to the callback function 486 * 487 * Since: 2.30 488 */ 489 public void verifyChainAsync(TlsCertificate chain, string purpose, SocketConnectableIF identity, TlsInteraction interaction, GTlsDatabaseVerifyFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 490 { 491 g_tls_database_verify_chain_async(gTlsDatabase, (chain is null) ? null : chain.getTlsCertificateStruct(), Str.toStringz(purpose), (identity is null) ? null : identity.getSocketConnectableStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 492 } 493 494 /** 495 * Finish an asynchronous verify chain operation. See 496 * g_tls_database_verify_chain() for more information. 497 * 498 * If @chain is found to be valid, then the return value will be 0. If 499 * @chain is found to be invalid, then the return value will indicate 500 * the problems found. If the function is unable to determine whether 501 * @chain is valid or not (eg, because @cancellable is triggered 502 * before it completes) then the return value will be 503 * %G_TLS_CERTIFICATE_GENERIC_ERROR and @error will be set 504 * accordingly. @error is not set when @chain is successfully analyzed 505 * but found to be invalid. 506 * 507 * Params: 508 * result = a #GAsyncResult. 509 * 510 * Returns: the appropriate #GTlsCertificateFlags which represents the 511 * result of verification. 512 * 513 * Since: 2.30 514 * 515 * Throws: GException on failure. 516 */ 517 public GTlsCertificateFlags verifyChainFinish(AsyncResultIF result) 518 { 519 GError* err = null; 520 521 auto p = g_tls_database_verify_chain_finish(gTlsDatabase, (result is null) ? null : result.getAsyncResultStruct(), &err); 522 523 if (err !is null) 524 { 525 throw new GException( new ErrorG(err) ); 526 } 527 528 return p; 529 } 530 }