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:
Thu Mar 21 11:21:19 2019 +0000
Revision:
76:bb34dbb26aae
Parent:
73:4e769dbbf9f2
Comments improved

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 72:1ba60063c643 11 void HttpLoginPasswordRestore()
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 73:4e769dbbf9f2 17 uint32_t hasher(char *p) //Jenkins 'one at a time' hash
andrewboyson 72:1ba60063c643 18 {
andrewboyson 72:1ba60063c643 19 uint32_t h = 0;
andrewboyson 72:1ba60063c643 20
andrewboyson 72:1ba60063c643 21 while (*p)
andrewboyson 72:1ba60063c643 22 {
andrewboyson 72:1ba60063c643 23 h += *p;
andrewboyson 72:1ba60063c643 24 h += (h << 10);
andrewboyson 72:1ba60063c643 25 h ^= (h >> 6);
andrewboyson 72:1ba60063c643 26 p++;
andrewboyson 72:1ba60063c643 27 }
andrewboyson 72:1ba60063c643 28 h += (h << 3);
andrewboyson 72:1ba60063c643 29 h ^= (h >> 11);
andrewboyson 72:1ba60063c643 30 h += (h << 15);
andrewboyson 72:1ba60063c643 31
andrewboyson 72:1ba60063c643 32 return h;
andrewboyson 72:1ba60063c643 33 }
andrewboyson 71:d6aacc7d62ab 34 bool HttpLoginPasswordIsSet()
andrewboyson 71:d6aacc7d62ab 35 {
andrewboyson 72:1ba60063c643 36 return hashIsSet;
andrewboyson 71:d6aacc7d62ab 37 }
andrewboyson 72:1ba60063c643 38 void HttpLoginPasswordSet(char* password)
andrewboyson 71:d6aacc7d62ab 39 {
andrewboyson 73:4e769dbbf9f2 40 if (!password) return;
andrewboyson 73:4e769dbbf9f2 41 if (!*password) return;
andrewboyson 73:4e769dbbf9f2 42 hash = hasher(password);
andrewboyson 72:1ba60063c643 43 GPREG2 = hash;
andrewboyson 72:1ba60063c643 44 hashIsSet = true;
andrewboyson 71:d6aacc7d62ab 45 }
andrewboyson 72:1ba60063c643 46 bool HttpLoginPasswordMatches(char* password)
andrewboyson 73:4e769dbbf9f2 47 {
andrewboyson 73:4e769dbbf9f2 48 if (!hashIsSet) return false;
andrewboyson 73:4e769dbbf9f2 49 if (!password) return false;
andrewboyson 73:4e769dbbf9f2 50 if (!*password) return false;
andrewboyson 73:4e769dbbf9f2 51 return hash == hasher(password);
andrewboyson 71:d6aacc7d62ab 52 }