//-------------------------------------------------------------------------- // Copyright 2016, RIoT International Pty Ltd // // @author Aaron Ardiri //-------------------------------------------------------------------------- // microTLS - none/rot13 //-------------------------------------------------------------------------- // configuration //-------------------------------------------------------------------------- const char WiFi_SSID[] PROGMEM = "xxxx"; const char WiFi_PASS[] PROGMEM = "xxxx"; const uint8_t SERVER[] PROGMEM = { xxx, xxx, xxx, xxx }; #define SERVER_URI "/xxx/index.php" #define SERVER_NAME "xxx.xxxxxxxx.xxx" #define CLIENT_GUID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" #define CLIENT_INTERVAL 300 // 5 minutes //-------------------------------------------------------------------------- // pre-shared keys //-------------------------------------------------------------------------- // none //-------------------------------------------------------------------------- // modules //-------------------------------------------------------------------------- #include "microTLS-module-rot13.h" #define SESS_SECURITY "none" #define PING_SECURITY "rot13" //-------------------------------------------------------------------------- // additional globals //-------------------------------------------------------------------------- typedef struct xGlobals { void *_empty_; } xGlobals; xGlobals gx; //-------------------------------------------------------------------------- // entry point //-------------------------------------------------------------------------- void microTLS_setup() { } //-------------------------------------------------------------------------- // session: creation //-------------------------------------------------------------------------- void microTLS_sess_prepare() { HashEngine ctx_hash; int ofs; SYS_RAM_CHECK; // we must prepare our send buffer g.scratch.send.len = 0; ofs = g.scratch.token.len + g.scratch.param.len + g.scratch.send.len + g.scratch.recv.len; g.scratch.send.buf = &g.scratch.reserved[ofs]; // copy the token to the send buffer, server expects it g.scratch.send.len = MIN(g.scratch.token.len, CLIENT_SCRATCH_LEN - ofs); memcpy((char *)g.scratch.send.buf, (char *)g.scratch.token.buf, g.scratch.send.len); // we need to generate an integrity hash for the buffer we are sending hashInit(&ctx_hash); hashUpdate(&ctx_hash, g.scratch.send.buf, g.scratch.send.len); hashFinal(&ctx_hash); g.scratch.send.digest = ctx_hash.digest; } bool microTLS_sess_process() { return false; } //-------------------------------------------------------------------------- // session: update //-------------------------------------------------------------------------- const char msg[] PROGMEM = "sending a message over microTLS"; void microTLS_ping_prepare() { HashEngine ctx_hash; int ofs; SYS_RAM_CHECK; // we must prepare our send buffer g.scratch.send.len = 0; ofs = g.scratch.token.len + g.scratch.param.len + g.scratch.send.len + g.scratch.recv.len; g.scratch.send.buf = &g.scratch.reserved[ofs]; // copy the message to the send buffer g.scratch.send.len = MIN(strlen_P(msg), CLIENT_SCRATCH_LEN - ofs); strncpy_P((char *)g.scratch.send.buf, msg, g.scratch.send.len); // we need to generate an integrity hash for the buffer we are sending hashInit(&ctx_hash); hashUpdate(&ctx_hash, g.scratch.send.buf, g.scratch.send.len); hashFinal(&ctx_hash); g.scratch.send.digest = ctx_hash.digest; // we must encode the data in scratch using rot13 rot13crypt((char *)g.scratch.send.buf, g.scratch.send.len); } bool microTLS_ping_process() { // we must decode the data in scratch using rot13 rot13crypt((char *)g.scratch.recv.buf, g.scratch.recv.len); return true; } //--------------------------------------------------------------------------