Dependents: oldheating gps motorhome heating
tcp/https/https.c
- Committer:
- andrewboyson
- Date:
- 2019-01-20
- Revision:
- 111:3600389d1add
- Child:
- 142:a8c0890a58d1
File content as of revision 111:3600389d1add:
#include <stdbool.h> #include "http.h" #include "tcpbuf.h" #include "action.h" #include "net.h" #include "log.h" #include "led.h" #include "fault.h" #define TLS_CONTENT_TYPE_ChangeCipher 20 #define TLS_CONTENT_TYPE_Alert 21 #define TLS_CONTENT_TYPE_Handshake 22 #define TLS_CONTENT_TYPE_Application 23 #define TLS_CONTENT_TYPE_Heartbeat 24 #define TLS_HANDSHAKE_HelloRequest 0 #define TLS_HANDSHAKE_ClientHello 1 #define TLS_HANDSHAKE_ServerHello 2 #define TLS_HANDSHAKE_NewSessionTicket 4 #define TLS_HANDSHAKE_EncryptedExtensions 8 #define TLS_HANDSHAKE_Certificate 11 #define TLS_HANDSHAKE_ServerKeyExchange 12 #define TLS_HANDSHAKE_CertificateRequest 13 #define TLS_HANDSHAKE_ServerHelloDone 14 #define TLS_HANDSHAKE_CertificateVerify 15 #define TLS_HANDSHAKE_ClientKeyExchange 16 #define TLS_HANDSHAKE_Finished 20 #define DO_SERVER_HELLO 100 static void logHandshakeType(char handshakeType) { switch (handshakeType) { case TLS_HANDSHAKE_HelloRequest: Log ("Hello request"); break; case TLS_HANDSHAKE_ClientHello: Log ("Client hello"); break; case TLS_HANDSHAKE_ServerHello: Log ("Server hello"); break; case TLS_HANDSHAKE_NewSessionTicket: Log ("New session ticket"); break; case TLS_HANDSHAKE_EncryptedExtensions: Log ("Encrypted extensions"); break; case TLS_HANDSHAKE_Certificate: Log ("Certificate"); break; case TLS_HANDSHAKE_ServerKeyExchange: Log ("Server key exchange"); break; case TLS_HANDSHAKE_CertificateRequest: Log ("Certificate request"); break; case TLS_HANDSHAKE_ServerHelloDone: Log ("Server hello done"); break; case TLS_HANDSHAKE_CertificateVerify: Log ("Certificate verify"); break; case TLS_HANDSHAKE_ClientKeyExchange: Log ("Client key exchange"); break; case TLS_HANDSHAKE_Finished: Log ("Finished"); break; default: LogF("%02hX", handshakeType); break; } } static void logContentType(char contentType) { switch (contentType) { case TLS_CONTENT_TYPE_ChangeCipher: Log ("Change cipher"); break; case TLS_CONTENT_TYPE_Alert: Log ("Alert"); break; case TLS_CONTENT_TYPE_Handshake: Log ("Handshake"); break; case TLS_CONTENT_TYPE_Application: Log ("Application"); break; case TLS_CONTENT_TYPE_Heartbeat: Log ("Heartbeat"); break; default: LogF("%02hX", contentType); break; } } bool HttpsTrace = true; void HttpsHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, int* pToDo) { if (HttpsTrace) { LogF("HTTPS <<< %d (%u)\r\n", size, positionInRequestStream); } //Handle request for the first packet of data received but leave todo the same after that. if (size == 0) return; if (positionInRequestStream != 0) return; char contentType = pRequestStream[0]; if (HttpsTrace) Log(" content type: "); logContentType(contentType); Log("\r\n"); switch (contentType) { case TLS_CONTENT_TYPE_Handshake: { char handshakeType = pRequestStream[5]; if (HttpsTrace) Log(" handshake type: "); logHandshakeType(handshakeType); Log("\r\n"); *pToDo = DO_SERVER_HELLO; return; } default: Log("HTTPS - ignoring untreated content type\r\n"); *pToDo = 0; return; } //ECDHE-RSA-AES128-GCM-SHA256 } static void sendServerHello() { Log(" sending server hello\r\n"); } void HttpsSendReply(int* pSize, char* pReplyStream, uint32_t positionInReplyStream, uint16_t mss, int todo) { TcpBufStart(positionInReplyStream, mss, pReplyStream); if (todo == DO_SERVER_HELLO) sendServerHello(); *pSize = TcpBufLength(); if (HttpsTrace) { LogF("HTTPS >>> %d (%d)\r\n", *pSize, positionInReplyStream); } }