| 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.17 2002/09/20 19:01:34 disastry 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 /* not USE_SOCK */
|
| 23 |
#include <windows.h>
|
| 24 |
#ifdef _MSC
|
| 25 |
#define snprintf _snprintf
|
| 26 |
#endif /* _MSC */
|
| 27 |
#define DIRSEP '\\'
|
| 28 |
#define DIRSEPSTR "\\"
|
| 29 |
#else /* end of WIN32 */
|
| 30 |
#define DIRSEP '/'
|
| 31 |
#define DIRSEPSTR "/"
|
| 32 |
#endif /* else if not WIN32 */
|
| 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 /* USE_IDEA */
|
| 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 /* USE_AES */
|
| 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_config(void);
|
| 241 |
int mix_initialized(void);
|
| 242 |
int mix_daily(void);
|
| 243 |
|
| 244 |
/* message pool */
|
| 245 |
#define INTERMEDIATE 0
|
| 246 |
int pool_send(void);
|
| 247 |
int pool_read(BUFFER *pool);
|
| 248 |
int pool_add(BUFFER *msg, char *type);
|
| 249 |
FILE *pool_new(char *type, char *tmpname, char *path);
|
| 250 |
int mix_pool(BUFFER *msg, int type, long latent);
|
| 251 |
int pool_packetfile(char *fname, BUFFER *mid, int packetnum);
|
| 252 |
void pool_packetexp(void);
|
| 253 |
int idexp(void);
|
| 254 |
void pop3get(void);
|
| 255 |
|
| 256 |
typedef struct { /* added for binary id.log change */
|
| 257 |
char id[16];
|
| 258 |
long time;
|
| 259 |
} idlog_t;
|
| 260 |
|
| 261 |
/* statistics */
|
| 262 |
int stats_log(int);
|
| 263 |
int stats_out(int);
|
| 264 |
|
| 265 |
/* OpenPGP */
|
| 266 |
#define PGP_ARMOR_NORMAL 0
|
| 267 |
#define PGP_ARMOR_REM 1
|
| 268 |
#define PGP_ARMOR_KEY 2
|
| 269 |
#define PGP_ARMOR_NYMKEY 3
|
| 270 |
#define PGP_ARMOR_NYMSIG 4
|
| 271 |
#define PGP_ARMOR_SECKEY 5
|
| 272 |
|
| 273 |
int pgp_keymgt(int force);
|
| 274 |
int pgp_armor(BUFFER *buf, int mode);
|
| 275 |
int pgp_dearmor(BUFFER *buf, BUFFER *out);
|
| 276 |
int pgp_pubkeycert(BUFFER *userid, char *keyring, BUFFER *pass,
|
| 277 |
BUFFER *out, int remail);
|
| 278 |
int pgp_signtxt(BUFFER *msg, BUFFER *uid, BUFFER *pass,
|
| 279 |
char *secring, int remail);
|
| 280 |
int pgp_isconventional(BUFFER *buf);
|
| 281 |
int pgp_mailenc(int mode, BUFFER *msg, char *sigid,
|
| 282 |
BUFFER *pass, char *pubring, char *secring);
|
| 283 |
int pgp_signhashalgo(BUFFER *algo, BUFFER *userid, char *secring,
|
| 284 |
BUFFER *pass);
|
| 285 |
|
| 286 |
/* menu */
|
| 287 |
int menu_initialized;
|
| 288 |
void menu_main(void);
|
| 289 |
void menu_folder(char command, char *name);
|
| 290 |
int menu_getuserpass(BUFFER *p, int mode);
|
| 291 |
|
| 292 |
int user_pass(BUFFER *b);
|
| 293 |
int user_confirmpass(BUFFER *b);
|
| 294 |
void user_delpass(void);
|
| 295 |
|
| 296 |
/* remailer */
|
| 297 |
typedef struct {
|
| 298 |
char name[20];
|
| 299 |
int version;
|
| 300 |
char addr[128];
|
| 301 |
byte keyid[16];
|
| 302 |
struct {
|
| 303 |
unsigned int mix:1;
|
| 304 |
unsigned int compress:1;
|
| 305 |
|
| 306 |
unsigned int cpunk:1;
|
| 307 |
unsigned int pgp:1;
|
| 308 |
unsigned int pgponly:1;
|
| 309 |
unsigned int latent:1;
|
| 310 |
unsigned int hash:1;
|
| 311 |
unsigned int ek:1;
|
| 312 |
unsigned int esub:1;
|
| 313 |
|
| 314 |
unsigned int nym:1;
|
| 315 |
unsigned int newnym:1;
|
| 316 |
|
| 317 |
unsigned int post:1;
|
| 318 |
unsigned int middle:1;
|
| 319 |
} flags;
|
| 320 |
struct rinfo {
|
| 321 |
int reliability;
|
| 322 |
int latency;
|
| 323 |
char history[13];
|
| 324 |
} info[2];
|
| 325 |
} REMAILER;
|
| 326 |
|
| 327 |
#define CHAINMAX 421
|
| 328 |
#define MAXREM 100
|
| 329 |
int prepare_type2list(BUFFER *out);
|
| 330 |
int mix2_rlist(REMAILER remailer[]);
|
| 331 |
int t1_rlist(REMAILER remailer[]);
|
| 332 |
int pgp_rlist(REMAILER remailer[], int n);
|
| 333 |
int pgp_rkeylist(REMAILER remailer[], int keyid[], int n);
|
| 334 |
int chain_select(int hop[], char *chainstr, int maxrem, REMAILER *remailer,
|
| 335 |
int type, BUFFER *feedback);
|
| 336 |
int chain_rand(REMAILER *remailer, int maxrem,
|
| 337 |
int thischain[], int chainlen, int t);
|
| 338 |
int chain_randfinal(int type, REMAILER *remailer, int maxrem, int t);
|
| 339 |
|
| 340 |
float chain_reliability(char *chain, int chaintype,
|
| 341 |
char *reliability_string);
|
| 342 |
int mix2_encrypt(int type, BUFFER *message, char *chainstr, int numcopies,
|
| 343 |
BUFFER *feedback);
|
| 344 |
int t1_encrypt(int type, BUFFER *message, char *chainstr, int latency,
|
| 345 |
BUFFER *ek, BUFFER *feedback);
|
| 346 |
|
| 347 |
int t1_getreply(BUFFER *msg, BUFFER *ek, int len);
|
| 348 |
|
| 349 |
int t1_decrypt(BUFFER *in);
|
| 350 |
int t2_decrypt(BUFFER *in);
|
| 351 |
|
| 352 |
int mix2_decrypt(BUFFER *m);
|
| 353 |
int mix3_decrypt(BUFFER *m);
|
| 354 |
|
| 355 |
/* type 2 */
|
| 356 |
#define MAGIC0 0
|
| 357 |
#define MAGIC1 3
|
| 358 |
|
| 359 |
int v3_magic(byte *b);
|
| 360 |
int v2body(BUFFER *body);
|
| 361 |
int v2body_setlen(BUFFER *body);
|
| 362 |
int v2partial(BUFFER *body, BUFFER *mid, int packet, int numpackets);
|
| 363 |
int v2_merge(BUFFER *mid);
|
| 364 |
int mix_armor(BUFFER *in);
|
| 365 |
int mix_dearmor(BUFFER *armored, BUFFER *bin);
|
| 366 |
|
| 367 |
/* type 1 */
|
| 368 |
#define HDRMARK "::"
|
| 369 |
#define EKMARK "**"
|
| 370 |
#define HASHMARK "##"
|
| 371 |
int isline(BUFFER *line, char *text);
|
| 372 |
|
| 373 |
/* nym database */
|
| 374 |
|
| 375 |
#define NYM_WAITING 0
|
| 376 |
#define NYM_OK 1
|
| 377 |
#define NYM_DELETED 2
|
| 378 |
#define NYM_ANY -1
|
| 379 |
|
| 380 |
int nymlist_read(BUFFER *n);
|
| 381 |
int nymlist_write(BUFFER *list);
|
| 382 |
int nymlist_get(BUFFER *list, char *nym, BUFFER *config, BUFFER *ek,
|
| 383 |
BUFFER *options, BUFFER *name, BUFFER *rblocks, int *status);
|
| 384 |
int nymlist_append(BUFFER *list, char *nym, BUFFER *config, BUFFER *options,
|
| 385 |
BUFFER *name, BUFFER *chains, BUFFER *eklist, int status);
|
| 386 |
int nymlist_del(BUFFER *list, char *nym);
|
| 387 |
int nymlist_getnym(char *nym, BUFFER *config, BUFFER *ek, BUFFER *opt,
|
| 388 |
BUFFER *name, BUFFER *rblocks);
|
| 389 |
int nymlist_getstatus(char *nym);
|
| 390 |
|
| 391 |
/* Visual C lacks dirent */
|
| 392 |
#ifdef _MSC
|
| 393 |
typedef HANDLE DIR;
|
| 394 |
|
| 395 |
struct dirent {
|
| 396 |
char d_name[PATHMAX];
|
| 397 |
};
|
| 398 |
|
| 399 |
DIR *opendir(const char *name);
|
| 400 |
struct dirent *readdir(DIR *dir);
|
| 401 |
int closedir(DIR *dir);
|
| 402 |
#endif /* _MSC */
|
| 403 |
|
| 404 |
/* sockets */
|
| 405 |
#if defined(WIN32) && defined(USE_SOCK)
|
| 406 |
#include <winsock.h>
|
| 407 |
int sock_init(void);
|
| 408 |
void sock_exit(void);
|
| 409 |
|
| 410 |
#else /* end of defined(WIN32) && defined(USE_SOCK) */
|
| 411 |
typedef int SOCKET;
|
| 412 |
|
| 413 |
#define INVALID_SOCKET -1
|
| 414 |
SOCKET opensocket(char *hostname, int port);
|
| 415 |
int closesocket(SOCKET s);
|
| 416 |
|
| 417 |
#endif /* else if not defined(WIN32) && defined(USE_SOCK) */
|
| 418 |
|
| 419 |
#ifdef WIN32
|
| 420 |
int is_nt_service(void);
|
| 421 |
void set_nt_exit_event();
|
| 422 |
#endif /* WIN32 */
|
| 423 |
|
| 424 |
/* check for memory leaks */
|
| 425 |
#ifdef DEBUG
|
| 426 |
#define malloc mix3_malloc
|
| 427 |
#define free mix3_free
|
| 428 |
BUFFER *mix3_bufnew(char *, int, char*);
|
| 429 |
#if __GNUC__ >= 2
|
| 430 |
# define buf_new() mix3_bufnew(__FILE__, __LINE__, __PRETTY_FUNCTION__)
|
| 431 |
#else /* end of __GNUC__ >= 2 */
|
| 432 |
# define buf_new() mix3_bufnew(__FILE__, __LINE__, "file")
|
| 433 |
#endif /* else if not __GNUC__ >= 2 */
|
| 434 |
#endif /* DEBUG */
|
| 435 |
|
| 436 |
#endif /* not _MIX3_H */
|