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.

Revision:
119:794e5985d6c8
Parent:
118:53430a2a2595
Child:
138:44d84506b2f6
--- a/web-add.c	Wed May 08 12:14:13 2019 +0000
+++ b/web-add.c	Thu May 09 07:48:03 2019 +0000
@@ -8,7 +8,7 @@
 #include "ip4addr.h"
 #include "ip6addr.h"
 
-void WebAddNavItem(int highlight, char* href, char* title)
+void WebAddNavItem(int highlight, const char* href, const char* title)
 {
     char *p;
     HttpAddText("<li ");
@@ -84,14 +84,14 @@
                 "</html>\r\n");
 }
 
-void WebAddLabelledPrefixSuffix(char* label, char* prefix, char* text, char* suffix)
+void WebAddLabelledPrefixSuffix(const char* label, const char* prefix, const char* text, const char* suffix)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddF   ("  <div>%s%s%s</div>\r\n", prefix, text, suffix);
     HttpAddText("</div>\r\n");
 }
-void WebAddLabelledText(char* label, char* text)
+void WebAddLabelledText(const char* label, const char* text)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
@@ -99,7 +99,7 @@
     HttpAddText("</div>\r\n");
 }
 
-void WebAddLabelledMac(char* label, char* mac)
+void WebAddLabelledMac(const char* label, const char* mac)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
@@ -107,7 +107,7 @@
     HttpAddText("</div>\r\n");
 }
 
-void WebAddLabelledIp4(char* label, uint32_t ip)
+void WebAddLabelledIp4(const char* label, uint32_t ip)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
@@ -115,32 +115,32 @@
     HttpAddText("</div>\r\n");
 }
 
-void WebAddLabelledIp6(char* label, char* ip)
+void WebAddLabelledIp6(const char* label, const char* ip)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddText("  <div>"); Ip6AddressHttp(ip); HttpAddText("</div>\r\n");
     HttpAddText("</div>\r\n");
 }
-void WebAddLabelledOnOff(char* label, bool value)
+void WebAddLabelledOnOff(const char* label, bool value)
 {
     if (value) WebAddLabelledText(label, "On");
     else       WebAddLabelledText(label, "Off");
 }
-void WebAddLabelledLed(char* label, bool value)
+void WebAddLabelledLed(const char* label, bool value)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddF   ("  <div class='led' dir='%s'></div>\r\n", value ? "rtl" : "ltr");
     HttpAddText("</div>\r\n");
 }
-void WebAddLabelledInt(char* label, int value)
+void WebAddLabelledInt(const char* label, int value)
 {
     char text[30];
     snprintf(text, sizeof(text), "%8d", value); //Right align with enough spaces so that the length is always constant. 
     WebAddLabelledText(label, text);
 }
-void WebAddInputText(char* label, float inputwidth, char* value, char* action, char* name)
+void WebAddInputText(const char* label, float inputwidth, const char* value, const char* action, const char* name)
 {
     HttpAddF   ("<form action='%s' method='get'>\r\n", action);
     HttpAddText("<div class='line'>\r\n");
@@ -151,13 +151,13 @@
     HttpAddF   ("</form>\r\n");
 
 }
-void WebAddInputInt(char* label, float inputwidth, int value, char* action, char* name)
+void WebAddInputInt(const char* label, float inputwidth, int value, const char* action, const char* name)
 {    
     char text[30];
     snprintf(text, sizeof(text), "%d", value);
     WebAddInputText(label, inputwidth, text, action, name);
 }
-void WebAddInputButton(char* label, char* value, char* action, char* name)
+void WebAddInputButton(const char* label, const char* value, const char* action, const char* name)
 {
     HttpAddF   ("<form action='%s' method='get'>\r\n", action);
     HttpAddF   ("<input type='hidden' name='%s'>\r\n", name);
@@ -167,7 +167,7 @@
     HttpAddText("</div>\r\n");
     HttpAddText("</form>\r\n");
 }
-void WebAddAjaxInputToggle(char* label, char* id, char* name)
+void WebAddAjaxInputToggle(const char* label, const char* id, const char* name)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
@@ -176,42 +176,42 @@
     HttpAddText("  </div>\r\n");
     HttpAddText("</div>\r\n");
 }
-void WebAddAjaxLed(char* label, char* id)
+void WebAddAjaxLed(const char* label, const char* id)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddF   ("  <div class='led' id='%s' dir='ltr'></div>\r\n", id);
     HttpAddText("</div>\r\n");
 }
-void WebAddAjaxInput(char* label, float inputwidth, char* id, char* name)
+void WebAddAjaxInput(const char* label, float inputwidth, const char* id, const char* name)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxRequest(\"%s=\" + this.value)'>\r\n", inputwidth, id, name);
     HttpAddText("</div>\r\n");
 }
-void WebAddAjaxInputSuffix(char* label, float inputwidth, char* id, char* name, char* suffix)
+void WebAddAjaxInputSuffix(const char* label, float inputwidth, const char* id, const char* name, const char* suffix)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxRequest(\"%s=\" + this.value)'>%s\r\n", inputwidth, id, name, suffix);
     HttpAddText("</div>\r\n");
 }
-void WebAddAjaxLabelled(char* label, char* id)
+void WebAddAjaxLabelled(const char* label, const char* id)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddF   ("  <div id='%s'></div>\r\n", id);
     HttpAddText("</div>\r\n");
 }
-void WebAddAjaxLabelledSuffix(char* label, char* id, char* suffix)
+void WebAddAjaxLabelledSuffix(const char* label, const char* id, const char* suffix)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
     HttpAddF   ("  <div><span id='%s'></span>%s</div>\r\n", id, suffix);
     HttpAddText("</div>\r\n");
 }
-void WebAddAjaxInputLabelId(char* labelId, float inputwidth, char* id, char* name)
+void WebAddAjaxInputLabelId(const char* labelId, float inputwidth, const char* id, const char* name)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div id='%s'></div>\r\n", labelId);