A simple library to support serving https.
Dependents: oldheating gps motorhome heating
tls/tls-connection.h@6:819c17738dc2, 2019-09-01 (annotated)
- Committer:
- andrewboyson
- Date:
- Sun Sep 01 18:15:12 2019 +0000
- Revision:
- 6:819c17738dc2
- Parent:
- 5:ee5489ee1117
- Child:
- 7:94ef5824c3c0
Making progress - now have decryption working.
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:ee5489ee1117 | 7 | #define DO_SEND_SERVER_HELLO 1 |
andrewboyson | 5:ee5489ee1117 | 8 | #define DO_WAIT_CLIENT_CHANGE 2 |
andrewboyson | 5:ee5489ee1117 | 9 | #define DO_WAIT_DECRYPT_MASTER_SECRET 3 |
andrewboyson | 5:ee5489ee1117 | 10 | #define DO_SEND_SERVER_CHANGE 4 |
andrewboyson | 5:ee5489ee1117 | 11 | #define DO_APPLICATION 5 |
andrewboyson | 5:ee5489ee1117 | 12 | #define DO_SEND_ALERT_ILLEGAL_PARAMETER 6 |
andrewboyson | 5:ee5489ee1117 | 13 | #define DO_SEND_ALERT_INTERNAL_ERROR 7 |
andrewboyson | 5:ee5489ee1117 | 14 | |
andrewboyson | 6:819c17738dc2 | 15 | #define TLS_RANDOM_SIZE 32 |
andrewboyson | 6:819c17738dc2 | 16 | #define TLS_VERIFY_SIZE 64 |
andrewboyson | 6:819c17738dc2 | 17 | |
andrewboyson | 6:819c17738dc2 | 18 | #define TLS_KEY_SIZE_MAC 20 |
andrewboyson | 6:819c17738dc2 | 19 | #define TLS_KEY_SIZE_WRITE 16 |
andrewboyson | 6:819c17738dc2 | 20 | |
andrewboyson | 5:ee5489ee1117 | 21 | struct TlsConnection |
andrewboyson | 5:ee5489ee1117 | 22 | { |
andrewboyson | 5:ee5489ee1117 | 23 | int id; //An id of zero means the record is empty |
andrewboyson | 5:ee5489ee1117 | 24 | uint32_t lastUsed; |
andrewboyson | 5:ee5489ee1117 | 25 | int toDo; |
andrewboyson | 5:ee5489ee1117 | 26 | int session; |
andrewboyson | 5:ee5489ee1117 | 27 | struct Sha256State handshakeHash; |
andrewboyson | 6:819c17738dc2 | 28 | bool clientEncrypted; |
andrewboyson | 6:819c17738dc2 | 29 | bool serverEncrypted; |
andrewboyson | 6:819c17738dc2 | 30 | uint8_t clientRandom[TLS_RANDOM_SIZE]; |
andrewboyson | 6:819c17738dc2 | 31 | uint8_t serverRandom[TLS_RANDOM_SIZE]; |
andrewboyson | 6:819c17738dc2 | 32 | uint8_t clientVerify[TLS_VERIFY_SIZE]; |
andrewboyson | 6:819c17738dc2 | 33 | |
andrewboyson | 6:819c17738dc2 | 34 | uint8_t clientMacKey [TLS_KEY_SIZE_MAC ]; |
andrewboyson | 6:819c17738dc2 | 35 | uint8_t serverMacKey [TLS_KEY_SIZE_MAC ]; |
andrewboyson | 6:819c17738dc2 | 36 | uint8_t clientWriteKey[TLS_KEY_SIZE_WRITE ]; |
andrewboyson | 6:819c17738dc2 | 37 | uint8_t serverWriteKey[TLS_KEY_SIZE_WRITE ]; |
andrewboyson | 5:ee5489ee1117 | 38 | }; |
andrewboyson | 5:ee5489ee1117 | 39 | |
andrewboyson | 5:ee5489ee1117 | 40 | extern struct TlsConnection* TlsConnectionNew (int connectionId); //Never fails so never returns NULL |
andrewboyson | 5:ee5489ee1117 | 41 | extern struct TlsConnection* TlsConnectionOrNull(int connectionId); |
andrewboyson | 5:ee5489ee1117 | 42 | extern void TlsConnectionReset (int connectionId); |