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.
base/firmware/web-firmware-script.inc@160:daa94b75b94c, 2021-05-11 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue May 11 11:00:00 2021 +0000
- Revision:
- 160:daa94b75b94c
- Parent:
- 158:80441390de93
CSS modified to not change the text colour when hovering over a disabled button: it still does for buttons which are enabled.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 50:edd44fe9320f | 1 | "'use strict';\n" |
andrewboyson | 50:edd44fe9320f | 2 | "\n" |
andrewboyson | 48:4e678727c4c9 | 3 | "var file;\n" |
andrewboyson | 46:1822fdbe6c0c | 4 | "var xhr;\n" |
andrewboyson | 48:4e678727c4c9 | 5 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 6 | "function logUpload(text)\n" |
andrewboyson | 50:edd44fe9320f | 7 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 8 | " document.getElementById('uploadresult').textContent = text;\n" |
andrewboyson | 50:edd44fe9320f | 9 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 10 | "function xhrUploadResponse()\n" |
andrewboyson | 51:c605b2794b44 | 11 | "{\n" |
andrewboyson | 158:80441390de93 | 12 | " document.getElementById('restartbutton').disabled = false;\n" |
andrewboyson | 51:c605b2794b44 | 13 | " var topics = xhr.responseText.split('\\f');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 14 | " logUpload(topics[0]);\n" |
andrewboyson | 51:c605b2794b44 | 15 | " if (topics.length > 1) document.getElementById('list').textContent = topics[1];\n" |
andrewboyson | 51:c605b2794b44 | 16 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 17 | "function xhrUploadOnLoad()\n" |
andrewboyson | 46:1822fdbe6c0c | 18 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 19 | " if (xhr.status == 200) xhrUploadResponse();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 20 | " else logUpload('Upload failed');\n" |
andrewboyson | 46:1822fdbe6c0c | 21 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 22 | "function xhrUploadOnError()\n" |
andrewboyson | 46:1822fdbe6c0c | 23 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 24 | " logUpload('Upload error');\n" |
andrewboyson | 46:1822fdbe6c0c | 25 | "}\n" |
andrewboyson | 149:24365666d28d | 26 | "function xhrUploadProgress(e)\n" |
andrewboyson | 149:24365666d28d | 27 | "{\n" |
andrewboyson | 158:80441390de93 | 28 | " logUpload('Uploading ' + e.total + ' bytes ' + '(' + Math.round(e.loaded/e.total * 100) + '%)...\\r\\n');\n" |
andrewboyson | 149:24365666d28d | 29 | "}\n" |
andrewboyson | 156:005785e4740e | 30 | "function xhrUploadComplete(e)\n" |
andrewboyson | 156:005785e4740e | 31 | "{\n" |
andrewboyson | 156:005785e4740e | 32 | " logUpload('Saving ' + e.loaded + ' bytes...');\n" |
andrewboyson | 156:005785e4740e | 33 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 34 | "function xhrUploadStart()\n" |
andrewboyson | 48:4e678727c4c9 | 35 | "{\n" |
andrewboyson | 158:80441390de93 | 36 | " document.getElementById('restartbutton').disabled = true;\n" |
andrewboyson | 149:24365666d28d | 37 | " logUpload('Upload starting...');\n" |
andrewboyson | 48:4e678727c4c9 | 38 | " \n" |
andrewboyson | 48:4e678727c4c9 | 39 | " xhr = new XMLHttpRequest();\n" |
andrewboyson | 48:4e678727c4c9 | 40 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 41 | " xhr.onload = xhrUploadOnLoad;\n" |
andrewboyson | 55:3d1e52e3e9b7 | 42 | " xhr.onerror = xhrUploadOnError;\n" |
andrewboyson | 149:24365666d28d | 43 | " xhr.upload.onprogress = xhrUploadProgress;\n" |
andrewboyson | 156:005785e4740e | 44 | " xhr.upload.onload = xhrUploadComplete;\n" |
andrewboyson | 48:4e678727c4c9 | 45 | "\n" |
andrewboyson | 53:27d56a22a450 | 46 | " xhr.open('POST', '/firmware-ajax'); //Defaults to async=true\n" |
andrewboyson | 48:4e678727c4c9 | 47 | " xhr.send(file);\n" |
andrewboyson | 48:4e678727c4c9 | 48 | "}\n" |
andrewboyson | 46:1822fdbe6c0c | 49 | "function startUpload()\n" |
andrewboyson | 46:1822fdbe6c0c | 50 | "{\n" |
andrewboyson | 46:1822fdbe6c0c | 51 | " var fileInput = document.getElementById('fileInput');\n" |
andrewboyson | 46:1822fdbe6c0c | 52 | "\n" |
andrewboyson | 46:1822fdbe6c0c | 53 | " if (fileInput.files.length == 0)\n" |
andrewboyson | 46:1822fdbe6c0c | 54 | " {\n" |
andrewboyson | 55:3d1e52e3e9b7 | 55 | " logUpload('Please choose a file');\n" |
andrewboyson | 46:1822fdbe6c0c | 56 | " return;\n" |
andrewboyson | 46:1822fdbe6c0c | 57 | " }\n" |
andrewboyson | 46:1822fdbe6c0c | 58 | "\n" |
andrewboyson | 46:1822fdbe6c0c | 59 | " if (fileInput.files.length > 1)\n" |
andrewboyson | 46:1822fdbe6c0c | 60 | " {\n" |
andrewboyson | 55:3d1e52e3e9b7 | 61 | " logUpload('Please choose just one file');\n" |
andrewboyson | 46:1822fdbe6c0c | 62 | " return;\n" |
andrewboyson | 46:1822fdbe6c0c | 63 | " }\n" |
andrewboyson | 48:4e678727c4c9 | 64 | " \n" |
andrewboyson | 48:4e678727c4c9 | 65 | " file = fileInput.files[0];\n" |
andrewboyson | 48:4e678727c4c9 | 66 | " \n" |
andrewboyson | 55:3d1e52e3e9b7 | 67 | " xhrUploadStart();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 68 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 69 | "function logRestart(text)\n" |
andrewboyson | 55:3d1e52e3e9b7 | 70 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 71 | " document.getElementById('restartresult').textContent = text;\n" |
andrewboyson | 55:3d1e52e3e9b7 | 72 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 73 | "function redirect()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 74 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 75 | " location.href = '/firmware';\n" |
andrewboyson | 55:3d1e52e3e9b7 | 76 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 77 | "function xhrRestartOnLoad()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 78 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 79 | " if (xhr.status == 200) logRestart('Restart should never have returned');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 80 | " else logRestart('Restart failed');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 81 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 82 | "function xhrRestartStart()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 83 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 84 | " logRestart('Restarting...');\n" |
andrewboyson | 55:3d1e52e3e9b7 | 85 | " \n" |
andrewboyson | 55:3d1e52e3e9b7 | 86 | " xhr = new XMLHttpRequest();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 87 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 88 | " xhr.onload = xhrRestartOnLoad;\n" |
andrewboyson | 55:3d1e52e3e9b7 | 89 | "\n" |
andrewboyson | 55:3d1e52e3e9b7 | 90 | " xhr.open('GET', '/firmware-ajax?restart='); //Defaults to async=true\n" |
andrewboyson | 55:3d1e52e3e9b7 | 91 | " xhr.send();\n" |
andrewboyson | 55:3d1e52e3e9b7 | 92 | " \n" |
andrewboyson | 55:3d1e52e3e9b7 | 93 | " setTimeout(redirect, 2000);\n" |
andrewboyson | 55:3d1e52e3e9b7 | 94 | "}\n" |
andrewboyson | 55:3d1e52e3e9b7 | 95 | "function restart()\n" |
andrewboyson | 55:3d1e52e3e9b7 | 96 | "{\n" |
andrewboyson | 55:3d1e52e3e9b7 | 97 | " xhrRestartStart();\n" |
andrewboyson | 48:4e678727c4c9 | 98 | "}\n" |
andrewboyson | 149:24365666d28d | 99 | "\n" |
andrewboyson | 48:4e678727c4c9 | 100 | "" |