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:
Sun Jan 17 18:24:37 2021 +0000
Revision:
150:f676c14793fc
Parent:
149:24365666d28d
Child:
152:edbf676b08ca
Tidied the Firmware upload message to warn the user (me) against restarting before the file has been saved ok.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 50:edd44fe9320f 1 'use strict';
andrewboyson 50:edd44fe9320f 2
andrewboyson 48:4e678727c4c9 3 var file;
andrewboyson 46:1822fdbe6c0c 4 var xhr;
andrewboyson 48:4e678727c4c9 5
andrewboyson 55:3d1e52e3e9b7 6 function logUpload(text)
andrewboyson 50:edd44fe9320f 7 {
andrewboyson 55:3d1e52e3e9b7 8 document.getElementById('uploadresult').textContent = text;
andrewboyson 50:edd44fe9320f 9 }
andrewboyson 55:3d1e52e3e9b7 10 function xhrUploadResponse()
andrewboyson 51:c605b2794b44 11 {
andrewboyson 51:c605b2794b44 12 var topics = xhr.responseText.split('\f');
andrewboyson 55:3d1e52e3e9b7 13 logUpload(topics[0]);
andrewboyson 51:c605b2794b44 14 if (topics.length > 1) document.getElementById('list').textContent = topics[1];
andrewboyson 51:c605b2794b44 15 }
andrewboyson 55:3d1e52e3e9b7 16 function xhrUploadOnLoad()
andrewboyson 46:1822fdbe6c0c 17 {
andrewboyson 55:3d1e52e3e9b7 18 if (xhr.status == 200) xhrUploadResponse();
andrewboyson 55:3d1e52e3e9b7 19 else logUpload('Upload failed');
andrewboyson 46:1822fdbe6c0c 20 }
andrewboyson 55:3d1e52e3e9b7 21 function xhrUploadOnError()
andrewboyson 46:1822fdbe6c0c 22 {
andrewboyson 55:3d1e52e3e9b7 23 logUpload('Upload error');
andrewboyson 46:1822fdbe6c0c 24 }
andrewboyson 149:24365666d28d 25 function xhrUploadProgress(e)
andrewboyson 149:24365666d28d 26 {
andrewboyson 150:f676c14793fc 27 logUpload('Total ' + e.total + ' bytes\r\n' +
andrewboyson 150:f676c14793fc 28 'Sent ' + e.loaded + ' bytes\r\n' +
andrewboyson 150:f676c14793fc 29 'Don\'t restart yet, wait for the ok...');
andrewboyson 149:24365666d28d 30 }
andrewboyson 55:3d1e52e3e9b7 31 function xhrUploadStart()
andrewboyson 48:4e678727c4c9 32 {
andrewboyson 149:24365666d28d 33 logUpload('Upload starting...');
andrewboyson 48:4e678727c4c9 34
andrewboyson 48:4e678727c4c9 35 xhr = new XMLHttpRequest();
andrewboyson 48:4e678727c4c9 36
andrewboyson 55:3d1e52e3e9b7 37 xhr.onload = xhrUploadOnLoad;
andrewboyson 55:3d1e52e3e9b7 38 xhr.onerror = xhrUploadOnError;
andrewboyson 149:24365666d28d 39 xhr.upload.onprogress = xhrUploadProgress;
andrewboyson 48:4e678727c4c9 40
andrewboyson 53:27d56a22a450 41 xhr.open('POST', '/firmware-ajax'); //Defaults to async=true
andrewboyson 48:4e678727c4c9 42 xhr.send(file);
andrewboyson 48:4e678727c4c9 43 }
andrewboyson 46:1822fdbe6c0c 44 function startUpload()
andrewboyson 46:1822fdbe6c0c 45 {
andrewboyson 46:1822fdbe6c0c 46 var fileInput = document.getElementById('fileInput');
andrewboyson 46:1822fdbe6c0c 47
andrewboyson 46:1822fdbe6c0c 48 if (fileInput.files.length == 0)
andrewboyson 46:1822fdbe6c0c 49 {
andrewboyson 55:3d1e52e3e9b7 50 logUpload('Please choose a file');
andrewboyson 46:1822fdbe6c0c 51 return;
andrewboyson 46:1822fdbe6c0c 52 }
andrewboyson 46:1822fdbe6c0c 53
andrewboyson 46:1822fdbe6c0c 54 if (fileInput.files.length > 1)
andrewboyson 46:1822fdbe6c0c 55 {
andrewboyson 55:3d1e52e3e9b7 56 logUpload('Please choose just one file');
andrewboyson 46:1822fdbe6c0c 57 return;
andrewboyson 46:1822fdbe6c0c 58 }
andrewboyson 48:4e678727c4c9 59
andrewboyson 48:4e678727c4c9 60 file = fileInput.files[0];
andrewboyson 47:cf7d4c34158e 61
andrewboyson 55:3d1e52e3e9b7 62 xhrUploadStart();
andrewboyson 55:3d1e52e3e9b7 63 }
andrewboyson 55:3d1e52e3e9b7 64 function logRestart(text)
andrewboyson 55:3d1e52e3e9b7 65 {
andrewboyson 55:3d1e52e3e9b7 66 document.getElementById('restartresult').textContent = text;
andrewboyson 55:3d1e52e3e9b7 67 }
andrewboyson 55:3d1e52e3e9b7 68 function redirect()
andrewboyson 55:3d1e52e3e9b7 69 {
andrewboyson 55:3d1e52e3e9b7 70 location.href = '/firmware';
andrewboyson 55:3d1e52e3e9b7 71 }
andrewboyson 55:3d1e52e3e9b7 72 function xhrRestartOnLoad()
andrewboyson 55:3d1e52e3e9b7 73 {
andrewboyson 55:3d1e52e3e9b7 74 if (xhr.status == 200) logRestart('Restart should never have returned');
andrewboyson 55:3d1e52e3e9b7 75 else logRestart('Restart failed');
andrewboyson 48:4e678727c4c9 76 }
andrewboyson 55:3d1e52e3e9b7 77 function xhrRestartStart()
andrewboyson 55:3d1e52e3e9b7 78 {
andrewboyson 55:3d1e52e3e9b7 79 logRestart('Restarting...');
andrewboyson 55:3d1e52e3e9b7 80
andrewboyson 55:3d1e52e3e9b7 81 xhr = new XMLHttpRequest();
andrewboyson 55:3d1e52e3e9b7 82
andrewboyson 55:3d1e52e3e9b7 83 xhr.onload = xhrRestartOnLoad;
andrewboyson 55:3d1e52e3e9b7 84
andrewboyson 55:3d1e52e3e9b7 85 xhr.open('GET', '/firmware-ajax?restart='); //Defaults to async=true
andrewboyson 55:3d1e52e3e9b7 86 xhr.send();
andrewboyson 55:3d1e52e3e9b7 87
andrewboyson 55:3d1e52e3e9b7 88 setTimeout(redirect, 2000);
andrewboyson 55:3d1e52e3e9b7 89 }
andrewboyson 55:3d1e52e3e9b7 90 function restart()
andrewboyson 55:3d1e52e3e9b7 91 {
andrewboyson 55:3d1e52e3e9b7 92 xhrRestartStart();
andrewboyson 55:3d1e52e3e9b7 93 }
andrewboyson 114:900e33dfa460 94