Anonymous committed e859c5e

mtpd: Build L2TP challenge from /dev/urandom to improve the security.

Also make it return CHALLENGE_FAILED when the response is incorrect.

Comments (0)

Files changed (1)

 static uint16_t state;
 static int acknowledged;
+#define RANDOM_DEVICE   "/dev/urandom"
 #define CHALLENGE_SIZE  32
 static char *secret;
     add_attribute_u16(WINDOW_SIZE, htons(1));
     if (argc >= 3) {
-        int i;
-        for (i = 0; i < CHALLENGE_SIZE; ++i) {
-            challenge[i] = random();
+        FILE *fp = fopen(RANDOM_DEVICE, "r");
+        if (!fp || fread(challenge, 1, CHALLENGE_SIZE, fp) != CHALLENGE_SIZE) {
+            log_print(FATAL, "Cannot read %s", RANDOM_DEVICE);
+            exit(SYSTEM_ERROR);
+        fclose(fp);
         add_attribute_raw(CHALLENGE, challenge, CHALLENGE_SIZE);
         secret = argv[2];
         secret_length = strlen(argv[2]);
                 log_print(DEBUG, "Received SCCRP without %s", tunnel ?
                           "valid challenge response" : "assigned tunnel");
                 log_print(ERROR, "Protocol error");
-                return -PROTOCOL_ERROR;
+                return tunnel ? -CHALLENGE_FAILED : -PROTOCOL_ERROR;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.