| 1 |
/* Mixmaster version 3 -- (C) 1999 Anonymizer Inc. |
/* Mixmaster version 3.0 -- (C) 1999 - 2004 Anonymizer Inc. and others. |
| 2 |
|
|
| 3 |
Mixmaster may be redistributed and modified under certain conditions. |
Mixmaster may be redistributed and modified under certain conditions. |
| 4 |
This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF |
This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF |
| 6 |
details. |
details. |
| 7 |
|
|
| 8 |
Encrypt message for Cypherpunk remailer chain |
Encrypt message for Cypherpunk remailer chain |
| 9 |
$Id: chain1.c,v 1.3 2002/09/18 23:26:16 rabbi Exp $ */ |
$Id$ */ |
| 10 |
|
|
| 11 |
|
|
| 12 |
#include "mix3.h" |
#include "mix3.h" |
| 16 |
|
|
| 17 |
#define N(X) (isdigit(X) ? (X)-'0' : 0) |
#define N(X) (isdigit(X) ? (X)-'0' : 0) |
| 18 |
|
|
| 19 |
int t1_rlist(REMAILER remailer[]) |
int t1_rlist(REMAILER remailer[], int badchains[MAXREM][MAXREM]) |
| 20 |
{ |
{ |
| 21 |
FILE *list; |
FILE *list, *excl; |
| 22 |
int i, listed = 0; |
int i, listed = 0; |
| 23 |
int n = 0; |
int n = 0; |
| 24 |
char line[2 * LINELEN], l2[LINELEN], name[LINELEN], *flags; |
char line[2 * LINELEN], l2[LINELEN], name[LINELEN], *flags; |
| 25 |
|
BUFFER *starex; |
| 26 |
|
|
| 27 |
|
starex = buf_new(); |
| 28 |
|
excl = mix_openfile(STAREX, "r"); |
| 29 |
|
if (excl != NULL) { |
| 30 |
|
buf_read(starex, excl); |
| 31 |
|
fclose(excl); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
list = mix_openfile(TYPE1LIST, "r"); |
list = mix_openfile(TYPE1LIST, "r"); |
| 35 |
if (list == NULL) |
if (list == NULL) { |
| 36 |
|
buf_free(starex); |
| 37 |
return (-1); |
return (-1); |
| 38 |
|
} |
| 39 |
|
|
| 40 |
while (fgets(line, sizeof(line), list) != NULL && n < MAXREM) { |
while (fgets(line, sizeof(line), list) != NULL && n < MAXREM) { |
| 41 |
if (strleft(line, "$remailer") && |
if (strleft(line, "$remailer") && |
| 42 |
strchr(line, '<') && strchr(line, '>') && |
strchr(line, '<') && strchr(line, '>') && |
| 82 |
remailer[i].info[1].reliability = 0; |
remailer[i].info[1].reliability = 0; |
| 83 |
remailer[i].info[1].latency = 0; |
remailer[i].info[1].latency = 0; |
| 84 |
remailer[i].info[1].history[0] = '\0'; |
remailer[i].info[1].history[0] = '\0'; |
| 85 |
} |
remailer[i].flags.star_ex = bufifind(starex, name); |
| 86 |
|
} |
| 87 |
if (strleft(line, |
if (strleft(line, |
| 88 |
"-----------------------------------------------------------------------")) |
"-----------------------------------------------------------------------")) |
| 89 |
break; |
break; |
| 107 |
} |
} |
| 108 |
} |
} |
| 109 |
fclose(list); |
fclose(list); |
| 110 |
|
parse_badchains(badchains, TYPE1LIST, "Broken type-I remailer chains", remailer, n); |
| 111 |
if (listed < 4) /* we have no valid reliability info */ |
if (listed < 4) /* we have no valid reliability info */ |
| 112 |
for (i = 1; i < n; i++) |
for (i = 1; i < n; i++) |
| 113 |
remailer[i].info[1].reliability = 10000; |
remailer[i].info[1].reliability = 10000; |
| 115 |
#ifdef USE_PGP |
#ifdef USE_PGP |
| 116 |
pgp_rlist(remailer, n); |
pgp_rlist(remailer, n); |
| 117 |
#endif /* USE_PGP */ |
#endif /* USE_PGP */ |
| 118 |
|
buf_free(starex); |
| 119 |
return (n); |
return (n); |
| 120 |
} |
} |
| 121 |
|
|
| 130 |
fprintf(stderr, "passphrase=%s (%2X%2X%2X%2X %d)\n", key->data, |
fprintf(stderr, "passphrase=%s (%2X%2X%2X%2X %d)\n", key->data, |
| 131 |
seed->data[0], seed->data[1], seed->data[2], seed->data[3], num); |
seed->data[0], seed->data[1], seed->data[2], seed->data[3], num); |
| 132 |
#endif /* DEBUG */ |
#endif /* DEBUG */ |
| 133 |
return (0); |
return (0); |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
int t1_encrypt(int type, BUFFER *message, char *chainstr, int latency, |
int t1_encrypt(int type, BUFFER *message, char *chainstr, int latency, |
| 138 |
{ |
{ |
| 139 |
BUFFER *b, *rem, *dest, *line, *field, *content; |
BUFFER *b, *rem, *dest, *line, *field, *content; |
| 140 |
REMAILER remailer[MAXREM]; |
REMAILER remailer[MAXREM]; |
| 141 |
|
int badchains[MAXREM][MAXREM]; |
| 142 |
int maxrem, chainlen = 0; |
int maxrem, chainlen = 0; |
| 143 |
int chain[20]; |
int chain[20]; |
| 144 |
int hop; |
int hop; |
| 152 |
field = buf_new(); |
field = buf_new(); |
| 153 |
content = buf_new(); |
content = buf_new(); |
| 154 |
|
|
| 155 |
maxrem = t1_rlist(remailer); |
maxrem = t1_rlist(remailer, badchains); |
| 156 |
if (maxrem < 1) { |
if (maxrem < 1) { |
| 157 |
clienterr(feedback, "No remailer list!"); |
clienterr(feedback, "No remailer list!"); |
| 158 |
err = -1; |
err = -1; |
| 168 |
goto end; |
goto end; |
| 169 |
} |
} |
| 170 |
if (chain[0] == 0) |
if (chain[0] == 0) |
| 171 |
chain[0] = chain_randfinal(type, remailer, maxrem, 1); |
chain[0] = chain_randfinal(type, remailer, badchains, maxrem, 1, chain, chainlen, 0); |
| 172 |
|
|
| 173 |
if (chain[0] == -1) { |
if (chain[0] == -1) { |
| 174 |
clienterr(feedback, "Invalid remailer chain!"); |
clienterr(feedback, "Invalid remailer chain!"); |
| 175 |
err = -1; |
err = -1; |
| 176 |
goto end; |
goto end; |
| 177 |
} |
} |
| 178 |
if (chain_rand(remailer, maxrem, chain, chainlen, 1) == -1) { |
if (chain_rand(remailer, badchains, maxrem, chain, chainlen, 1, 0) == -1) { |
| 179 |
clienterr(feedback, "No reliable remailers!"); |
clienterr(feedback, "No reliable remailers!"); |
| 180 |
err = -1; |
err = -1; |
| 181 |
goto end; |
goto end; |