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