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