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