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