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 private import glib.Str;
70 private import glib.ErrorG;
71 private import glib.GException;
72 private import glib.ListG;
73 private import gio.SocketConnectableIF;
74 
75 
76 private import gobject.ObjectG;
77 
78 /**
79  * A certificate used for TLS authentication and encryption.
80  * This can represent either a certificate only (eg, the certificate
81  * received by a client from a server), or the combination of
82  * a certificate and a private key (which is needed when acting as a
83  * GTlsServerConnection).
84  */
85 public class TlsCertificate : ObjectG
86 {
87 	
88 	/** the main Gtk struct */
89 	protected GTlsCertificate* gTlsCertificate;
90 	
91 	
92 	/** Get the main Gtk struct */
93 	public GTlsCertificate* getTlsCertificateStruct()
94 	{
95 		return gTlsCertificate;
96 	}
97 	
98 	
99 	/** the main Gtk struct as a void* */
100 	protected override void* getStruct()
101 	{
102 		return cast(void*)gTlsCertificate;
103 	}
104 	
105 	/**
106 	 * Sets our main struct and passes it to the parent class
107 	 */
108 	public this (GTlsCertificate* gTlsCertificate)
109 	{
110 		super(cast(GObject*)gTlsCertificate);
111 		this.gTlsCertificate = gTlsCertificate;
112 	}
113 	
114 	protected override void setStruct(GObject* obj)
115 	{
116 		super.setStruct(obj);
117 		gTlsCertificate = cast(GTlsCertificate*)obj;
118 	}
119 	
120 	/**
121 	 * GTlsConnection and related classes provide TLS (Transport Layer
122 	 * Security, previously known as SSL, Secure Sockets Layer) support for
123 	 * gio-based network streams.
124 	 *
125 	 * In the simplest case, for a client connection, you can just set the
126 	 * "tls" flag on a GSocketClient, and then any
127 	 * connections created by that client will have TLS negotiated
128 	 * automatically, using appropriate default settings, and rejecting
129 	 * any invalid or self-signed certificates (unless you change that
130 	 * default by setting the "tls-validation-flags"
131 	 * property). The returned object will be a GTcpWrapperConnection,
132 	 * which wraps the underlying GTlsClientConnection.
133 	 *
134 	 * For greater control, you can create your own GTlsClientConnection,
135 	 * wrapping a GSocketConnection (or an arbitrary GIOStream with
136 	 * pollable input and output streams) and then connect to its signals,
137 	 * such as "accept-certificate", before starting the
138 	 * handshake.
139 	 *
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. (See
150 	 * the "private-key-pem" property for information about
151 	 * supported formats.)
152 	 * If data includes multiple certificates, only the first one will be
153 	 * parsed.
154 	 * Since 2.28
155 	 * Params:
156 	 * data = PEM-encoded certificate data
157 	 * Throws: GException on failure.
158 	 * Throws: ConstructionException GTK+ fails to create the object.
159 	 */
160 	public this (string data)
161 	{
162 		// GTlsCertificate * g_tls_certificate_new_from_pem (const gchar *data,  gssize length,  GError **error);
163 		GError* err = null;
164 		
165 		auto p = g_tls_certificate_new_from_pem(cast(char*)data.ptr, cast(int) data.length, &err);
166 		
167 		if (err !is null)
168 		{
169 			throw new GException( new ErrorG(err) );
170 		}
171 		
172 		if(p is null)
173 		{
174 			throw new ConstructionException("null returned by g_tls_certificate_new_from_pem(cast(char*)data.ptr, cast(int) data.length, &err)");
175 		}
176 		this(cast(GTlsCertificate*) p);
177 	}
178 	
179 	/**
180 	 * Creates a GTlsCertificate from the PEM-encoded data in cert_file
181 	 * and key_file. If either file cannot be read or parsed, the
182 	 * function will return NULL and set error. Otherwise, this behaves
183 	 * like g_tls_certificate_new_from_pem().
184 	 * Since 2.28
185 	 * Params:
186 	 * certFile = file containing a PEM-encoded certificate to import
187 	 * keyFile = file containing a PEM-encoded private key to import
188 	 * Throws: GException on failure.
189 	 * Throws: ConstructionException GTK+ fails to create the object.
190 	 */
191 	public this (string certFile, string keyFile)
192 	{
193 		// GTlsCertificate * g_tls_certificate_new_from_files (const gchar *cert_file,  const gchar *key_file,  GError **error);
194 		GError* err = null;
195 		
196 		auto p = g_tls_certificate_new_from_files(Str.toStringz(certFile), Str.toStringz(keyFile), &err);
197 		
198 		if (err !is null)
199 		{
200 			throw new GException( new ErrorG(err) );
201 		}
202 		
203 		if(p is null)
204 		{
205 			throw new ConstructionException("null returned by g_tls_certificate_new_from_files(Str.toStringz(certFile), Str.toStringz(keyFile), &err)");
206 		}
207 		this(cast(GTlsCertificate*) p);
208 	}
209 	
210 	/**
211 	 * Creates one or more GTlsCertificates from the PEM-encoded
212 	 * data in file. If file cannot be read or parsed, the function will
213 	 * return NULL and set error. If file does not contain any
214 	 * PEM-encoded certificates, this will return an empty list and not
215 	 * set error.
216 	 * Since 2.28
217 	 * Params:
218 	 * file = file containing PEM-encoded certificates to import
219 	 * 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]
220 	 * Throws: GException on failure.
221 	 */
222 	public static ListG listNewFromFile(string file)
223 	{
224 		// GList * g_tls_certificate_list_new_from_file  (const gchar *file,  GError **error);
225 		GError* err = null;
226 		
227 		auto p = g_tls_certificate_list_new_from_file(Str.toStringz(file), &err);
228 		
229 		if (err !is null)
230 		{
231 			throw new GException( new ErrorG(err) );
232 		}
233 		
234 		
235 		if(p is null)
236 		{
237 			return null;
238 		}
239 		
240 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
241 	}
242 	
243 	/**
244 	 * Gets the GTlsCertificate representing cert's issuer, if known
245 	 * Since 2.28
246 	 * Returns: The certificate of cert's issuer, or NULL if cert is self-signed or signed with an unknown certificate. [transfer none]
247 	 */
248 	public TlsCertificate getIssuer()
249 	{
250 		// GTlsCertificate * g_tls_certificate_get_issuer (GTlsCertificate *cert);
251 		auto p = g_tls_certificate_get_issuer(gTlsCertificate);
252 		
253 		if(p is null)
254 		{
255 			return null;
256 		}
257 		
258 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
259 	}
260 	
261 	/**
262 	 * This verifies cert and returns a set of GTlsCertificateFlags
263 	 * indicating any problems found with it. This can be used to verify a
264 	 * certificate outside the context of making a connection, or to
265 	 * check a certificate against a CA that is not part of the system
266 	 * CA database.
267 	 * If identity is not NULL, cert's name(s) will be compared against
268 	 * it, and G_TLS_CERTIFICATE_BAD_IDENTITY will be set in the return
269 	 * value if it does not match. If identity is NULL, that bit will
270 	 * never be set in the return value.
271 	 * If trusted_ca is not NULL, then cert (or one of the certificates
272 	 * in its chain) must be signed by it, or else
273 	 * G_TLS_CERTIFICATE_UNKNOWN_CA will be set in the return value. If
274 	 * trusted_ca is NULL, that bit will never be set in the return
275 	 * value.
276 	 * (All other GTlsCertificateFlags values will always be set or unset
277 	 * as appropriate.)
278 	 * Since 2.28
279 	 * Params:
280 	 * identity = the expected peer identity. [allow-none]
281 	 * trustedCa = the certificate of a trusted authority. [allow-none]
282 	 * Returns: the appropriate GTlsCertificateFlags
283 	 */
284 	public GTlsCertificateFlags verify(SocketConnectableIF identity, TlsCertificate trustedCa)
285 	{
286 		// GTlsCertificateFlags g_tls_certificate_verify (GTlsCertificate *cert,  GSocketConnectable *identity,  GTlsCertificate *trusted_ca);
287 		return g_tls_certificate_verify(gTlsCertificate, (identity is null) ? null : identity.getSocketConnectableTStruct(), (trustedCa is null) ? null : trustedCa.getTlsCertificateStruct());
288 	}
289 	
290 	/**
291 	 * Check if two GTlsCertificate objects represent the same certificate.
292 	 * The raw DER byte data of the two certificates are checked for equality.
293 	 * This has the effect that two certificates may compare equal even if
294 	 * their "issuer", "private-key", or
295 	 * "private-key-pem" properties differ.
296 	 * Since 2.34
297 	 * Params:
298 	 * certTwo = second certificate to compare
299 	 * Returns: whether the same or not
300 	 */
301 	public int isSame(TlsCertificate certTwo)
302 	{
303 		// gboolean g_tls_certificate_is_same (GTlsCertificate *cert_one,  GTlsCertificate *cert_two);
304 		return g_tls_certificate_is_same(gTlsCertificate, (certTwo is null) ? null : certTwo.getTlsCertificateStruct());
305 	}
306 }