Central Heating controller using the real time clock, PHY module for internet, 1-wire interface for temperature sensors, a system log and a configuration file

Dependencies:   net 1-wire lpc1768 crypto clock web fram log

/media/uploads/andrewboyson/heating.sch

/media/uploads/andrewboyson/heating.brd

/media/uploads/andrewboyson/eagle.epf

Committer:
andrewboyson
Date:
Tue Sep 24 18:17:49 2019 +0000
Revision:
74:8228f0297227
Parent:
72:13bc405bd40b
Child:
75:cc9a1e104e0e
Updated libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 49:9491c966dc60 1 #include <stdio.h>
andrewboyson 67:2d379b0c5f05 2 #include <string.h>
andrewboyson 49:9491c966dc60 3
andrewboyson 49:9491c966dc60 4 #include "http.h"
andrewboyson 53:c1bf7d9db507 5 #include "web-nav-this.h"
andrewboyson 51:c7c6ce0d57ad 6 #include "web-add.h"
andrewboyson 67:2d379b0c5f05 7 #include "log.h"
andrewboyson 63:ae264156d655 8 #include "bignum.h"
andrewboyson 74:8228f0297227 9 #include "rsa.h"
andrewboyson 69:ca9010196c6e 10 #include "sha256.h"
andrewboyson 74:8228f0297227 11 #include "hmac-sha256.h"
andrewboyson 69:ca9010196c6e 12 #include "tls-prf.h"
andrewboyson 71:9edbc59d6f64 13 #include "aes128.h"
andrewboyson 71:9edbc59d6f64 14 #include "sha1.h"
andrewboyson 49:9491c966dc60 15
andrewboyson 49:9491c966dc60 16 void WebSystemHtml()
andrewboyson 49:9491c966dc60 17 {
andrewboyson 49:9491c966dc60 18 HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL);
andrewboyson 51:c7c6ce0d57ad 19 WebAddHeader("System", "settings.css", "system.js");
andrewboyson 51:c7c6ce0d57ad 20 WebAddNav(SYSTEM_PAGE);
andrewboyson 51:c7c6ce0d57ad 21 WebAddH1("System");
andrewboyson 49:9491c966dc60 22
andrewboyson 51:c7c6ce0d57ad 23 WebAddH2("TFTP");
andrewboyson 51:c7c6ce0d57ad 24 WebAddAjaxInput ("Server url", 5, "ajax-server-name", "tftpserver" );
andrewboyson 51:c7c6ce0d57ad 25 WebAddAjaxInput ("File (strftime)", 11, "ajax-file-name", "tftpfilename" );
andrewboyson 51:c7c6ce0d57ad 26 WebAddAjaxInput ("Interval (secs) 0=no", 5, "ajax-read-interval", "tftpreadint" );
andrewboyson 51:c7c6ce0d57ad 27 WebAddAjaxInput ("Records per backup 0=no", 5, "ajax-write-size", "tftpwriteint" );
andrewboyson 51:c7c6ce0d57ad 28 WebAddAjaxLabelled("Count", "ajax-count" );
andrewboyson 51:c7c6ce0d57ad 29 WebAddAjaxLabelled("Started", "ajax-start-time" );
andrewboyson 49:9491c966dc60 30
andrewboyson 51:c7c6ce0d57ad 31 WebAddH2("FRAM");
andrewboyson 51:c7c6ce0d57ad 32 WebAddAjaxLabelled("Used", "ajax-fram-used" );
andrewboyson 49:9491c966dc60 33
andrewboyson 51:c7c6ce0d57ad 34 WebAddH2("Compiler");
andrewboyson 51:c7c6ce0d57ad 35 WebAddLabelledInt("Version Vvvbbbb", __ARMCC_VERSION);
andrewboyson 71:9edbc59d6f64 36
andrewboyson 71:9edbc59d6f64 37 WebAddH2("AES 128 test");
andrewboyson 71:9edbc59d6f64 38 uint8_t aeskey[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c };
andrewboyson 71:9edbc59d6f64 39 uint8_t in[] = { 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
andrewboyson 71:9edbc59d6f64 40 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee, 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
andrewboyson 71:9edbc59d6f64 41 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b, 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
andrewboyson 71:9edbc59d6f64 42 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 };
andrewboyson 71:9edbc59d6f64 43 uint8_t iv[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
andrewboyson 71:9edbc59d6f64 44 /*
andrewboyson 71:9edbc59d6f64 45 uint8_t out[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
andrewboyson 71:9edbc59d6f64 46 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
andrewboyson 71:9edbc59d6f64 47 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
andrewboyson 71:9edbc59d6f64 48 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 };
andrewboyson 71:9edbc59d6f64 49 */
andrewboyson 71:9edbc59d6f64 50 struct AES_ctx ctx;
andrewboyson 71:9edbc59d6f64 51
andrewboyson 71:9edbc59d6f64 52 AES_init_ctx_iv(&ctx, aeskey, iv);
andrewboyson 71:9edbc59d6f64 53 AES_CBC_decrypt_buffer(&ctx, in, 64);
andrewboyson 67:2d379b0c5f05 54 HttpAddText("<code>");
andrewboyson 71:9edbc59d6f64 55 HttpAddBytesAsHex(in, sizeof(in));
andrewboyson 69:ca9010196c6e 56 HttpAddText("</code>");
andrewboyson 69:ca9010196c6e 57
andrewboyson 69:ca9010196c6e 58 WebAddH2("SHA 256 stream test");
andrewboyson 71:9edbc59d6f64 59 uint8_t hash[32];
andrewboyson 71:9edbc59d6f64 60 char* input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
andrewboyson 69:ca9010196c6e 61 struct Sha256State sha256state;
andrewboyson 69:ca9010196c6e 62 Sha256Start (&sha256state);
andrewboyson 69:ca9010196c6e 63 Sha256Add (&sha256state, (uint8_t*)input, strlen(input));
andrewboyson 69:ca9010196c6e 64 Sha256Finish(&sha256state, (uint8_t*)hash);
andrewboyson 69:ca9010196c6e 65
andrewboyson 69:ca9010196c6e 66 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 67 HttpAddBytesAsHex(hash, sizeof(hash));
andrewboyson 67:2d379b0c5f05 68 HttpAddText("</code>");
andrewboyson 67:2d379b0c5f05 69
andrewboyson 71:9edbc59d6f64 70 WebAddH2("SHA1 stream test");
andrewboyson 72:13bc405bd40b 71 struct Sha1State sha1state;
andrewboyson 72:13bc405bd40b 72 Sha1Start (&sha1state);
andrewboyson 72:13bc405bd40b 73 Sha1Add (&sha1state, (uint8_t*)input, strlen(input));
andrewboyson 72:13bc405bd40b 74 Sha1Finish(&sha1state, (uint8_t*)hash);
andrewboyson 71:9edbc59d6f64 75
andrewboyson 71:9edbc59d6f64 76 HttpAddText("<code>");
andrewboyson 72:13bc405bd40b 77 HttpAddBytesAsHex(hash, SHA1_HASH_SIZE);
andrewboyson 71:9edbc59d6f64 78 HttpAddText("</code>");
andrewboyson 71:9edbc59d6f64 79
andrewboyson 67:2d379b0c5f05 80 WebAddH2("HMAC SHA 256 test");
andrewboyson 67:2d379b0c5f05 81 char* key = "Jefe";
andrewboyson 67:2d379b0c5f05 82 char* msg = "what do ya want for nothing?";
andrewboyson 69:ca9010196c6e 83 uint8_t mac[32];
andrewboyson 69:ca9010196c6e 84 HmacSha256((uint8_t*)key, strlen(key), (uint8_t*)msg, strlen(msg), mac);
andrewboyson 69:ca9010196c6e 85 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 86 HttpAddBytesAsHex(mac, sizeof(mac));
andrewboyson 69:ca9010196c6e 87 HttpAddText("</code>");
andrewboyson 69:ca9010196c6e 88
andrewboyson 69:ca9010196c6e 89 WebAddH2("HMAC SHA 256 stream test");
andrewboyson 69:ca9010196c6e 90 struct HmacSha256Struct hmacState;
andrewboyson 69:ca9010196c6e 91 HmacSha256Start (&hmacState, (uint8_t*)key, strlen(key));
andrewboyson 69:ca9010196c6e 92 HmacSha256Add (&hmacState, (uint8_t*)msg, strlen(msg));
andrewboyson 69:ca9010196c6e 93 HmacSha256Finish(&hmacState, mac);
andrewboyson 67:2d379b0c5f05 94 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 95 HttpAddBytesAsHex(mac, sizeof(mac));
andrewboyson 67:2d379b0c5f05 96 HttpAddText("</code>");
andrewboyson 67:2d379b0c5f05 97
andrewboyson 69:ca9010196c6e 98 WebAddH2("Verify data test");
andrewboyson 69:ca9010196c6e 99 uint8_t masterSecret [48] = {0x91, 0x6a, 0xbf, 0x9d, 0xa5, 0x59, 0x73, 0xe1,
andrewboyson 69:ca9010196c6e 100 0x36, 0x14, 0xae, 0x0a, 0x3f, 0x5d, 0x3f, 0x37,
andrewboyson 69:ca9010196c6e 101 0xb0, 0x23, 0xba, 0x12, 0x9a, 0xee, 0x02, 0xcc,
andrewboyson 69:ca9010196c6e 102 0x91, 0x34, 0x33, 0x81, 0x27, 0xcd, 0x70, 0x49,
andrewboyson 69:ca9010196c6e 103 0x78, 0x1c, 0x8e, 0x19, 0xfc, 0x1e, 0xb2, 0xa7,
andrewboyson 69:ca9010196c6e 104 0x38, 0x7a, 0xc0, 0x6a, 0xe2, 0x37, 0x34, 0x4c};
andrewboyson 69:ca9010196c6e 105
andrewboyson 69:ca9010196c6e 106 uint8_t hashHandshakes[32] = {0xb2, 0x01, 0x7b, 0xa2, 0x8d, 0x0e, 0x27, 0xf0,
andrewboyson 69:ca9010196c6e 107 0x3a, 0xe3, 0x27, 0x45, 0x6b, 0x6f, 0xf0, 0x0b,
andrewboyson 69:ca9010196c6e 108 0x4d, 0x5b, 0xbf, 0x0e, 0xf7, 0xcd, 0xa8, 0x3c,
andrewboyson 69:ca9010196c6e 109 0xe1, 0x02, 0x9b, 0x52, 0x1c, 0x3e, 0x7c, 0x35};
andrewboyson 69:ca9010196c6e 110 uint8_t verifyData[12];
andrewboyson 71:9edbc59d6f64 111 TlsPrfServerFinished(masterSecret, hashHandshakes, verifyData);
andrewboyson 69:ca9010196c6e 112
andrewboyson 69:ca9010196c6e 113 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 114 HttpAddBytesAsHex(verifyData, sizeof(verifyData));
andrewboyson 69:ca9010196c6e 115 HttpAddText("</code>");
andrewboyson 69:ca9010196c6e 116
andrewboyson 69:ca9010196c6e 117
andrewboyson 71:9edbc59d6f64 118 WebAddH2("Key test");
andrewboyson 71:9edbc59d6f64 119
andrewboyson 71:9edbc59d6f64 120 uint8_t clientRandom[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
andrewboyson 71:9edbc59d6f64 121 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
andrewboyson 71:9edbc59d6f64 122 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
andrewboyson 71:9edbc59d6f64 123 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
andrewboyson 71:9edbc59d6f64 124
andrewboyson 71:9edbc59d6f64 125 uint8_t serverRandom[] = { 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
andrewboyson 71:9edbc59d6f64 126 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
andrewboyson 71:9edbc59d6f64 127 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
andrewboyson 71:9edbc59d6f64 128 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f };
andrewboyson 71:9edbc59d6f64 129
andrewboyson 71:9edbc59d6f64 130 uint8_t client_MAC_key_20[20];
andrewboyson 71:9edbc59d6f64 131 uint8_t server_MAC_key_20[20];
andrewboyson 71:9edbc59d6f64 132 uint8_t client_key_16[16];
andrewboyson 71:9edbc59d6f64 133 uint8_t server_key_16[16];
andrewboyson 71:9edbc59d6f64 134 TlsPrfKeys(masterSecret, clientRandom, serverRandom, client_MAC_key_20, server_MAC_key_20, client_key_16, server_key_16);
andrewboyson 71:9edbc59d6f64 135 HttpAddText("<code>");
andrewboyson 71:9edbc59d6f64 136 HttpAddBytesAsHex(client_MAC_key_20, sizeof(client_MAC_key_20));
andrewboyson 71:9edbc59d6f64 137 HttpAddBytesAsHex(server_MAC_key_20, sizeof(server_MAC_key_20));
andrewboyson 71:9edbc59d6f64 138 HttpAddBytesAsHex(client_key_16, sizeof(client_key_16));
andrewboyson 71:9edbc59d6f64 139 HttpAddBytesAsHex(server_key_16, sizeof(server_key_16));
andrewboyson 71:9edbc59d6f64 140 HttpAddText("</code>");
andrewboyson 71:9edbc59d6f64 141
andrewboyson 71:9edbc59d6f64 142
andrewboyson 69:ca9010196c6e 143
andrewboyson 74:8228f0297227 144 WebAddH2("RSA slow test");
andrewboyson 63:ae264156d655 145
andrewboyson 63:ae264156d655 146 char* n =
andrewboyson 63:ae264156d655 147 "E08973398DD8F5F5E88776397F4EB005BB5383DE0FB7ABDC7DC775290D052E6D"
andrewboyson 63:ae264156d655 148 "12DFA68626D4D26FAA5829FC97ECFA82510F3080BEB1509E4644F12CBBD832CF"
andrewboyson 63:ae264156d655 149 "C6686F07D9B060ACBEEE34096A13F5F7050593DF5EBA3556D961FF197FC981E6"
andrewboyson 63:ae264156d655 150 "F86CEA874070EFAC6D2C749F2DFA553AB9997702A648528C4EF357385774575F";
andrewboyson 63:ae264156d655 151
andrewboyson 63:ae264156d655 152 char* d =
andrewboyson 63:ae264156d655 153 "00A403C327477634346CA686B57949014B2E8AD2C862B2C7D748096A8B91F736"
andrewboyson 63:ae264156d655 154 "F275D6E8CD15906027314735644D95CD6763CEB49F56AC2F376E1CEE0EBF282D"
andrewboyson 63:ae264156d655 155 "F439906F34D86E085BD5656AD841F313D72D395EFE33CBFF29E4030B3D05A28F"
andrewboyson 63:ae264156d655 156 "B7F18EA27637B07957D32F2BDE8706227D04665EC91BAF8B1AC3EC9144AB7F21";
andrewboyson 64:c736b8924574 157
andrewboyson 63:ae264156d655 158 char* m =
andrewboyson 63:ae264156d655 159 "0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
andrewboyson 63:ae264156d655 160 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
andrewboyson 63:ae264156d655 161 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00302130"
andrewboyson 63:ae264156d655 162 "0906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D";
andrewboyson 49:9491c966dc60 163
andrewboyson 64:c736b8924574 164 uint32_t message [32];
andrewboyson 64:c736b8924574 165 uint32_t exponent[32];
andrewboyson 64:c736b8924574 166 uint32_t modulus [32];
andrewboyson 63:ae264156d655 167
andrewboyson 64:c736b8924574 168 BnParseHex1024(message, m);
andrewboyson 64:c736b8924574 169 BnParseHex1024(exponent, d);
andrewboyson 64:c736b8924574 170 BnParseHex1024(modulus, n);
andrewboyson 63:ae264156d655 171
andrewboyson 68:19c5efffc900 172 static int ticket = 0;
andrewboyson 63:ae264156d655 173
andrewboyson 63:ae264156d655 174 static bool started = false;
andrewboyson 63:ae264156d655 175 if (!started)
andrewboyson 63:ae264156d655 176 {
andrewboyson 74:8228f0297227 177 ticket = RsaSlowStart(message, exponent, modulus);
andrewboyson 63:ae264156d655 178 started = true;
andrewboyson 63:ae264156d655 179 }
andrewboyson 63:ae264156d655 180
andrewboyson 63:ae264156d655 181 HttpAddText("<code>");
andrewboyson 63:ae264156d655 182 HttpAddText("Message\r\n");
andrewboyson 64:c736b8924574 183 BnAsHttp1024(message);
andrewboyson 63:ae264156d655 184 HttpAddText("\r\nExponent\r\n");
andrewboyson 64:c736b8924574 185 BnAsHttp1024(exponent);
andrewboyson 63:ae264156d655 186 HttpAddText("\r\nModulus\r\n");
andrewboyson 64:c736b8924574 187 BnAsHttp1024(modulus);
andrewboyson 63:ae264156d655 188 HttpAddText("\r\nResult\r\n");
andrewboyson 68:19c5efffc900 189 if (ticket >= 0)
andrewboyson 63:ae264156d655 190 {
andrewboyson 74:8228f0297227 191 if (RsaSlowFinished(ticket)) HttpAddText("Finished\r\n");
andrewboyson 74:8228f0297227 192 else HttpAddText("Not finished\r\n");
andrewboyson 74:8228f0297227 193 BnAsHttp1024(RsaSlowResult(ticket));
andrewboyson 68:19c5efffc900 194 }
andrewboyson 68:19c5efffc900 195 else
andrewboyson 68:19c5efffc900 196 {
andrewboyson 68:19c5efffc900 197 HttpAddText("No ticket available to calculate result\r\n");
andrewboyson 63:ae264156d655 198 }
andrewboyson 63:ae264156d655 199 HttpAddText("</code>");
andrewboyson 63:ae264156d655 200
andrewboyson 63:ae264156d655 201 WebAddEnd();
andrewboyson 49:9491c966dc60 202 }