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

  ViewVC Help
Powered by ViewVC 1.1.5