mirror of
https://github.com/darkk/redsocks.git
synced 2025-08-26 03:35:30 +00:00
Improve nonce generation: srand() should be called only during startup.
This commit is contained in:
parent
8b0a9dcc6c
commit
ebaeedead1
@ -210,7 +210,6 @@ static struct evbuffer *httpc_mkconnect(redsocks_client *client)
|
|||||||
|
|
||||||
/* prepare an random string for cnounce */
|
/* prepare an random string for cnounce */
|
||||||
char cnounce[17];
|
char cnounce[17];
|
||||||
srand(time(0));
|
|
||||||
for (int i = 0; i < 16; i += 4)
|
for (int i = 0; i < 16; i += 4)
|
||||||
sprintf(cnounce + i, "%02x", rand() & 65535);
|
sprintf(cnounce + i, "%02x", rand() & 65535);
|
||||||
|
|
||||||
|
@ -321,7 +321,6 @@ static void httpr_relay_write_cb(struct bufferevent *buffev, void *_arg)
|
|||||||
|
|
||||||
/* prepare an random string for cnounce */
|
/* prepare an random string for cnounce */
|
||||||
char cnounce[17];
|
char cnounce[17];
|
||||||
srand(time(0));
|
|
||||||
for (int i = 0; i < 16; i += 4)
|
for (int i = 0; i < 16; i += 4)
|
||||||
sprintf(cnounce + i, "%04x", rand() & 65535);
|
sprintf(cnounce + i, "%04x", rand() & 65535);
|
||||||
|
|
||||||
|
9
main.c
9
main.c
@ -46,6 +46,14 @@ static void terminate(int sig, short what, void *_arg)
|
|||||||
log_error(LOG_WARNING, "event_loopbreak");
|
log_error(LOG_WARNING, "event_loopbreak");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void red_srand()
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
// using tv_usec is a bit less predictable than tv_sec
|
||||||
|
srand(tv.tv_sec*1000000+tv.tv_usec);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
@ -56,6 +64,7 @@ int main(int argc, char **argv)
|
|||||||
int opt;
|
int opt;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
red_srand();
|
||||||
while ((opt = getopt(argc, argv, "tc:p:")) != -1) {
|
while ((opt = getopt(argc, argv, "tc:p:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 't':
|
case 't':
|
||||||
|
Loading…
Reference in New Issue
Block a user