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