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