Force response to be in uppercase
authoraland <aland>
Sun, 8 Apr 2007 06:25:37 +0000 (06:25 +0000)
committeraland <aland>
Sun, 8 Apr 2007 06:25:37 +0000 (06:25 +0000)
This fixes bug #439

src/modules/rlm_mschap/rlm_mschap.c

index e9ac66a..8ba9173 100644 (file)
@@ -199,19 +199,22 @@ static void auth_response(const char *username,
                          char *response)
 {
        SHA1_CTX Context;
-       const uint8_t magic1[39] =
+       static const uint8_t magic1[39] =
        {0x4D, 0x61, 0x67, 0x69, 0x63, 0x20, 0x73, 0x65, 0x72, 0x76,
         0x65, 0x72, 0x20, 0x74, 0x6F, 0x20, 0x63, 0x6C, 0x69, 0x65,
         0x6E, 0x74, 0x20, 0x73, 0x69, 0x67, 0x6E, 0x69, 0x6E, 0x67,
         0x20, 0x63, 0x6F, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x74};
 
-       const uint8_t magic2[41] =
+       static const uint8_t magic2[41] =
        {0x50, 0x61, 0x64, 0x20, 0x74, 0x6F, 0x20, 0x6D, 0x61, 0x6B,
         0x65, 0x20, 0x69, 0x74, 0x20, 0x64, 0x6F, 0x20, 0x6D, 0x6F,
         0x72, 0x65, 0x20, 0x74, 0x68, 0x61, 0x6E, 0x20, 0x6F, 0x6E,
         0x65, 0x20, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6F,
         0x6E};
 
+       static const char hex[16] = "0123456789ABCDEF";
+
+       int i;
         char challenge[8];
        uint8_t digest[20];
 
@@ -236,7 +239,14 @@ static void auth_response(const char *username,
         */
        response[0] = 'S';
        response[1] = '=';
-       lrad_bin2hex(digest, response + 2, 20);
+
+       /*
+        *      The hexadecimal digits [A-F] MUST be uppercase.
+        */
+       for (i = 0; i < 10; i++) {
+               response[2 + (i * 2)] = hex[(digest[i] >> 4) & 0x0f];
+               response[3 + (i * 2)] = hex[digest[i] & 0x0f];
+       }
 }