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  = GTlsCertificate.html
27  * outPack = gio
28  * outFile = TlsCertificate
29  * strct   = GTlsCertificate
30  * realStrct=
31  * ctorStrct=
32  * clss    = TlsCertificate
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_tls_certificate_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- g_tls_certificate_new_from_file
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- glib.ListG
51  * 	- gio.SocketConnectableIF
52  * structWrap:
53  * 	- GList* -> ListG
54  * 	- GSocketConnectable* -> SocketConnectableIF
55  * 	- GTlsCertificate* -> TlsCertificate
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gio.TlsCertificate;
62 
63 public  import gtkc.giotypes;
64 
65 private import gtkc.gio;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 
70 private import glib.Str;
71 private import glib.ErrorG;
72 private import glib.GException;
73 private import glib.ListG;
74 private import gio.SocketConnectableIF;
75 
76 
77 
78 private import gobject.ObjectG;
79 
80 /**
81  * Description
82  * A certificate used for TLS authentication and encryption.
83  * This can represent either a public key only (eg, the certificate
84  * received by a client from a server), or the combination of
85  * a public key and a private key (which is needed when acting as a
86  * GTlsServerConnection).
87  */
88 public class TlsCertificate : ObjectG
89 {
90 	
91 	/** the main Gtk struct */
92 	protected GTlsCertificate* gTlsCertificate;
93 	
94 	
95 	public GTlsCertificate* getTlsCertificateStruct()
96 	{
97 		return gTlsCertificate;
98 	}
99 	
100 	
101 	/** the main Gtk struct as a void* */
102 	protected override void* getStruct()
103 	{
104 		return cast(void*)gTlsCertificate;
105 	}
106 	
107 	/**
108 	 * Sets our main struct and passes it to the parent class
109 	 */
110 	public this (GTlsCertificate* gTlsCertificate)
111 	{
112 		super(cast(GObject*)gTlsCertificate);
113 		this.gTlsCertificate = gTlsCertificate;
114 	}
115 	
116 	protected override void setStruct(GObject* obj)
117 	{
118 		super.setStruct(obj);
119 		gTlsCertificate = cast(GTlsCertificate*)obj;
120 	}
121 	
122 	/**
123 	 * Description
124 	 * GTlsConnection and related classes provide TLS (Transport Layer
125 	 * Security, previously known as SSL, Secure Sockets Layer) support for
126 	 * gio-based network streams.
127 	 * In the simplest case, for a client connection, you can just set the
128 	 * "tls" flag on a GSocketClient, and then any
129 	 * connections created by that client will have TLS negotiated
130 	 * automatically, using appropriate default settings, and rejecting
131 	 * any invalid or self-signed certificates (unless you change that
132 	 * default by setting the "tls-validation-flags"
133 	 * property). The returned object will be a GTcpWrapperConnection,
134 	 * which wraps the underlying GTlsClientConnection.
135 	 * For greater control, you can create your own GTlsClientConnection,
136 	 * wrapping a GSocketConnection (or an arbitrary GIOStream with
137 	 * pollable input and output streams) and then connect to its signals,
138 	 * such as "accept-certificate", before starting the
139 	 * handshake.
140 	 * Server-side TLS is similar, using GTlsServerConnection. At the
141 	 * moment, there is no support for automatically wrapping server-side
142 	 * connections in the way GSocketClient does for client-side
143 	 * connections.
144 	 */
145 	
146 	/**
147 	 * Creates a new GTlsCertificate from the PEM-encoded data in data.
148 	 * If data includes both a certificate and a private key, then the
149 	 * returned certificate will include the private key data as well.
150 	 * If data includes multiple certificates, only the first one will be
151 	 * parsed.
152 	 * Since 2.28
153 	 * Params:
154 	 * data = PEM-encoded certificate data
155 	 * Throws: GException on failure.
156 	 * Throws: ConstructionException GTK+ fails to create the object.
157 	 */
158 	public this (string data)
159 	{
160 		// GTlsCertificate * g_tls_certificate_new_from_pem (const gchar *data,  gssize length,  GError **error);
161 		GError* err = null;
162 		
163 		auto p = g_tls_certificate_new_from_pem(cast(char*)data.ptr, cast(int) data.length, &err);
164 		
165 		if (err !is null)
166 		{
167 			throw new GException( new ErrorG(err) );
168 		}
169 		
170 		if(p is null)
171 		{
172 			throw new ConstructionException("null returned by g_tls_certificate_new_from_pem(cast(char*)data.ptr, cast(int) data.length, &err)");
173 		}
174 		this(cast(GTlsCertificate*) p);
175 	}
176 	
177 	/**
178 	 * Creates a GTlsCertificate from the PEM-encoded data in cert_file
179 	 * and key_file. If either file cannot be read or parsed, the
180 	 * function will return NULL and set error. Otherwise, this behaves
181 	 * like g_tls_certificate_new().
182 	 * Since 2.28
183 	 * Params:
184 	 * certFile = file containing a PEM-encoded certificate to import
185 	 * keyFile = file containing a PEM-encoded private key to import
186 	 * Throws: GException on failure.
187 	 * Throws: ConstructionException GTK+ fails to create the object.
188 	 */
189 	public this (string certFile, string keyFile)
190 	{
191 		// GTlsCertificate * g_tls_certificate_new_from_files (const gchar *cert_file,  const gchar *key_file,  GError **error);
192 		GError* err = null;
193 		
194 		auto p = g_tls_certificate_new_from_files(Str.toStringz(certFile), Str.toStringz(keyFile), &err);
195 		
196 		if (err !is null)
197 		{
198 			throw new GException( new ErrorG(err) );
199 		}
200 		
201 		if(p is null)
202 		{
203 			throw new ConstructionException("null returned by g_tls_certificate_new_from_files(Str.toStringz(certFile), Str.toStringz(keyFile), &err)");
204 		}
205 		this(cast(GTlsCertificate*) p);
206 	}
207 	
208 	/**
209 	 * Creates one or more GTlsCertificates from the PEM-encoded
210 	 * data in file. If file cannot be read or parsed, the function will
211 	 * return NULL and set error. If file does not contain any
212 	 * PEM-encoded certificates, this will return an empty list and not
213 	 * set error.
214 	 * Since 2.28
215 	 * Params:
216 	 * file = file containing PEM-encoded certificates to import
217 	 * Returns: a GList containing GTlsCertificate objects. You must free the list and its contents when you are done with it. [element-type Gio.TlsCertificate][transfer full]
218 	 * Throws: GException on failure.
219 	 */
220 	public static ListG listNewFromFile(string file)
221 	{
222 		// GList * g_tls_certificate_list_new_from_file  (const gchar *file,  GError **error);
223 		GError* err = null;
224 		
225 		auto p = g_tls_certificate_list_new_from_file(Str.toStringz(file), &err);
226 		
227 		if (err !is null)
228 		{
229 			throw new GException( new ErrorG(err) );
230 		}
231 		
232 		
233 		if(p is null)
234 		{
235 			return null;
236 		}
237 		
238 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
239 	}
240 	
241 	/**
242 	 * Gets the GTlsCertificate representing cert's issuer, if known
243 	 * Since 2.28
244 	 * Returns: The certificate of cert's issuer, or NULL if cert is self-signed or signed with an unknown certificate. [transfer none]
245 	 */
246 	public TlsCertificate getIssuer()
247 	{
248 		// GTlsCertificate * g_tls_certificate_get_issuer (GTlsCertificate *cert);
249 		auto p = g_tls_certificate_get_issuer(gTlsCertificate);
250 		
251 		if(p is null)
252 		{
253 			return null;
254 		}
255 		
256 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
257 	}
258 	
259 	/**
260 	 * This verifies cert and returns a set of GTlsCertificateFlags
261 	 * indicating any problems found with it. This can be used to verify a
262 	 * certificate outside the context of making a connection, or to
263 	 * check a certificate against a CA that is not part of the system
264 	 * CA database.
265 	 * If identity is not NULL, cert's name(s) will be compared against
266 	 * it, and G_TLS_CERTIFICATE_BAD_IDENTITY will be set in the return
267 	 * value if it does not match. If identity is NULL, that bit will
268 	 * never be set in the return value.
269 	 * If trusted_ca is not NULL, then cert (or one of the certificates
270 	 * in its chain) must be signed by it, or else
271 	 * G_TLS_CERTIFICATE_UNKNOWN_CA will be set in the return value. If
272 	 * trusted_ca is NULL, that bit will never be set in the return
273 	 * value.
274 	 * (All other GTlsCertificateFlags values will always be set or unset
275 	 * as appropriate.)
276 	 * Since 2.28
277 	 * Params:
278 	 * identity = the expected peer identity. [allow-none]
279 	 * trustedCa = the certificate of a trusted authority. [allow-none]
280 	 * Returns: the appropriate GTlsCertificateFlags
281 	 */
282 	public GTlsCertificateFlags verify(SocketConnectableIF identity, TlsCertificate trustedCa)
283 	{
284 		// GTlsCertificateFlags g_tls_certificate_verify (GTlsCertificate *cert,  GSocketConnectable *identity,  GTlsCertificate *trusted_ca);
285 		return g_tls_certificate_verify(gTlsCertificate, (identity is null) ? null : identity.getSocketConnectableTStruct(), (trustedCa is null) ? null : trustedCa.getTlsCertificateStruct());
286 	}
287 }