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:
110:8ab752842d25
Amalgamated Reply into Poll function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 103:91194cc19bbb 1 #include <stdint.h>
andrewboyson 103:91194cc19bbb 2 #include <stdio.h>
andrewboyson 103:91194cc19bbb 3
andrewboyson 103:91194cc19bbb 4 #include "http.h"
andrewboyson 103:91194cc19bbb 5 #include "rtc.h"
andrewboyson 103:91194cc19bbb 6 #include "clk.h"
andrewboyson 103:91194cc19bbb 7 #include "clktime.h"
andrewboyson 103:91194cc19bbb 8 #include "clkgov.h"
andrewboyson 103:91194cc19bbb 9 #include "clkutc.h"
andrewboyson 109:3e82f62c7e1f 10 #include "ntpclient.h"
andrewboyson 103:91194cc19bbb 11 #include "scan.h"
andrewboyson 103:91194cc19bbb 12
andrewboyson 103:91194cc19bbb 13 void WebClockAjax()
andrewboyson 103:91194cc19bbb 14 {
andrewboyson 103:91194cc19bbb 15 HttpOk("text/plain; charset=UTF-8", "no-cache", NULL, NULL);
andrewboyson 103:91194cc19bbb 16
andrewboyson 103:91194cc19bbb 17 //Time and UTC
andrewboyson 103:91194cc19bbb 18 clktime now = ClkNowTai();
andrewboyson 103:91194cc19bbb 19 clktime fraction = now & ((1UL << CLK_TIME_ONE_SECOND_SHIFT) - 1);
andrewboyson 103:91194cc19bbb 20 clktime ms = (fraction * 1000) >> CLK_TIME_ONE_SECOND_SHIFT;
andrewboyson 103:91194cc19bbb 21 HttpAddInt16AsHex(ms ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 22 char byte = 0;
andrewboyson 103:91194cc19bbb 23 if (RtcIsSet() ) byte |= 0x01;
andrewboyson 103:91194cc19bbb 24 if (ClkTimeIsSet() ) byte |= 0x02;
andrewboyson 103:91194cc19bbb 25 if (ClkGovIsReceivingTime ) byte |= 0x04;
andrewboyson 103:91194cc19bbb 26 if (ClkGovRateIsSynced ) byte |= 0x08;
andrewboyson 103:91194cc19bbb 27 if (ClkGovTimeIsSynced ) byte |= 0x10;
andrewboyson 103:91194cc19bbb 28 if (ClkUtcGetNextLeapEnable() ) byte |= 0x20;
andrewboyson 103:91194cc19bbb 29 if (ClkUtcGetNextLeapForward()) byte |= 0x40;
andrewboyson 103:91194cc19bbb 30 if (ClkGovTrace) byte |= 0x80;
andrewboyson 103:91194cc19bbb 31 HttpAddByteAsHex (byte ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 32 HttpAddInt12AsHex(ClkUtcGetNextEpochMonth1970()); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 33 HttpAddInt16AsHex(ClkUtcGetEpochOffset() ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 34 HttpAddChar('\f');
andrewboyson 103:91194cc19bbb 35
andrewboyson 103:91194cc19bbb 36 //Governer
andrewboyson 103:91194cc19bbb 37 HttpAddInt32AsHex(ClkGovGetPpb() ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 38 HttpAddInt32AsHex(ClkGovFreqDivisor ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 39 HttpAddInt32AsHex(ClkGovFreqChangeMaxPpb ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 40 HttpAddInt32AsHex(ClkGovFreqSyncedLimPpb ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 41 HttpAddInt32AsHex(ClkGovFreqSyncedHysPpb ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 42 HttpAddInt32AsHex(ClkGovSlewDivisor ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 43 HttpAddInt32AsHex(ClkGovSlewChangeMaxMs ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 44 HttpAddInt32AsHex(ClkGovSlewSyncedLimNs ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 45 HttpAddInt32AsHex(ClkGovSlewSyncedHysNs ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 46 HttpAddInt32AsHex(ClkGovSlewOffsetMaxSecs ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 47 HttpAddChar('\f');
andrewboyson 103:91194cc19bbb 48
andrewboyson 103:91194cc19bbb 49 //NTP
andrewboyson 103:91194cc19bbb 50 HttpAddText (NtpClientQueryServerName ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 51 HttpAddInt32AsHex(NtpClientQueryInitialInterval); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 52 HttpAddInt32AsHex(NtpClientQueryNormalInterval ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 53 HttpAddInt32AsHex(NtpClientQueryRetryInterval ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 54 HttpAddInt32AsHex(NtpClientReplyOffsetMs ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 55 HttpAddInt32AsHex(NtpClientReplyMaxDelayMs ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 56 HttpAddChar('\f');
andrewboyson 103:91194cc19bbb 57
andrewboyson 103:91194cc19bbb 58 //Scan
andrewboyson 103:91194cc19bbb 59 HttpAddInt32AsHex(ScanAverage ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 60 HttpAddInt32AsHex(ScanMaximum ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 61 HttpAddInt32AsHex(ScanMinimum ); HttpAddChar('\n');
andrewboyson 103:91194cc19bbb 62 HttpAddChar('\f');
andrewboyson 103:91194cc19bbb 63 }
andrewboyson 103:91194cc19bbb 64