A simple library to support serving https.
Dependents: oldheating gps motorhome heating
pki/ser-cer.c@24:cb43290fc439, 2020-04-01 (annotated)
- Committer:
- andrewboyson
- Date:
- Wed Apr 01 12:48:52 2020 +0000
- Revision:
- 24:cb43290fc439
- Parent:
- 21:a6d6e26dd742
Added check so that if the client closes the TCP connection before the TLS connection is established then respond that we have finished and the TCP connection is to be closed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 4:6a1d887f1cad | 1 | #include <stdint.h> |
andrewboyson | 4:6a1d887f1cad | 2 | |
andrewboyson | 0:be515c9019e3 | 3 | #include "base64.h" |
andrewboyson | 0:be515c9019e3 | 4 | #include "log.h" |
andrewboyson | 10:e269fd7b9500 | 5 | #include "led.h" |
andrewboyson | 0:be515c9019e3 | 6 | |
andrewboyson | 4:6a1d887f1cad | 7 | uint8_t SerCerData[1024]; |
andrewboyson | 4:6a1d887f1cad | 8 | int SerCerSize = 0; |
andrewboyson | 0:be515c9019e3 | 9 | |
andrewboyson | 0:be515c9019e3 | 10 | static const char* pNext; |
andrewboyson | 0:be515c9019e3 | 11 | static const char* buffer = |
andrewboyson | 0:be515c9019e3 | 12 | #include "ser-cer.inc" |
andrewboyson | 0:be515c9019e3 | 13 | ; |
andrewboyson | 0:be515c9019e3 | 14 | static char readChar() |
andrewboyson | 0:be515c9019e3 | 15 | { |
andrewboyson | 0:be515c9019e3 | 16 | char c = *pNext; |
andrewboyson | 0:be515c9019e3 | 17 | if (!c) return 0; |
andrewboyson | 0:be515c9019e3 | 18 | pNext++; |
andrewboyson | 0:be515c9019e3 | 19 | return c; |
andrewboyson | 0:be515c9019e3 | 20 | } |
andrewboyson | 0:be515c9019e3 | 21 | static void readData() |
andrewboyson | 0:be515c9019e3 | 22 | { |
andrewboyson | 0:be515c9019e3 | 23 | SerCerSize = 0; |
andrewboyson | 0:be515c9019e3 | 24 | while (true) |
andrewboyson | 0:be515c9019e3 | 25 | { |
andrewboyson | 0:be515c9019e3 | 26 | int c = Base64ReadByte(); |
andrewboyson | 0:be515c9019e3 | 27 | if (c == -1) return; //EOF or an error |
andrewboyson | 0:be515c9019e3 | 28 | SerCerData[SerCerSize] = c; |
andrewboyson | 0:be515c9019e3 | 29 | SerCerSize++; |
andrewboyson | 0:be515c9019e3 | 30 | } |
andrewboyson | 0:be515c9019e3 | 31 | } |
andrewboyson | 0:be515c9019e3 | 32 | void SerCerInit() |
andrewboyson | 0:be515c9019e3 | 33 | { |
andrewboyson | 0:be515c9019e3 | 34 | |
andrewboyson | 0:be515c9019e3 | 35 | pNext = buffer; |
andrewboyson | 0:be515c9019e3 | 36 | Base64ReadNextCharFunctionPointer = readChar; |
andrewboyson | 0:be515c9019e3 | 37 | |
andrewboyson | 0:be515c9019e3 | 38 | int r = Base64SkipLine(); |
andrewboyson | 0:be515c9019e3 | 39 | if (r < 0) return; |
andrewboyson | 0:be515c9019e3 | 40 | |
andrewboyson | 0:be515c9019e3 | 41 | readData(); |
andrewboyson | 21:a6d6e26dd742 | 42 | /* |
andrewboyson | 0:be515c9019e3 | 43 | LogF("Server certificate content - %d bytes\r\n", SerCerSize); |
andrewboyson | 0:be515c9019e3 | 44 | LogBytesAsHex(SerCerData, SerCerSize); Log("\n\n"); |
andrewboyson | 21:a6d6e26dd742 | 45 | */ |
andrewboyson | 0:be515c9019e3 | 46 | } |