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 gobject.ObjectG;
40 public  import gtkc.giotypes;
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 check for pinned certificates (trust exceptions)
423 	 * in the database. These will override the normal verification process on a
424 	 * host by host basis.
425 	 *
426 	 * Currently there are no @flags, and %G_TLS_DATABASE_VERIFY_NONE should be
427 	 * used.
428 	 *
429 	 * If @chain is found to be valid, then the return value will be 0. If
430 	 * @chain is found to be invalid, then the return value will indicate
431 	 * the problems found. If the function is unable to determine whether
432 	 * @chain is valid or not (eg, because @cancellable is triggered
433 	 * before it completes) then the return value will be
434 	 * %G_TLS_CERTIFICATE_GENERIC_ERROR and @error will be set
435 	 * accordingly. @error is not set when @chain is successfully analyzed
436 	 * but found to be invalid.
437 	 *
438 	 * This function can block, use g_tls_database_verify_chain_async() to perform
439 	 * the verification operation asynchronously.
440 	 *
441 	 * Params:
442 	 *     chain = a #GTlsCertificate chain
443 	 *     purpose = the purpose that this certificate chain will be used for.
444 	 *     identity = the expected peer identity
445 	 *     interaction = used to interact with the user if necessary
446 	 *     flags = additional verify flags
447 	 *     cancellable = a #GCancellable, or %NULL
448 	 *
449 	 * Returns: the appropriate #GTlsCertificateFlags which represents the
450 	 *     result of verification.
451 	 *
452 	 * Since: 2.30
453 	 *
454 	 * Throws: GException on failure.
455 	 */
456 	public GTlsCertificateFlags verifyChain(TlsCertificate chain, string purpose, SocketConnectableIF identity, TlsInteraction interaction, GTlsDatabaseVerifyFlags flags, Cancellable cancellable)
457 	{
458 		GError* err = null;
459 
460 		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);
461 
462 		if (err !is null)
463 		{
464 			throw new GException( new ErrorG(err) );
465 		}
466 
467 		return __p;
468 	}
469 
470 	/**
471 	 * Asynchronously determines the validity of a certificate chain after
472 	 * looking up and adding any missing certificates to the chain. See
473 	 * g_tls_database_verify_chain() for more information.
474 	 *
475 	 * Params:
476 	 *     chain = a #GTlsCertificate chain
477 	 *     purpose = the purpose that this certificate chain will be used for.
478 	 *     identity = the expected peer identity
479 	 *     interaction = used to interact with the user if necessary
480 	 *     flags = additional verify flags
481 	 *     cancellable = a #GCancellable, or %NULL
482 	 *     callback = callback to call when the operation completes
483 	 *     userData = the data to pass to the callback function
484 	 *
485 	 * Since: 2.30
486 	 */
487 	public void verifyChainAsync(TlsCertificate chain, string purpose, SocketConnectableIF identity, TlsInteraction interaction, GTlsDatabaseVerifyFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
488 	{
489 		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);
490 	}
491 
492 	/**
493 	 * Finish an asynchronous verify chain operation. See
494 	 * g_tls_database_verify_chain() for more information.
495 	 *
496 	 * If @chain is found to be valid, then the return value will be 0. If
497 	 * @chain is found to be invalid, then the return value will indicate
498 	 * the problems found. If the function is unable to determine whether
499 	 * @chain is valid or not (eg, because @cancellable is triggered
500 	 * before it completes) then the return value will be
501 	 * %G_TLS_CERTIFICATE_GENERIC_ERROR and @error will be set
502 	 * accordingly. @error is not set when @chain is successfully analyzed
503 	 * but found to be invalid.
504 	 *
505 	 * Params:
506 	 *     result = a #GAsyncResult.
507 	 *
508 	 * Returns: the appropriate #GTlsCertificateFlags which represents the
509 	 *     result of verification.
510 	 *
511 	 * Since: 2.30
512 	 *
513 	 * Throws: GException on failure.
514 	 */
515 	public GTlsCertificateFlags verifyChainFinish(AsyncResultIF result)
516 	{
517 		GError* err = null;
518 
519 		auto __p = g_tls_database_verify_chain_finish(gTlsDatabase, (result is null) ? null : result.getAsyncResultStruct(), &err);
520 
521 		if (err !is null)
522 		{
523 			throw new GException( new ErrorG(err) );
524 		}
525 
526 		return __p;
527 	}
528 }