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