/[pkg-mixmaster]/trunk/Mix/Src/mix3.h
ViewVC logotype

Contents of /trunk/Mix/Src/mix3.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 214 - (show annotations) (download)
Thu Sep 5 01:21:54 2002 UTC (10 years, 8 months ago) by weaselp
File MIME type: text/plain
File size: 12266 byte(s)
Mixmaster keys now have creation and expiration date.
It is not secured by any crypto voodoo, it's only
informational for clients to decide which keys to
use should they have more.
- on the client side we do not show remailers (and
  therefore not use them) if their key is expired.
- the remailer refuses to decrypt messages to keys
  that expired one month ago or earlier.
- the remailer automatically creates new mixmaster
  keys if the current one are about to expire or
  already are expired.
- the latest key from secring.mix is written to
  key.txt. It used to be the first one. Since
  creation of new mix key appends the key, this
  seemed sensible.
1 /* Mixmaster version 3 -- (C) 1999 Anonymizer Inc.
2
3 Mixmaster may be redistributed and modified under certain conditions.
4 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
5 ANY KIND, either express or implied. See the file COPYRIGHT for
6 details.
7
8 Function prototypes
9 $Id: mix3.h,v 1.15 2002/09/05 01:21:54 weaselp Exp $ */
10
11
12 #ifndef _MIX3_H
13 #define _MIX3_H
14 #define COPYRIGHT "Copyright Anonymizer Inc."
15
16 #include "config.h"
17 #include "mix.h"
18
19 #ifdef WIN32
20 #ifndef USE_SOCK
21 #define _WINSOCKAPI_ /* don't include winsock */
22 #endif
23 #include <windows.h>
24 #ifdef _MSC
25 #define snprintf _snprintf
26 #endif
27 #define DIRSEP '\\'
28 #define DIRSEPSTR "\\"
29 #else
30 #define DIRSEP '/'
31 #define DIRSEPSTR "/"
32 #endif
33
34 #define NOT_IMPLEMENTED {printf("Function not implemented.\n");return -1;}
35 #define SECONDSPERDAY 86400
36
37 #include <time.h>
38
39 /* Dynamically allocated buffers */
40
41 int buf_reset(BUFFER *buffer);
42 int buf_clear(BUFFER *buffer);
43 int buf_append(BUFFER *buffer, byte *mess, int len);
44 int buf_cat(BUFFER *to, BUFFER *from);
45 int buf_set(BUFFER *to, BUFFER *from);
46 int buf_rest(BUFFER *to, BUFFER *from);
47 int buf_appendrnd(BUFFER *to, int n);
48 int buf_appendzero(BUFFER *to, int n);
49 int buf_setc(BUFFER *buf, byte c);
50 int buf_appendc(BUFFER *to, byte b);
51 int buf_setrnd(BUFFER *b, int n);
52 int buf_setf(BUFFER *buffer, char *fmt, ...);
53 int buf_appendf(BUFFER *buffer, char *fmt, ...);
54 int buf_sets(BUFFER *buf, char *s);
55 int buf_appends(BUFFER *buffer, char *s);
56 int buf_nl(BUFFER *buffer);
57 int buf_pad(BUFFER *buffer, int size);
58 int buf_prepare(BUFFER *buffer, int size);
59 int buf_rewind(BUFFER *buffer);
60 int buf_getc(BUFFER *buffer);
61 void buf_ungetc(BUFFER *buffer);
62 int buf_get(BUFFER *buffer, BUFFER *to, int n);
63 int buf_getline(BUFFER *buffer, BUFFER *line);
64 int buf_chop(BUFFER *b);
65 void buf_move(BUFFER *dest, BUFFER *src);
66 byte *buf_data(BUFFER *buffer);
67 int buf_isheader(BUFFER *buffer);
68 int buf_getheader(BUFFER *buffer, BUFFER *field, BUFFER *content);
69 int buf_appendheader(BUFFER *buffer, BUFFER *field, BUFFER *contents);
70 int buf_lookahead(BUFFER *buffer, BUFFER *line);
71 int buf_eq(BUFFER *b1, BUFFER *b2);
72 int buf_ieq(BUFFER *b1, BUFFER *b2);
73 void buf_cut_out(BUFFER *buffer, BUFFER *cut_out, BUFFER *rest,
74 int from, int len);
75
76 int buf_appendl(BUFFER *b, long l);
77 int buf_appendl_lo(BUFFER *b, long l);
78 long buf_getl(BUFFER *b);
79 long buf_getl_lo(BUFFER *b);
80 int buf_appendi(BUFFER *b, int i);
81 int buf_appendi_lo(BUFFER *b, int i);
82 int buf_geti(BUFFER *b);
83 int buf_geti_lo(BUFFER *b);
84
85 /* String comparison */
86 int strieq(const char *s1, const char *s2);
87 int strileft(const char *string, const char *keyword);
88 int striright(const char *string, const char *keyword);
89 int strifind(const char *string, const char *keyword);
90
91 int streq(const char *s1, const char *s2);
92 int strfind(const char *string, const char *keyword);
93 int strleft(const char *string, const char *keyword);
94
95 void strcatn(char *dest, const char *src, int n);
96
97 int bufleft(BUFFER *b, char *k);
98 int buffind(BUFFER *b, char *k);
99 int bufeq(BUFFER *b, char *k);
100
101 int bufileft(BUFFER *b, char *k);
102 int bufifind(BUFFER *b, char *k);
103 int bufiright(BUFFER *b, char *k);
104 int bufieq(BUFFER *b, char *k);
105
106 /* Utility functions */
107 void whoami(char *addr, char *defaultname);
108 int sendinfofile(char *name, char *log, BUFFER *address, BUFFER *subject);
109 int stats(BUFFER *out);
110 int conf(BUFFER *out);
111 void conf_premail(BUFFER *out);
112
113 void rfc822_addr(BUFFER *line, BUFFER *list);
114 void rfc822_name(BUFFER *line, BUFFER *name);
115 void sendmail_begin(void); /* begin mail sending session */
116 void sendmail_end(void); /* end mail sending session */
117 int sendmail_loop(BUFFER *message, char *from, BUFFER *address);
118 int sendmail(BUFFER *message, char *from, BUFFER *address);
119 int mixfile(char *path, const char *name);
120 int file_to_out(const char *name);
121 FILE *mix_openfile(const char *name, const char *a);
122 FILE *openpipe(const char *prog);
123 int closepipe(FILE *fp);
124 int maildirWrite(char *maildir, BUFFER *message, int create);
125 int write_pidfile(char *pidfile);
126 int clear_pidfile(char *pidfile);
127 time_t parse_yearmonthday(char* str);
128
129
130 typedef struct {
131 char *name;
132 FILE *f;
133 } LOCK;
134
135 int lock(FILE *f);
136 int unlock(FILE *f);
137 LOCK *lockfile(char *filename);
138 int unlockfile(LOCK *lock);
139
140 int filtermsg(BUFFER *msg);
141 BUFFER *readdestblk( );
142 int doblock(BUFFER *line, BUFFER *filter, int logandreset);
143 int doallow(BUFFER *line, BUFFER *filter);
144 int allowmessage(BUFFER *in);
145
146 void errlog(int type, char *format,...);
147 void clienterr(BUFFER *msgbuf, char *err);
148 void logmail(char *mailbox, BUFFER *message);
149
150 void mix_status(char *fmt,...);
151 void mix_genericerror(void);
152
153 #define ERRORMSG 1
154 #define WARNING 2
155 #define NOTICE 3
156 #define LOG 4
157 #define DEBUGINFO 5
158
159 int decode(BUFFER *in, BUFFER *out);
160 int encode(BUFFER *b, int linelen);
161 void id_encode(byte id[], byte *s);
162 void id_decode(byte *s, byte id[]);
163
164 int decode_header(BUFFER *content);
165 int boundary(BUFFER *line, BUFFER *mboundary);
166 void get_parameter(BUFFER *content, char *attribute, BUFFER *value);
167 int get_type(BUFFER *content, BUFFER *type, BUFFER *subtype);
168 int mail_encode(BUFFER *in, int encoding);
169 int hdr_encode(BUFFER *in, int n);
170 int attachfile(BUFFER *message, BUFFER *filename);
171 int pgpmime_sign(BUFFER *message, BUFFER *uid, BUFFER *pass, char *secring);
172 int mime_attach(BUFFER *message, BUFFER *attachment, BUFFER *type);
173 void mimedecode(BUFFER *msg);
174 int qp_decode_message(BUFFER *msg);
175
176 #define MIME_8BIT 1 /* transport is 8bit */
177 #define MIME_7BIT 2 /* transport is 7bit */
178
179 /* randomness */
180 int rnd_bytes(byte *b, int n);
181 byte rnd_byte(void);
182 int rnd_number(int n);
183 int rnd_add(byte *b, int l);
184 int rnd_seed(void);
185 void rnd_time(void);
186
187 int rnd_init(void);
188 int rnd_final(void);
189 void rnd_error(void);
190
191 #define RND_QUERY 0
192 #define RND_NOTSEEDED -1
193 #define RND_SEEDED 1
194 #define RND_WILLSEED 2
195 extern int rnd_state; /* flag for PRNG status */
196
197 /* compression */
198 int buf_compress(BUFFER *b);
199 int buf_zip(BUFFER *out, BUFFER *in, int bits);
200 int buf_uncompress(BUFFER *b);
201 int buf_unzip(BUFFER *b, int type);
202
203 /* crypto functions */
204 int digest_md5(BUFFER *b, BUFFER *md);
205 int isdigest_md5(BUFFER *b, BUFFER *md);
206 int digestmem_md5(byte *b, int n, BUFFER *md);
207 int digest_sha1(BUFFER *b, BUFFER *md);
208 int digest_rmd160(BUFFER *b, BUFFER *md);
209
210 int keymgt(int force);
211 int key(BUFFER *b);
212 int adminkey(BUFFER *b);
213
214 #define ENCRYPT 1
215 #define DECRYPT 0
216 int buf_crypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
217
218 #ifdef USE_IDEA
219 int buf_ideacrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
220 #endif
221 int buf_bfcrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
222 int buf_3descrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
223 int buf_castcrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
224 #ifdef USE_AES
225 int buf_aescrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
226 #endif
227
228 int db_getseckey(byte keyid[], BUFFER *key);
229 int db_getpubkey(byte keyid[], BUFFER *key);
230 int pk_decrypt(BUFFER *encrypted, BUFFER *privkey);
231 int pk_encrypt(BUFFER *plaintext, BUFFER *privkey);
232 int check_seckey(BUFFER *buf, const byte id[]);
233 int check_pubkey(BUFFER *buf, const byte id[]);
234 int v2createkey(void);
235 int getv2seckey(byte keyid[], BUFFER *key);
236 int seckeytopub(BUFFER *pub, BUFFER *sec, byte keyid[]);
237
238 /* configuration, general remailer functions */
239 int mix_configline(char *line);
240 int mix_initialized(void);
241 int mix_daily(void);
242
243 /* message pool */
244 #define INTERMEDIATE 0
245 int pool_send(void);
246 int pool_read(BUFFER *pool);
247 int pool_add(BUFFER *msg, char *type);
248 FILE *pool_new(char *type, char *tmpname, char *path);
249 int mix_pool(BUFFER *msg, int type, long latent);
250 int pool_packetfile(char *fname, BUFFER *mid, int packetnum);
251 void pool_packetexp(void);
252 int idexp(void);
253 void pop3get(void);
254
255 typedef struct { /* added for binary id.log change */
256 char id[16];
257 long time;
258 } idlog_t;
259
260 /* statistics */
261 int stats_log(int);
262 int stats_out(int);
263
264 /* OpenPGP */
265 #define PGP_ARMOR_NORMAL 0
266 #define PGP_ARMOR_REM 1
267 #define PGP_ARMOR_KEY 2
268 #define PGP_ARMOR_NYMKEY 3
269 #define PGP_ARMOR_NYMSIG 4
270 #define PGP_ARMOR_SECKEY 5
271
272 int pgp_keymgt(int force);
273 int pgp_armor(BUFFER *buf, int mode);
274 int pgp_dearmor(BUFFER *buf, BUFFER *out);
275 int pgp_pubkeycert(BUFFER *userid, char *keyring, BUFFER *pass,
276 BUFFER *out, int remail);
277 int pgp_signtxt(BUFFER *msg, BUFFER *uid, BUFFER *pass,
278 char *secring, int remail);
279 int pgp_isconventional(BUFFER *buf);
280 int pgp_mailenc(int mode, BUFFER *msg, char *sigid,
281 BUFFER *pass, char *pubring, char *secring);
282 int pgp_signhashalgo(BUFFER *algo, BUFFER *userid, char *secring,
283 BUFFER *pass);
284
285 /* menu */
286 int menu_initialized;
287 void menu_main(void);
288 void menu_folder(char command, char *name);
289 int menu_getuserpass(BUFFER *p, int mode);
290
291 int user_pass(BUFFER *b);
292 int user_confirmpass(BUFFER *b);
293 void user_delpass(void);
294
295 /* remailer */
296 typedef struct {
297 char name[20];
298 int version;
299 char addr[128];
300 byte keyid[16];
301 struct {
302 unsigned int mix:1;
303 unsigned int compress:1;
304
305 unsigned int cpunk:1;
306 unsigned int pgp:1;
307 unsigned int pgponly:1;
308 unsigned int latent:1;
309 unsigned int hash:1;
310 unsigned int ek:1;
311 unsigned int esub:1;
312
313 unsigned int nym:1;
314 unsigned int newnym:1;
315
316 unsigned int post:1;
317 unsigned int middle:1;
318 } flags;
319 struct rinfo {
320 int reliability;
321 int latency;
322 char history[13];
323 } info[2];
324 } REMAILER;
325
326 #define CHAINMAX 421
327 #define MAXREM 100
328 int prepare_type2list(BUFFER *out);
329 int mix2_rlist(REMAILER remailer[]);
330 int t1_rlist(REMAILER remailer[]);
331 int pgp_rlist(REMAILER remailer[], int n);
332 int pgp_rkeylist(REMAILER remailer[], int keyid[], int n);
333 int chain_select(int hop[], char *chainstr, int maxrem, REMAILER *remailer,
334 int type, BUFFER *feedback);
335 int chain_rand(REMAILER *remailer, int maxrem,
336 int thischain[], int chainlen, int t);
337 int chain_randfinal(int type, REMAILER *remailer, int maxrem, int t);
338
339 float chain_reliability(char *chain, int chaintype,
340 char *reliability_string);
341 int mix2_encrypt(int type, BUFFER *message, char *chainstr, int numcopies,
342 BUFFER *feedback);
343 int t1_encrypt(int type, BUFFER *message, char *chainstr, int latency,
344 BUFFER *ek, BUFFER *feedback);
345
346 int t1_getreply(BUFFER *msg, BUFFER *ek, int len);
347
348 int t1_decrypt(BUFFER *in);
349 int t2_decrypt(BUFFER *in);
350
351 int mix2_decrypt(BUFFER *m);
352 int mix3_decrypt(BUFFER *m);
353
354 /* type 2 */
355 #define MAGIC0 0
356 #define MAGIC1 3
357
358 int v3_magic(byte *b);
359 int v2body(BUFFER *body);
360 int v2body_setlen(BUFFER *body);
361 int v2partial(BUFFER *body, BUFFER *mid, int packet, int numpackets);
362 int v2_merge(BUFFER *mid);
363 int mix_armor(BUFFER *in);
364 int mix_dearmor(BUFFER *armored, BUFFER *bin);
365
366 /* type 1 */
367 #define HDRMARK "::"
368 #define EKMARK "**"
369 #define HASHMARK "##"
370 int isline(BUFFER *line, char *text);
371
372 /* nym database */
373
374 #define NYM_WAITING 0
375 #define NYM_OK 1
376 #define NYM_DELETED 2
377 #define NYM_ANY -1
378
379 int nymlist_read(BUFFER *n);
380 int nymlist_write(BUFFER *list);
381 int nymlist_get(BUFFER *list, char *nym, BUFFER *config, BUFFER *ek,
382 BUFFER *options, BUFFER *name, BUFFER *rblocks, int *status);
383 int nymlist_append(BUFFER *list, char *nym, BUFFER *config, BUFFER *options,
384 BUFFER *name, BUFFER *chains, BUFFER *eklist, int status);
385 int nymlist_del(BUFFER *list, char *nym);
386 int nymlist_getnym(char *nym, BUFFER *config, BUFFER *ek, BUFFER *opt,
387 BUFFER *name, BUFFER *rblocks);
388 int nymlist_getstatus(char *nym);
389
390 /* Visual C lacks dirent */
391 #ifdef _MSC
392 typedef HANDLE DIR;
393
394 struct dirent {
395 char d_name[PATHMAX];
396 };
397
398 DIR *opendir(const char *name);
399 struct dirent *readdir(DIR *dir);
400 int closedir(DIR *dir);
401 #endif
402
403 /* sockets */
404 #if defined(WIN32) && defined(USE_SOCK)
405 #include <winsock.h>
406 int sock_init(void);
407 void sock_exit(void);
408
409 #else
410 typedef int SOCKET;
411
412 #define INVALID_SOCKET -1
413 SOCKET opensocket(char *hostname, int port);
414 int closesocket(SOCKET s);
415
416 #endif
417
418 #ifdef WIN32
419 int is_nt_service(void);
420 void set_nt_exit_event();
421 #endif
422
423 /* check for memory leaks */
424 #ifdef DEBUG
425 #define malloc mix3_malloc
426 #define free mix3_free
427 BUFFER *mix3_bufnew(char *, int, char*);
428 #if __GNUC__ >= 2
429 # define buf_new() mix3_bufnew(__FILE__, __LINE__, __PRETTY_FUNCTION__)
430 #else
431 # define buf_new() mix3_bufnew(__FILE__, __LINE__, "file")
432 #endif
433 #endif /* DEBUG */
434
435 #endif

  ViewVC Help
Powered by ViewVC 1.1.5