Common stuff for all my devices' web server pages: css, login, log, ipv4, ipv6, firmware update, clock, reset info etc.

Dependents:   oldheating gps motorhome heating

Security

A password has to be set whenever there has been a software reset. Resets following faults or power on do not require a new password as the hash is restored from the RTC GPREG register.

The password is not saved on the device; instead a 32 bit hash of the password is saved. It would take 2^31 attempts to brute force the password: this could be done in under a month if an attempt were possible every millisecond. To prevent this a 200 ms delay is introduced in the reply to the login form, that gives a more reasonable 13 years to brute force the password.

Once the password is accepted a random session id is created. This is 36 bit to give six base 64 characters but without an extra delay. If an attempt could be made every ms then this would still take over a year to brute force.

The most likely attack would to use a dictionary with, say, 10 million entries against the password which would still take 20 days to do.

Committer:
andrewboyson
Date:
Wed Jul 31 15:09:15 2019 +0000
Revision:
127:bd6dd135009d
Parent:
114:900e33dfa460
Amalgamated Reply into Poll function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 71:d6aacc7d62ab 1 #include <stdbool.h>
andrewboyson 72:1ba60063c643 2 #include <stdint.h>
andrewboyson 71:d6aacc7d62ab 3
andrewboyson 71:d6aacc7d62ab 4 #include "http.h"
andrewboyson 71:d6aacc7d62ab 5
andrewboyson 76:bb34dbb26aae 6 #define GPREG2 (*((volatile unsigned *) 0x4002404C))
andrewboyson 71:d6aacc7d62ab 7
andrewboyson 72:1ba60063c643 8 static uint32_t hash;
andrewboyson 72:1ba60063c643 9 static bool hashIsSet = false;
andrewboyson 71:d6aacc7d62ab 10
andrewboyson 103:91194cc19bbb 11 void WebLoginPasswordRestore()
andrewboyson 71:d6aacc7d62ab 12 {
andrewboyson 72:1ba60063c643 13 hash = GPREG2;
andrewboyson 72:1ba60063c643 14 hashIsSet = true;
andrewboyson 71:d6aacc7d62ab 15 }
andrewboyson 71:d6aacc7d62ab 16
andrewboyson 114:900e33dfa460 17 void WebLoginPasswordReset()
andrewboyson 114:900e33dfa460 18 {
andrewboyson 114:900e33dfa460 19 GPREG2 = 0;
andrewboyson 114:900e33dfa460 20 hashIsSet = false;
andrewboyson 114:900e33dfa460 21 }
andrewboyson 73:4e769dbbf9f2 22 uint32_t hasher(char *p) //Jenkins 'one at a time' hash
andrewboyson 72:1ba60063c643 23 {
andrewboyson 72:1ba60063c643 24 uint32_t h = 0;
andrewboyson 72:1ba60063c643 25
andrewboyson 72:1ba60063c643 26 while (*p)
andrewboyson 72:1ba60063c643 27 {
andrewboyson 72:1ba60063c643 28 h += *p;
andrewboyson 72:1ba60063c643 29 h += (h << 10);
andrewboyson 72:1ba60063c643 30 h ^= (h >> 6);
andrewboyson 72:1ba60063c643 31 p++;
andrewboyson 72:1ba60063c643 32 }
andrewboyson 72:1ba60063c643 33 h += (h << 3);
andrewboyson 72:1ba60063c643 34 h ^= (h >> 11);
andrewboyson 72:1ba60063c643 35 h += (h << 15);
andrewboyson 72:1ba60063c643 36
andrewboyson 72:1ba60063c643 37 return h;
andrewboyson 72:1ba60063c643 38 }
andrewboyson 103:91194cc19bbb 39 bool WebLoginPasswordIsSet()
andrewboyson 71:d6aacc7d62ab 40 {
andrewboyson 72:1ba60063c643 41 return hashIsSet;
andrewboyson 71:d6aacc7d62ab 42 }
andrewboyson 103:91194cc19bbb 43 void WebLoginPasswordSet(char* password)
andrewboyson 71:d6aacc7d62ab 44 {
andrewboyson 73:4e769dbbf9f2 45 if (!password) return;
andrewboyson 73:4e769dbbf9f2 46 if (!*password) return;
andrewboyson 73:4e769dbbf9f2 47 hash = hasher(password);
andrewboyson 72:1ba60063c643 48 GPREG2 = hash;
andrewboyson 72:1ba60063c643 49 hashIsSet = true;
andrewboyson 71:d6aacc7d62ab 50 }
andrewboyson 103:91194cc19bbb 51 bool WebLoginPasswordMatches(char* password)
andrewboyson 73:4e769dbbf9f2 52 {
andrewboyson 73:4e769dbbf9f2 53 if (!hashIsSet) return false;
andrewboyson 73:4e769dbbf9f2 54 if (!password) return false;
andrewboyson 73:4e769dbbf9f2 55 if (!*password) return false;
andrewboyson 73:4e769dbbf9f2 56 return hash == hasher(password);
andrewboyson 71:d6aacc7d62ab 57 }