1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU Lesser General Public
9 * License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
24 #error "Only <camel/camel.h> can be included directly."
27 #ifndef CAMEL_CIPHER_CONTEXT_H
28 #define CAMEL_CIPHER_CONTEXT_H
30 #include <camel/camel-mime-part.h>
31 #include <camel/camel-session.h>
33 /* Standard GObject macros */
34 #define CAMEL_TYPE_CIPHER_CONTEXT \
35 (camel_cipher_context_get_type ())
36 #define CAMEL_CIPHER_CONTEXT(obj) \
37 (G_TYPE_CHECK_INSTANCE_CAST \
38 ((obj), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContext))
39 #define CAMEL_CIPHER_CONTEXT_CLASS(cls) \
40 (G_TYPE_CHECK_CLASS_CAST \
41 ((cls), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContextClass))
42 #define CAMEL_IS_CIPHER_CONTEXT(obj) \
43 (G_TYPE_CHECK_INSTANCE_TYPE \
44 ((obj), CAMEL_TYPE_CIPHER_CONTEXT))
45 #define CAMEL_IS_CIPHER_CONTEXT_CLASS(cls) \
46 (G_TYPE_CHECK_CLASS_TYPE \
47 ((cls), CAMEL_TYPE_CIPHER_CONTEXT))
48 #define CAMEL_CIPHER_CONTEXT_GET_CLASS(obj) \
49 (G_TYPE_INSTANCE_GET_CLASS \
50 ((obj), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContextClass))
54 typedef struct _CamelCipherValidity CamelCipherValidity;
55 typedef struct _CamelCipherCertInfo CamelCipherCertInfo;
57 typedef struct _CamelCipherContext CamelCipherContext;
58 typedef struct _CamelCipherContextClass CamelCipherContextClass;
59 typedef struct _CamelCipherContextPrivate CamelCipherContextPrivate;
62 CAMEL_CIPHER_HASH_DEFAULT,
63 CAMEL_CIPHER_HASH_MD2,
64 CAMEL_CIPHER_HASH_MD5,
65 CAMEL_CIPHER_HASH_SHA1,
66 CAMEL_CIPHER_HASH_SHA256,
67 CAMEL_CIPHER_HASH_SHA384,
68 CAMEL_CIPHER_HASH_SHA512,
69 CAMEL_CIPHER_HASH_RIPEMD160,
70 CAMEL_CIPHER_HASH_TIGER192,
71 CAMEL_CIPHER_HASH_HAVAL5160
74 typedef enum _camel_cipher_validity_sign_t {
75 CAMEL_CIPHER_VALIDITY_SIGN_NONE,
76 CAMEL_CIPHER_VALIDITY_SIGN_GOOD,
77 CAMEL_CIPHER_VALIDITY_SIGN_BAD,
78 CAMEL_CIPHER_VALIDITY_SIGN_UNKNOWN,
79 CAMEL_CIPHER_VALIDITY_SIGN_NEED_PUBLIC_KEY
80 } camel_cipher_validity_sign_t;
82 typedef enum _camel_cipher_validity_encrypt_t {
83 CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE,
84 CAMEL_CIPHER_VALIDITY_ENCRYPT_WEAK,
85 CAMEL_CIPHER_VALIDITY_ENCRYPT_ENCRYPTED, /* encrypted, unknown strenght */
86 CAMEL_CIPHER_VALIDITY_ENCRYPT_STRONG
87 } camel_cipher_validity_encrypt_t;
89 typedef enum _camel_cipher_validity_mode_t {
90 CAMEL_CIPHER_VALIDITY_SIGN,
91 CAMEL_CIPHER_VALIDITY_ENCRYPT
92 } camel_cipher_validity_mode_t;
94 struct _CamelCipherCertInfo {
95 gchar *name; /* common name */
98 gpointer cert_data; /* custom certificate data; can be NULL */
99 void (*cert_data_free) (gpointer cert_data); /* called to free cert_data; can be NULL only if cert_data is NULL */
100 gpointer (*cert_data_clone) (gpointer cert_data); /* called to clone cert_data; can be NULL only if cert_data is NULL */
103 struct _CamelCipherValidity {
107 enum _camel_cipher_validity_sign_t status;
109 GQueue signers; /* CamelCipherCertInfo's */
113 enum _camel_cipher_validity_encrypt_t status;
115 GQueue encrypters; /* CamelCipherCertInfo's */
119 struct _CamelCipherContext {
121 CamelCipherContextPrivate *priv;
124 struct _CamelCipherContextClass {
125 CamelObjectClass parent_class;
127 /* these MUST be set by implementors */
128 const gchar *sign_protocol;
129 const gchar *encrypt_protocol;
130 const gchar *key_protocol;
132 /* Non-Blocking Methods */
133 CamelCipherHash (*id_to_hash) (CamelCipherContext *context,
135 const gchar * (*hash_to_id) (CamelCipherContext *context,
136 CamelCipherHash hash);
138 /* Synchronous I/O Methods */
139 gboolean (*sign_sync) (CamelCipherContext *context,
141 CamelCipherHash hash,
142 CamelMimePart *ipart,
143 CamelMimePart *opart,
144 GCancellable *cancellable,
146 CamelCipherValidity *
147 (*verify_sync) (CamelCipherContext *context,
148 CamelMimePart *ipart,
149 GCancellable *cancellable,
151 gboolean (*encrypt_sync) (CamelCipherContext *context,
153 GPtrArray *recipients,
154 CamelMimePart *ipart,
155 CamelMimePart *opart,
156 GCancellable *cancellable,
158 CamelCipherValidity *
159 (*decrypt_sync) (CamelCipherContext *context,
160 CamelMimePart *ipart,
161 CamelMimePart *opart,
162 GCancellable *cancellable,
164 gboolean (*import_keys_sync) (CamelCipherContext *context,
165 CamelStream *istream,
166 GCancellable *cancellable,
168 gboolean (*export_keys_sync) (CamelCipherContext *context,
170 CamelStream *ostream,
171 GCancellable *cancellable,
174 /* Asynchronous I/O Methods (all have defaults) */
175 void (*sign) (CamelCipherContext *context,
177 CamelCipherHash hash,
178 CamelMimePart *ipart,
179 CamelMimePart *opart,
181 GCancellable *cancellable,
182 GAsyncReadyCallback callback,
184 gboolean (*sign_finish) (CamelCipherContext *context,
185 GAsyncResult *result,
187 void (*verify) (CamelCipherContext *context,
188 CamelMimePart *ipart,
190 GCancellable *cancellable,
191 GAsyncReadyCallback callback,
193 CamelCipherValidity *
194 (*verify_finish) (CamelCipherContext *context,
195 GAsyncResult *result,
197 void (*encrypt) (CamelCipherContext *context,
198 const gchar *user_id,
199 GPtrArray *recipients,
200 CamelMimePart *ipart,
201 CamelMimePart *opart,
203 GCancellable *cancellable,
204 GAsyncReadyCallback callback,
206 gboolean (*encrypt_finish) (CamelCipherContext *context,
207 GAsyncResult *result,
209 void (*decrypt) (CamelCipherContext *context,
210 CamelMimePart *ipart,
211 CamelMimePart *opart,
213 GCancellable *cancellable,
214 GAsyncReadyCallback callback,
216 CamelCipherValidity *
217 (*decrypt_finish) (CamelCipherContext *context,
218 GAsyncResult *result,
220 void (*import_keys) (CamelCipherContext *context,
221 CamelStream *istream,
223 GCancellable *cancellable,
224 GAsyncReadyCallback callback,
226 gboolean (*import_keys_finish) (CamelCipherContext *context,
227 GAsyncResult *result,
229 void (*export_keys) (CamelCipherContext *context,
231 CamelStream *ostream,
233 GCancellable *cancellable,
234 GAsyncReadyCallback callback,
236 gboolean (*export_keys_finish) (CamelCipherContext *context,
237 GAsyncResult *result,
241 GType camel_cipher_context_get_type (void);
243 camel_cipher_context_new (CamelSession *session);
244 CamelSession * camel_cipher_context_get_session
245 (CamelCipherContext *context);
247 /* cipher context util routines */
248 CamelCipherHash camel_cipher_context_id_to_hash (CamelCipherContext *context,
250 const gchar * camel_cipher_context_hash_to_id (CamelCipherContext *context,
251 CamelCipherHash hash);
254 * There are some inconsistencies here, the api's should probably handle CamelMimePart's as input/outputs,
255 * Something that might generate a multipart/signed should do it as part of that processing, internally
256 * to the cipher, etc etc. */
258 /* cipher routines */
259 gboolean camel_cipher_context_sign_sync (CamelCipherContext *context,
261 CamelCipherHash hash,
262 CamelMimePart *ipart,
263 CamelMimePart *opart,
264 GCancellable *cancellable,
266 void camel_cipher_context_sign (CamelCipherContext *context,
268 CamelCipherHash hash,
269 CamelMimePart *ipart,
270 CamelMimePart *opart,
272 GCancellable *cancellable,
273 GAsyncReadyCallback callback,
275 gboolean camel_cipher_context_sign_finish
276 (CamelCipherContext *context,
277 GAsyncResult *result,
279 CamelCipherValidity *
280 camel_cipher_context_verify_sync
281 (CamelCipherContext *context,
282 CamelMimePart *ipart,
283 GCancellable *cancellable,
285 void camel_cipher_context_verify (CamelCipherContext *context,
286 CamelMimePart *ipart,
288 GCancellable *cancellable,
289 GAsyncReadyCallback callback,
291 CamelCipherValidity *
292 camel_cipher_context_verify_finish
293 (CamelCipherContext *context,
294 GAsyncResult *result,
296 gboolean camel_cipher_context_encrypt_sync
297 (CamelCipherContext *context,
299 GPtrArray *recipients,
300 CamelMimePart *ipart,
301 CamelMimePart *opart,
302 GCancellable *cancellable,
304 void camel_cipher_context_encrypt (CamelCipherContext *context,
306 GPtrArray *recipients,
307 CamelMimePart *ipart,
308 CamelMimePart *opart,
310 GCancellable *cancellable,
311 GAsyncReadyCallback callback,
313 gboolean camel_cipher_context_encrypt_finish
314 (CamelCipherContext *context,
315 GAsyncResult *result,
317 CamelCipherValidity *
318 camel_cipher_context_decrypt_sync
319 (CamelCipherContext *context,
320 CamelMimePart *ipart,
321 CamelMimePart *opart,
322 GCancellable *cancellable,
324 void camel_cipher_context_decrypt (CamelCipherContext *context,
325 CamelMimePart *ipart,
326 CamelMimePart *opart,
328 GCancellable *cancellable,
329 GAsyncReadyCallback callback,
331 CamelCipherValidity *
332 camel_cipher_context_decrypt_finish
333 (CamelCipherContext *context,
334 GAsyncResult *result,
337 /* key/certificate routines */
338 gboolean camel_cipher_context_import_keys_sync
339 (CamelCipherContext *context,
340 CamelStream *istream,
341 GCancellable *cancellable,
343 void camel_cipher_context_import_keys
344 (CamelCipherContext *context,
345 CamelStream *istream,
347 GCancellable *cancellable,
348 GAsyncReadyCallback callback,
350 gboolean camel_cipher_context_import_keys_finish
351 (CamelCipherContext *context,
352 GAsyncResult *result,
354 gboolean camel_cipher_context_export_keys_sync
355 (CamelCipherContext *context,
357 CamelStream *ostream,
358 GCancellable *cancellable,
360 void camel_cipher_context_export_keys
361 (CamelCipherContext *context,
363 CamelStream *ostream,
365 GCancellable *cancellable,
366 GAsyncReadyCallback callback,
368 gboolean camel_cipher_context_export_keys_finish
369 (CamelCipherContext *context,
370 GAsyncResult *result,
373 /* CamelCipherValidity utility functions */
374 CamelCipherValidity *
375 camel_cipher_validity_new (void);
376 void camel_cipher_validity_init (CamelCipherValidity *validity);
377 gboolean camel_cipher_validity_get_valid (CamelCipherValidity *validity);
378 void camel_cipher_validity_set_valid (CamelCipherValidity *validity,
380 gchar * camel_cipher_validity_get_description
381 (CamelCipherValidity *validity);
382 void camel_cipher_validity_set_description
383 (CamelCipherValidity *validity,
384 const gchar *description);
385 void camel_cipher_validity_clear (CamelCipherValidity *validity);
386 CamelCipherValidity *
387 camel_cipher_validity_clone (CamelCipherValidity *vin);
388 void camel_cipher_validity_add_certinfo
389 (CamelCipherValidity *vin,
390 camel_cipher_validity_mode_t mode,
393 void camel_cipher_validity_add_certinfo_ex (
394 CamelCipherValidity *vin,
395 camel_cipher_validity_mode_t mode,
399 void (*cert_data_free) (gpointer cert_data),
400 gpointer (*cert_data_clone) (gpointer cert_data));
401 void camel_cipher_validity_envelope (CamelCipherValidity *parent,
402 CamelCipherValidity *valid);
403 void camel_cipher_validity_free (CamelCipherValidity *validity);
405 /* utility functions */
406 gint camel_cipher_canonical_to_stream
407 (CamelMimePart *part,
409 CamelStream *ostream,
410 GCancellable *cancellable,
415 #endif /* CAMEL_CIPHER_CONTEXT_H */