Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-cipher-context.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  *  Authors: Jeffrey Stedfast <fejj@ximian.com>
4  *
5  *  Copyright 2001 Ximian, Inc. (www.ximian.com)
6  *
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.
10  *
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.
15  *
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.
20  *
21  */
22
23 #ifndef CAMEL_CIPHER_CONTEXT_H
24 #define CAMEL_CIPHER_CONTEXT_H
25
26 #include <camel/camel-session.h>
27 #include <camel/camel-exception.h>
28
29 /* FIXME: camelise */
30 #include <libedataserver/e-msgport.h>
31
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))
36
37 G_BEGIN_DECLS
38
39 struct _CamelStream;
40 struct _CamelMimePart;
41
42 typedef struct _CamelCipherValidity CamelCipherValidity;
43 typedef struct _CamelCipherCertInfo CamelCipherCertInfo;
44
45 typedef enum {
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
53 } CamelCipherHash;
54
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;
62
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;
69
70 typedef enum _camel_cipher_validity_mode_t {
71         CAMEL_CIPHER_VALIDITY_SIGN,
72         CAMEL_CIPHER_VALIDITY_ENCRYPT,
73 } camel_cipher_validity_mode_t;
74
75 struct _CamelCipherCertInfo {
76         struct _CamelCipherCertInfo *next;
77         struct _CamelCipherCertInfo *prev;
78
79         char *name;             /* common name */
80         char *email;
81 };
82
83 struct _CamelCipherValidity {
84         struct _CamelCipherValidity *next;
85         struct _CamelCipherValidity *prev;
86         EDList children;
87
88         struct {
89                 enum _camel_cipher_validity_sign_t status;
90                 char *description;
91                 EDList signers; /* CamelCipherCertInfo's */
92         } sign;
93         struct {
94                 enum _camel_cipher_validity_encrypt_t status;
95                 char *description;
96                 EDList encrypters;      /* CamelCipherCertInfo's */
97         } encrypt;
98 };
99
100 typedef struct _CamelCipherContext {
101         CamelObject parent_object;
102         
103         struct _CamelCipherContextPrivate *priv;
104         
105         CamelSession *session;
106         
107         /* these MUST be set by implementors */
108         const char *sign_protocol;
109         const char *encrypt_protocol;
110         const char *key_protocol;
111 } CamelCipherContext;
112
113 typedef struct _CamelCipherContextClass {
114         CamelObjectClass parent_class;
115         
116         CamelCipherHash       (*id_to_hash)(CamelCipherContext *context, const char *id);
117         const char *          (*hash_to_id)(CamelCipherContext *context, CamelCipherHash hash);
118         
119         int                   (*sign)      (CamelCipherContext *context, const char *userid, CamelCipherHash hash,
120                                             struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex);
121         
122         CamelCipherValidity * (*verify)    (CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex);
123         
124         int                   (*encrypt)   (CamelCipherContext *context, const char *userid,
125                                             GPtrArray *recipients, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
126                                             CamelException *ex);
127         
128         CamelCipherValidity  *(*decrypt)  (CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
129                                            CamelException *ex);
130         
131         int                   (*import_keys) (CamelCipherContext *context, struct _CamelStream *istream,
132                                               CamelException *ex);
133         
134         int                   (*export_keys) (CamelCipherContext *context, GPtrArray *keys,
135                                               struct _CamelStream *ostream, CamelException *ex);
136 } CamelCipherContextClass;
137
138 CamelType            camel_cipher_context_get_type (void);
139
140 CamelCipherContext  *camel_cipher_context_new (CamelSession *session);
141
142 void                 camel_cipher_context_construct (CamelCipherContext *context, CamelSession *session);
143
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);
147
148 /* FIXME:
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. */
152
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,
159                                            CamelException *ex);
160 CamelCipherValidity *camel_cipher_decrypt (CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
161                                            CamelException *ex);
162
163 /* key/certificate routines */
164 int                  camel_cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream,
165                                                CamelException *ex);
166 int                  camel_cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
167                                                struct _CamelStream *ostream, CamelException *ex);
168
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);
181
182 /* utility functions */
183 int                  camel_cipher_canonical_to_stream(CamelMimePart *part, guint32 flags, CamelStream *ostream);
184
185 G_END_DECLS
186
187 #endif /* CAMEL_CIPHER_CONTEXT_H */