A simple library to support serving https.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Wed Oct 02 20:26:04 2019 +0000
Revision:
14:03a0b8fd6ddc
Parent:
10:e269fd7b9500
Child:
17:93feb2a51d58
Session resume now working. TLS working quickly after the initial 5 second RSA decrypt time using the 1024 bit private key.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 6:819c17738dc2 1 #include <stdbool.h>
andrewboyson 6:819c17738dc2 2 #include <stdint.h>
andrewboyson 6:819c17738dc2 3
andrewboyson 5:ee5489ee1117 4 #include "sha256.h"
andrewboyson 5:ee5489ee1117 5
andrewboyson 5:ee5489ee1117 6 #define DO_WAIT_CLIENT_HELLO 0
andrewboyson 14:03a0b8fd6ddc 7 #define DO_SEND_SERVER_HELLO_NEW 1
andrewboyson 14:03a0b8fd6ddc 8 #define DO_SEND_SERVER_HELLO_RESUME 2
andrewboyson 14:03a0b8fd6ddc 9 #define DO_WAIT_CLIENT_CHANGE 3
andrewboyson 14:03a0b8fd6ddc 10 #define DO_WAIT_DECRYPT_MASTER_SECRET 4
andrewboyson 14:03a0b8fd6ddc 11 #define DO_SEND_SERVER_CHANGE 5
andrewboyson 14:03a0b8fd6ddc 12 #define DO_APPLICATION 6
andrewboyson 14:03a0b8fd6ddc 13 #define DO_SEND_ALERT_ILLEGAL_PARAMETER 7
andrewboyson 14:03a0b8fd6ddc 14 #define DO_SEND_ALERT_INTERNAL_ERROR 8
andrewboyson 5:ee5489ee1117 15
andrewboyson 6:819c17738dc2 16 #define TLS_RANDOM_SIZE 32
andrewboyson 6:819c17738dc2 17 #define TLS_VERIFY_SIZE 64
andrewboyson 6:819c17738dc2 18
andrewboyson 6:819c17738dc2 19 #define TLS_KEY_SIZE_MAC 20
andrewboyson 6:819c17738dc2 20 #define TLS_KEY_SIZE_WRITE 16
andrewboyson 8:5e66a6b4b38c 21 #define TLS_DEFERRED_CONTENT_SIZE 100
andrewboyson 6:819c17738dc2 22
andrewboyson 5:ee5489ee1117 23 struct TlsConnection
andrewboyson 5:ee5489ee1117 24 {
andrewboyson 5:ee5489ee1117 25 int id; //An id of zero means the record is empty
andrewboyson 5:ee5489ee1117 26 uint32_t lastUsed;
andrewboyson 5:ee5489ee1117 27 int toDo;
andrewboyson 10:e269fd7b9500 28 uint32_t sessionId;
andrewboyson 14:03a0b8fd6ddc 29 bool resume;
andrewboyson 8:5e66a6b4b38c 30 struct Sha256State handshakeSha;
andrewboyson 6:819c17738dc2 31 bool clientEncrypted;
andrewboyson 6:819c17738dc2 32 bool serverEncrypted;
andrewboyson 6:819c17738dc2 33 uint8_t clientRandom[TLS_RANDOM_SIZE];
andrewboyson 6:819c17738dc2 34 uint8_t serverRandom[TLS_RANDOM_SIZE];
andrewboyson 8:5e66a6b4b38c 35 uint8_t clientHandshakeHash[SHA256_HASH_SIZE];
andrewboyson 8:5e66a6b4b38c 36 uint8_t deferredContent[TLS_DEFERRED_CONTENT_SIZE];
andrewboyson 8:5e66a6b4b38c 37 uint64_t clientSequence;
andrewboyson 8:5e66a6b4b38c 38 uint64_t serverSequence;
andrewboyson 10:e269fd7b9500 39 uint32_t clientPositionInStreamOffset;
andrewboyson 10:e269fd7b9500 40 uint32_t serverPositionInStreamOffset;
andrewboyson 6:819c17738dc2 41
andrewboyson 14:03a0b8fd6ddc 42 int slotPriKeyDecryption;
andrewboyson 8:5e66a6b4b38c 43 uint8_t clientMacKey [TLS_KEY_SIZE_MAC ];
andrewboyson 8:5e66a6b4b38c 44 uint8_t serverMacKey [TLS_KEY_SIZE_MAC ];
andrewboyson 8:5e66a6b4b38c 45 uint8_t clientWriteKey[TLS_KEY_SIZE_WRITE];
andrewboyson 8:5e66a6b4b38c 46 uint8_t serverWriteKey[TLS_KEY_SIZE_WRITE];
andrewboyson 5:ee5489ee1117 47 };
andrewboyson 5:ee5489ee1117 48
andrewboyson 8:5e66a6b4b38c 49 extern struct TlsConnection* TlsConnectionGetNext(void);
andrewboyson 8:5e66a6b4b38c 50
andrewboyson 10:e269fd7b9500 51 extern struct TlsConnection* TlsConnectionNew (int id); //Never fails so never returns NULL
andrewboyson 10:e269fd7b9500 52 extern struct TlsConnection* TlsConnectionOrNull(int id);
andrewboyson 10:e269fd7b9500 53 extern void TlsConnectionReset (int id);