A simple library to support serving https.
Dependents: oldheating gps motorhome heating
pki/ser-cer.c@4:6a1d887f1cad, 2019-08-20 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Aug 20 14:50:48 2019 +0000
- Revision:
- 4:6a1d887f1cad
- Parent:
- 0:be515c9019e3
- Child:
- 10:e269fd7b9500
Continued work to implement TLS
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 | 0:be515c9019e3 | 5 | |
andrewboyson | 4:6a1d887f1cad | 6 | uint8_t SerCerData[1024]; |
andrewboyson | 4:6a1d887f1cad | 7 | int SerCerSize = 0; |
andrewboyson | 0:be515c9019e3 | 8 | |
andrewboyson | 0:be515c9019e3 | 9 | static const char* pNext; |
andrewboyson | 0:be515c9019e3 | 10 | static const char* buffer = |
andrewboyson | 0:be515c9019e3 | 11 | #include "ser-cer.inc" |
andrewboyson | 0:be515c9019e3 | 12 | ; |
andrewboyson | 0:be515c9019e3 | 13 | static char readChar() |
andrewboyson | 0:be515c9019e3 | 14 | { |
andrewboyson | 0:be515c9019e3 | 15 | char c = *pNext; |
andrewboyson | 0:be515c9019e3 | 16 | if (!c) return 0; |
andrewboyson | 0:be515c9019e3 | 17 | pNext++; |
andrewboyson | 0:be515c9019e3 | 18 | return c; |
andrewboyson | 0:be515c9019e3 | 19 | } |
andrewboyson | 0:be515c9019e3 | 20 | static void readData() |
andrewboyson | 0:be515c9019e3 | 21 | { |
andrewboyson | 0:be515c9019e3 | 22 | SerCerSize = 0; |
andrewboyson | 0:be515c9019e3 | 23 | while (true) |
andrewboyson | 0:be515c9019e3 | 24 | { |
andrewboyson | 0:be515c9019e3 | 25 | int c = Base64ReadByte(); |
andrewboyson | 0:be515c9019e3 | 26 | if (c == -1) return; //EOF or an error |
andrewboyson | 0:be515c9019e3 | 27 | SerCerData[SerCerSize] = c; |
andrewboyson | 0:be515c9019e3 | 28 | SerCerSize++; |
andrewboyson | 0:be515c9019e3 | 29 | } |
andrewboyson | 0:be515c9019e3 | 30 | } |
andrewboyson | 0:be515c9019e3 | 31 | void SerCerInit() |
andrewboyson | 0:be515c9019e3 | 32 | { |
andrewboyson | 0:be515c9019e3 | 33 | |
andrewboyson | 0:be515c9019e3 | 34 | pNext = buffer; |
andrewboyson | 0:be515c9019e3 | 35 | Base64ReadNextCharFunctionPointer = readChar; |
andrewboyson | 0:be515c9019e3 | 36 | |
andrewboyson | 0:be515c9019e3 | 37 | int r = Base64SkipLine(); |
andrewboyson | 0:be515c9019e3 | 38 | if (r < 0) return; |
andrewboyson | 0:be515c9019e3 | 39 | |
andrewboyson | 0:be515c9019e3 | 40 | readData(); |
andrewboyson | 0:be515c9019e3 | 41 | |
andrewboyson | 0:be515c9019e3 | 42 | LogF("Server certificate content - %d bytes\r\n", SerCerSize); |
andrewboyson | 0:be515c9019e3 | 43 | LogBytesAsHex(SerCerData, SerCerSize); Log("\n\n"); |
andrewboyson | 0:be515c9019e3 | 44 | } |