Andrew Boyson / oldheating

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers web-system-html.c Source File

web-system-html.c

00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 #include "http.h"
00005 #include "web-nav-this.h"
00006 #include "web-add.h"
00007 #include "log.h"
00008 #include "bignum.h"
00009 #include "rsa.h"
00010 #include "sha256.h"
00011 #include "hmac-sha256.h"
00012 #include "tls-prf.h"
00013 #include "aes128cbc.h"
00014 #include "sha1.h"
00015 #include "pri-key.h"
00016 
00017 void WebSystemHtml()
00018 {
00019     HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL);
00020     WebAddHeader("System", "settings.css", "system.js");
00021     WebAddNav(SYSTEM_PAGE);
00022     WebAddH1("System");
00023 
00024     WebAddH2("TFTP");
00025     WebAddAjaxInput   ("Server url",                      5, "ajax-server-name",   "tftpserver"   );
00026     WebAddAjaxInput   ("File (strftime)",                11, "ajax-file-name",     "tftpfilename" );
00027     WebAddAjaxInput   ("Interval (secs) 0=no",            5, "ajax-read-interval", "tftpreadint"  );
00028     WebAddAjaxInput   ("Records per backup 0=no",         5, "ajax-write-size",    "tftpwriteint" );
00029     WebAddAjaxLabelled("Count",                              "ajax-count"                         );
00030     WebAddAjaxLabelled("Started",                            "ajax-start-time"                    );
00031 
00032     WebAddH2("FRAM");
00033     WebAddAjaxLabelled("Used",                               "ajax-fram-used"                     );
00034     
00035     WebAddH2("Compiler");
00036     WebAddLabelledInt("Version Vvvbbbb", __ARMCC_VERSION);
00037         
00038     WebAddH2("AES 128 test");
00039     uint8_t aeskey[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c };
00040     uint8_t in[]  = { 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
00041                       0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee, 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
00042                       0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b, 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
00043                       0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 };
00044     uint8_t iv[]  = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
00045     /*
00046     uint8_t out[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
00047                       0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
00048                       0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
00049                       0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 };
00050     */
00051 
00052     Aes128CbcDecrypt(aeskey, iv, in, 64);
00053     HttpAddText("<code>");
00054     HttpAddBytesAsHex(in, sizeof(in));
00055     HttpAddText("</code>");
00056     
00057     WebAddH2("SHA 256 stream test");
00058     uint8_t hash[32];
00059     char* input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
00060     struct Sha256State sha256state;
00061     Sha256Start (&sha256state);
00062     Sha256Add   (&sha256state, (uint8_t*)input, strlen(input));
00063     Sha256Finish(&sha256state, (uint8_t*)hash);
00064 
00065     HttpAddText("<code>");
00066     HttpAddBytesAsHex(hash, sizeof(hash));
00067     HttpAddText("</code>");
00068     
00069     WebAddH2("SHA1 stream test");
00070     struct Sha1State sha1state;
00071     Sha1Start (&sha1state);
00072     Sha1Add   (&sha1state, (uint8_t*)input, strlen(input));
00073     Sha1Finish(&sha1state, (uint8_t*)hash);
00074 
00075     HttpAddText("<code>");
00076     HttpAddBytesAsHex(hash, SHA1_HASH_SIZE);
00077     HttpAddText("</code>");
00078     
00079     WebAddH2("HMAC SHA 256 test");
00080     char* key = "Jefe";
00081     char* msg = "what do ya want for nothing?";
00082     uint8_t mac[32];
00083     HmacSha256((uint8_t*)key, strlen(key), (uint8_t*)msg, strlen(msg), mac);
00084     HttpAddText("<code>");
00085     HttpAddBytesAsHex(mac, sizeof(mac));
00086     HttpAddText("</code>");
00087     
00088     WebAddH2("HMAC SHA 256 stream test");
00089     struct HmacSha256Struct hmacState;
00090     HmacSha256Start (&hmacState, (uint8_t*)key, strlen(key));
00091     HmacSha256Add   (&hmacState, (uint8_t*)msg, strlen(msg));
00092     HmacSha256Finish(&hmacState, mac);
00093     HttpAddText("<code>");
00094     HttpAddBytesAsHex(mac, sizeof(mac));
00095     HttpAddText("</code>");
00096     
00097     WebAddH2("Verify data test");
00098     uint8_t masterSecret  [48] = {0x91, 0x6a, 0xbf, 0x9d, 0xa5, 0x59, 0x73, 0xe1,
00099                                   0x36, 0x14, 0xae, 0x0a, 0x3f, 0x5d, 0x3f, 0x37,
00100                                   0xb0, 0x23, 0xba, 0x12, 0x9a, 0xee, 0x02, 0xcc,
00101                                   0x91, 0x34, 0x33, 0x81, 0x27, 0xcd, 0x70, 0x49,
00102                                   0x78, 0x1c, 0x8e, 0x19, 0xfc, 0x1e, 0xb2, 0xa7,
00103                                   0x38, 0x7a, 0xc0, 0x6a, 0xe2, 0x37, 0x34, 0x4c};
00104                                   
00105     uint8_t hashHandshakes[32] = {0xb2, 0x01, 0x7b, 0xa2, 0x8d, 0x0e, 0x27, 0xf0, 
00106                                   0x3a, 0xe3, 0x27, 0x45, 0x6b, 0x6f, 0xf0, 0x0b,
00107                                   0x4d, 0x5b, 0xbf, 0x0e, 0xf7, 0xcd, 0xa8, 0x3c,
00108                                   0xe1, 0x02, 0x9b, 0x52, 0x1c, 0x3e, 0x7c, 0x35};
00109     uint8_t verifyData[12];
00110     TlsPrfServerFinished(masterSecret, hashHandshakes, verifyData);
00111     
00112     HttpAddText("<code>");
00113     HttpAddBytesAsHex(verifyData, sizeof(verifyData));
00114     HttpAddText("</code>");
00115     
00116     
00117     WebAddH2("Key test");
00118     
00119     uint8_t clientRandom[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
00120                                0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
00121                                0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
00122                                0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
00123                                
00124     uint8_t serverRandom[] = { 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
00125                                0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
00126                                0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
00127                                0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f };
00128 
00129     uint8_t client_MAC_key_20[20];
00130     uint8_t server_MAC_key_20[20];
00131     uint8_t client_key_16[16];
00132     uint8_t server_key_16[16];
00133     TlsPrfKeysAes128Sha1(masterSecret, clientRandom, serverRandom, client_MAC_key_20, server_MAC_key_20, client_key_16, server_key_16);
00134     HttpAddText("<code>");
00135     HttpAddBytesAsHex(client_MAC_key_20, sizeof(client_MAC_key_20)); HttpAddText("\r\n");
00136     HttpAddBytesAsHex(server_MAC_key_20, sizeof(server_MAC_key_20)); HttpAddText("\r\n");
00137     HttpAddBytesAsHex(    client_key_16, sizeof(    client_key_16)); HttpAddText("\r\n");
00138     HttpAddBytesAsHex(    server_key_16, sizeof(    server_key_16));
00139     HttpAddText("</code>");
00140 
00141     
00142     
00143     char* m =
00144 "0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
00145 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
00146 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00302130"
00147 "0906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D";
00148 
00149     uint32_t message [32];
00150     BnParseHex1024(message,  m);
00151     
00152     /*
00153     WebAddH2("RSA test");
00154 
00155     char* n =
00156 "E08973398DD8F5F5E88776397F4EB005BB5383DE0FB7ABDC7DC775290D052E6D"
00157 "12DFA68626D4D26FAA5829FC97ECFA82510F3080BEB1509E4644F12CBBD832CF"
00158 "C6686F07D9B060ACBEEE34096A13F5F7050593DF5EBA3556D961FF197FC981E6"
00159 "F86CEA874070EFAC6D2C749F2DFA553AB9997702A648528C4EF357385774575F";
00160 
00161     char* d =
00162 "00A403C327477634346CA686B57949014B2E8AD2C862B2C7D748096A8B91F736"
00163 "F275D6E8CD15906027314735644D95CD6763CEB49F56AC2F376E1CEE0EBF282D"
00164 "F439906F34D86E085BD5656AD841F313D72D395EFE33CBFF29E4030B3D05A28F"
00165 "B7F18EA27637B07957D32F2BDE8706227D04665EC91BAF8B1AC3EC9144AB7F21";
00166 
00167     uint32_t exponent[32];
00168     uint32_t modulus [32];
00169     
00170     BnParseHex1024(exponent, d);
00171     BnParseHex1024(modulus,  n);
00172 
00173     static int ticket = 0;
00174     static bool started = false;
00175     if (!started)
00176     {
00177         ticket = RsaSlowStart(message, exponent, modulus);
00178         started = true;
00179     }
00180     
00181     HttpAddText("<code>");
00182     HttpAddText("Message\r\n");
00183     BnAsHttp1024(message);
00184     HttpAddText("\r\nExponent\r\n");
00185     BnAsHttp1024(exponent);
00186     HttpAddText("\r\nModulus\r\n");
00187     BnAsHttp1024(modulus);
00188     HttpAddText("\r\nResult\r\n");
00189     if (ticket >= 0)
00190     {
00191         if (RsaSlowFinished(ticket)) HttpAddText("Finished\r\n");
00192         else                         HttpAddText("Not finished\r\n");
00193         BnAsHttp1024(RsaSlowResult(ticket));
00194     }
00195     else
00196     {
00197         HttpAddText("No ticket available to calculate result\r\n");
00198     }
00199     HttpAddText("</code>");
00200     */
00201     
00202     WebAddH2("RSA test");
00203     static int rsaTicket = 0;
00204     static bool rsaSlowStarted = false;
00205     if (!rsaSlowStarted)
00206     {
00207         rsaTicket = PriKeyDecryptStart((uint8_t*)message);
00208         rsaSlowStarted = true;
00209     }
00210     
00211     HttpAddText("<code>");
00212     HttpAddText("Message\r\n");
00213     BnAsHttp1024(message);
00214     HttpAddText("\r\nResult\r\n");
00215     if (rsaTicket >= 0)
00216     {
00217         if (PriKeyDecryptFinished(rsaTicket)) HttpAddText("Finished\r\n");
00218         else                                  HttpAddText("Not finished\r\n");
00219         BnAsHttp1024((uint32_t*)PriKeyDecryptResultLittleEndian(rsaTicket));
00220     }
00221     else
00222     {
00223         HttpAddText("No ticket available to calculate result\r\n");
00224     }
00225     HttpAddText("</code>");
00226     
00227     WebAddEnd();
00228 }