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()
59 	{
60 		return gTlsDatabase;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gTlsDatabase;
67 	}
68 
69 	protected override void setStruct(GObject* obj)
70 	{
71 		gTlsDatabase = cast(GTlsDatabase*)obj;
72 		super.setStruct(obj);
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 	 * Return: 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 	 * Lookup 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 	 * Return: 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 lookup 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_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 	 * Return: 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 	 * Lookup the issuer of @certificate in the database.
220 	 *
221 	 * The %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 	 * Return: 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 lookup 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 	 * Return: 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 	 * Lookup 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 	 * Return: 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 lookup 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 	 * Return: 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 	 * Verify's a certificate chain after looking up and adding any missing
408 	 * 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 %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 	 * This function can block, use g_tls_database_verify_chain_async() to perform
430 	 * the verification operation asynchronously.
431 	 *
432 	 * Params:
433 	 *     chain = a #GTlsCertificate chain
434 	 *     purpose = the purpose that this certificate chain will be used for.
435 	 *     identity = the expected peer identity
436 	 *     interaction = used to interact with the user if necessary
437 	 *     flags = additional verify flags
438 	 *     cancellable = a #GCancellable, or %NULL
439 	 *
440 	 * Return: the appropriate #GTlsCertificateFlags which represents the
441 	 *     result of verification.
442 	 *
443 	 * Since: 2.30
444 	 *
445 	 * Throws: GException on failure.
446 	 */
447 	public GTlsCertificateFlags verifyChain(TlsCertificate chain, string purpose, SocketConnectableIF identity, TlsInteraction interaction, GTlsDatabaseVerifyFlags flags, Cancellable cancellable)
448 	{
449 		GError* err = null;
450 		
451 		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);
452 		
453 		if (err !is null)
454 		{
455 			throw new GException( new ErrorG(err) );
456 		}
457 		
458 		return p;
459 	}
460 
461 	/**
462 	 * Asynchronously verify's a certificate chain after looking up and adding
463 	 * any missing certificates to the chain. See g_tls_database_verify_chain()
464 	 * for more information.
465 	 *
466 	 * Params:
467 	 *     chain = a #GTlsCertificate chain
468 	 *     purpose = the purpose that this certificate chain will be used for.
469 	 *     identity = the expected peer identity
470 	 *     interaction = used to interact with the user if necessary
471 	 *     flags = additional verify flags
472 	 *     cancellable = a #GCancellable, or %NULL
473 	 *     callback = callback to call when the operation completes
474 	 *     userData = the data to pass to the callback function
475 	 *
476 	 * Since: 2.30
477 	 */
478 	public void verifyChainAsync(TlsCertificate chain, string purpose, SocketConnectableIF identity, TlsInteraction interaction, GTlsDatabaseVerifyFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
479 	{
480 		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);
481 	}
482 
483 	/**
484 	 * Finish an asynchronous verify chain operation. See
485 	 * g_tls_database_verify_chain() for more information. *
486 	 *
487 	 * Params:
488 	 *     result = a #GAsyncResult.
489 	 *
490 	 * Return: the appropriate #GTlsCertificateFlags which represents the
491 	 *     result of verification.
492 	 *
493 	 * Since: 2.30
494 	 *
495 	 * Throws: GException on failure.
496 	 */
497 	public GTlsCertificateFlags verifyChainFinish(AsyncResultIF result)
498 	{
499 		GError* err = null;
500 		
501 		auto p = g_tls_database_verify_chain_finish(gTlsDatabase, (result is null) ? null : result.getAsyncResultStruct(), &err);
502 		
503 		if (err !is null)
504 		{
505 			throw new GException( new ErrorG(err) );
506 		}
507 		
508 		return p;
509 	}
510 }