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