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

web-this/system/web-system-html.c

Committer:
andrewboyson
Date:
2019-08-28
Revision:
70:c7d0d3d926e1
Parent:
69:ca9010196c6e
Child:
71:9edbc59d6f64

File content as of revision 70:c7d0d3d926e1:

#include <stdio.h>
#include <string.h>

#include "http.h"
#include "web-nav-this.h"
#include "web-add.h"
#include "log.h"
#include "bignum.h"
#include "sha-256.h"
#include "sha256.h"
#include "hmac-sha-256.h"
#include "tls-prf.h"

void WebSystemHtml()
{
    HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL);
    WebAddHeader("System", "settings.css", "system.js");
    WebAddNav(SYSTEM_PAGE);
    WebAddH1("System");

    WebAddH2("TFTP");
    WebAddAjaxInput   ("Server url",                      5, "ajax-server-name",   "tftpserver"   );
    WebAddAjaxInput   ("File (strftime)",                11, "ajax-file-name",     "tftpfilename" );
    WebAddAjaxInput   ("Interval (secs) 0=no",            5, "ajax-read-interval", "tftpreadint"  );
    WebAddAjaxInput   ("Records per backup 0=no",         5, "ajax-write-size",    "tftpwriteint" );
    WebAddAjaxLabelled("Count",                              "ajax-count"                         );
    WebAddAjaxLabelled("Started",                            "ajax-start-time"                    );

    WebAddH2("FRAM");
    WebAddAjaxLabelled("Used",                               "ajax-fram-used"                     );
    
    WebAddH2("Compiler");
    WebAddLabelledInt("Version Vvvbbbb", __ARMCC_VERSION);
    
    WebAddH2("SHA 256 test");
    uint8_t hash[32];
    char* input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
    Sha256Old((uint8_t*)input, strlen(input), hash);
    HttpAddText("<code>");
    HttpAddBytesAsHex(hash, sizeof(hash));
    HttpAddText("</code>");
    
    WebAddH2("SHA 256 stream test");
    struct Sha256State sha256state;
    Sha256Start (&sha256state);
    Sha256Add   (&sha256state, (uint8_t*)input, strlen(input));
    Sha256Finish(&sha256state, (uint8_t*)hash);

    HttpAddText("<code>");
    HttpAddBytesAsHex(hash, sizeof(hash));
    HttpAddText("</code>");
    
    WebAddH2("HMAC SHA 256 test");
    char* key = "Jefe";
    char* msg = "what do ya want for nothing?";
    uint8_t mac[32];
    HmacSha256((uint8_t*)key, strlen(key), (uint8_t*)msg, strlen(msg), mac);
    HttpAddText("<code>");
    HttpAddBytesAsHex(mac, sizeof(mac));
    HttpAddText("</code>");
    
    WebAddH2("HMAC SHA 256 stream test");
    struct HmacSha256Struct hmacState;
    HmacSha256Start (&hmacState, (uint8_t*)key, strlen(key));
    HmacSha256Add   (&hmacState, (uint8_t*)msg, strlen(msg));
    HmacSha256Finish(&hmacState, mac);
    HttpAddText("<code>");
    HttpAddBytesAsHex(mac, sizeof(mac));
    HttpAddText("</code>");
    
    WebAddH2("Verify data test");
    uint8_t masterSecret  [48] = {0x91, 0x6a, 0xbf, 0x9d, 0xa5, 0x59, 0x73, 0xe1,
                                  0x36, 0x14, 0xae, 0x0a, 0x3f, 0x5d, 0x3f, 0x37,
                                  0xb0, 0x23, 0xba, 0x12, 0x9a, 0xee, 0x02, 0xcc,
                                  0x91, 0x34, 0x33, 0x81, 0x27, 0xcd, 0x70, 0x49,
                                  0x78, 0x1c, 0x8e, 0x19, 0xfc, 0x1e, 0xb2, 0xa7,
                                  0x38, 0x7a, 0xc0, 0x6a, 0xe2, 0x37, 0x34, 0x4c};
                                  
    uint8_t hashHandshakes[32] = {0xb2, 0x01, 0x7b, 0xa2, 0x8d, 0x0e, 0x27, 0xf0, 
                                  0x3a, 0xe3, 0x27, 0x45, 0x6b, 0x6f, 0xf0, 0x0b,
                                  0x4d, 0x5b, 0xbf, 0x0e, 0xf7, 0xcd, 0xa8, 0x3c,
                                  0xe1, 0x02, 0x9b, 0x52, 0x1c, 0x3e, 0x7c, 0x35};
    uint8_t verifyData[12];
    TlsPrfServerFinished12(masterSecret, hashHandshakes, verifyData);
    
    HttpAddText("<code>");
    HttpAddBytesAsHex(verifyData, sizeof(verifyData));
    HttpAddText("</code>");
    
    
    
    WebAddH2("Big num test");

    char* n =
"E08973398DD8F5F5E88776397F4EB005BB5383DE0FB7ABDC7DC775290D052E6D"
"12DFA68626D4D26FAA5829FC97ECFA82510F3080BEB1509E4644F12CBBD832CF"
"C6686F07D9B060ACBEEE34096A13F5F7050593DF5EBA3556D961FF197FC981E6"
"F86CEA874070EFAC6D2C749F2DFA553AB9997702A648528C4EF357385774575F";

    char* d =
"00A403C327477634346CA686B57949014B2E8AD2C862B2C7D748096A8B91F736"
"F275D6E8CD15906027314735644D95CD6763CEB49F56AC2F376E1CEE0EBF282D"
"F439906F34D86E085BD5656AD841F313D72D395EFE33CBFF29E4030B3D05A28F"
"B7F18EA27637B07957D32F2BDE8706227D04665EC91BAF8B1AC3EC9144AB7F21";

    char* m =
"0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00302130"
"0906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D";

    uint32_t message [32];
    uint32_t exponent[32];
    uint32_t modulus [32];
    
    BnParseHex1024(message,  m);
    BnParseHex1024(exponent, d);
    BnParseHex1024(modulus,  n);
    
    static int ticket = 0;
    
    static bool started = false;
    if (!started)
    {
        ticket = BnExpModStart(message, exponent, modulus);
        started = true;
    }
    
    HttpAddText("<code>");
    HttpAddText("Message\r\n");
    BnAsHttp1024(message);
    HttpAddText("\r\nExponent\r\n");
    BnAsHttp1024(exponent);
    HttpAddText("\r\nModulus\r\n");
    BnAsHttp1024(modulus);
    HttpAddText("\r\nResult\r\n");
    if (ticket >= 0)
    {
        switch(BnExpModStatus[ticket])
        {
            case BIGNUM_CALC_NONE:
                HttpAddText("Not started\r\n");
                break;
            case BIGNUM_CALC_STARTED:
                HttpAddF("Progress %d\r\n", BnExpModProgress[ticket]);
                BnAsHttp1024(BnExpModGetResult(ticket));
                break;
            case BIGNUM_CALC_FINISHED:
                HttpAddText("Finished\r\n");
                BnAsHttp1024(BnExpModGetResult(ticket));
                HttpAddF("Time to multiply %llu ms\r\n", BnMulHr[ticket] / 96000);
                HttpAddF("Time to modulus  %llu ms\r\n", BnModHr[ticket] / 96000);
                break;
        }
    }
    else
    {
        HttpAddText("No ticket available to calculate result\r\n");
    }
    HttpAddText("</code>");
    
    WebAddEnd();
}