1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2001 Ximian, Inc. (www.ximian.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 #ifndef CAMEL_CIPHER_CONTEXT_H
24 #define CAMEL_CIPHER_CONTEXT_H
26 #include <camel/camel-session.h>
27 #include <camel/camel-exception.h>
30 #include <libedataserver/e-msgport.h>
32 #define CAMEL_CIPHER_CONTEXT_TYPE (camel_cipher_context_get_type ())
33 #define CAMEL_CIPHER_CONTEXT(obj) (CAMEL_CHECK_CAST((obj), CAMEL_CIPHER_CONTEXT_TYPE, CamelCipherContext))
34 #define CAMEL_CIPHER_CONTEXT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_CIPHER_CONTEXT_TYPE, CamelCipherContextClass))
35 #define CAMEL_IS_CIPHER_CONTEXT(o) (CAMEL_CHECK_TYPE((o), CAMEL_CIPHER_CONTEXT_TYPE))
40 struct _CamelMimePart;
42 typedef struct _CamelCipherValidity CamelCipherValidity;
43 typedef struct _CamelCipherCertInfo CamelCipherCertInfo;
46 CAMEL_CIPHER_HASH_DEFAULT,
47 CAMEL_CIPHER_HASH_MD2,
48 CAMEL_CIPHER_HASH_MD5,
49 CAMEL_CIPHER_HASH_SHA1,
50 CAMEL_CIPHER_HASH_RIPEMD160,
51 CAMEL_CIPHER_HASH_TIGER192,
52 CAMEL_CIPHER_HASH_HAVAL5160
55 typedef enum _camel_cipher_validity_sign_t {
56 CAMEL_CIPHER_VALIDITY_SIGN_NONE,
57 CAMEL_CIPHER_VALIDITY_SIGN_GOOD,
58 CAMEL_CIPHER_VALIDITY_SIGN_BAD,
59 CAMEL_CIPHER_VALIDITY_SIGN_UNKNOWN,
60 CAMEL_CIPHER_VALIDITY_SIGN_NEED_PUBLIC_KEY,
61 } camel_cipher_validity_sign_t;
63 typedef enum _camel_cipher_validity_encrypt_t {
64 CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE,
65 CAMEL_CIPHER_VALIDITY_ENCRYPT_WEAK,
66 CAMEL_CIPHER_VALIDITY_ENCRYPT_ENCRYPTED, /* encrypted, unknown strenght */
67 CAMEL_CIPHER_VALIDITY_ENCRYPT_STRONG,
68 } camel_cipher_validity_encrypt_t;
70 typedef enum _camel_cipher_validity_mode_t {
71 CAMEL_CIPHER_VALIDITY_SIGN,
72 CAMEL_CIPHER_VALIDITY_ENCRYPT,
73 } camel_cipher_validity_mode_t;
75 struct _CamelCipherCertInfo {
76 struct _CamelCipherCertInfo *next;
77 struct _CamelCipherCertInfo *prev;
79 char *name; /* common name */
83 struct _CamelCipherValidity {
84 struct _CamelCipherValidity *next;
85 struct _CamelCipherValidity *prev;
89 enum _camel_cipher_validity_sign_t status;
91 EDList signers; /* CamelCipherCertInfo's */
94 enum _camel_cipher_validity_encrypt_t status;
96 EDList encrypters; /* CamelCipherCertInfo's */
100 typedef struct _CamelCipherContext {
101 CamelObject parent_object;
103 struct _CamelCipherContextPrivate *priv;
105 CamelSession *session;
107 /* these MUST be set by implementors */
108 const char *sign_protocol;
109 const char *encrypt_protocol;
110 const char *key_protocol;
111 } CamelCipherContext;
113 typedef struct _CamelCipherContextClass {
114 CamelObjectClass parent_class;
116 CamelCipherHash (*id_to_hash)(CamelCipherContext *context, const char *id);
117 const char * (*hash_to_id)(CamelCipherContext *context, CamelCipherHash hash);
119 int (*sign) (CamelCipherContext *context, const char *userid, CamelCipherHash hash,
120 struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex);
122 CamelCipherValidity * (*verify) (CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex);
124 int (*encrypt) (CamelCipherContext *context, const char *userid,
125 GPtrArray *recipients, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
128 CamelCipherValidity *(*decrypt) (CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
131 int (*import_keys) (CamelCipherContext *context, struct _CamelStream *istream,
134 int (*export_keys) (CamelCipherContext *context, GPtrArray *keys,
135 struct _CamelStream *ostream, CamelException *ex);
136 } CamelCipherContextClass;
138 CamelType camel_cipher_context_get_type (void);
140 CamelCipherContext *camel_cipher_context_new (CamelSession *session);
142 void camel_cipher_context_construct (CamelCipherContext *context, CamelSession *session);
144 /* cipher context util routines */
145 CamelCipherHash camel_cipher_id_to_hash (CamelCipherContext *context, const char *id);
146 const char * camel_cipher_hash_to_id (CamelCipherContext *context, CamelCipherHash hash);
149 There are some inconsistencies here, the api's should probably handle CamelMimePart's as input/outputs,
150 Something that might generate a multipart/signed should do it as part of that processing, internally
151 to the cipher, etc etc. */
153 /* cipher routines */
154 int camel_cipher_sign (CamelCipherContext *context, const char *userid, CamelCipherHash hash,
155 struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex);
156 CamelCipherValidity *camel_cipher_verify (CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex);
157 int camel_cipher_encrypt (CamelCipherContext *context, const char *userid,
158 GPtrArray *recipients, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
160 CamelCipherValidity *camel_cipher_decrypt (CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
163 /* key/certificate routines */
164 int camel_cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream,
166 int camel_cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
167 struct _CamelStream *ostream, CamelException *ex);
169 /* CamelCipherValidity utility functions */
170 CamelCipherValidity *camel_cipher_validity_new (void);
171 void camel_cipher_validity_init (CamelCipherValidity *validity);
172 gboolean camel_cipher_validity_get_valid (CamelCipherValidity *validity);
173 void camel_cipher_validity_set_valid (CamelCipherValidity *validity, gboolean valid);
174 char *camel_cipher_validity_get_description (CamelCipherValidity *validity);
175 void camel_cipher_validity_set_description (CamelCipherValidity *validity, const char *description);
176 void camel_cipher_validity_clear (CamelCipherValidity *validity);
177 CamelCipherValidity *camel_cipher_validity_clone(CamelCipherValidity *vin);
178 void camel_cipher_validity_add_certinfo(CamelCipherValidity *vin, camel_cipher_validity_mode_t mode, const char *name, const char *email);
179 void camel_cipher_validity_envelope(CamelCipherValidity *valid, CamelCipherValidity *outer);
180 void camel_cipher_validity_free (CamelCipherValidity *validity);
182 /* utility functions */
183 int camel_cipher_canonical_to_stream(CamelMimePart *part, guint32 flags, CamelStream *ostream);
187 #endif /* CAMEL_CIPHER_CONTEXT_H */