ESP32 HTTPS Server: /home/frank/Projekte/esp32/https_server/esp32_https_server/src/SSLCert.hpp Source File

1 #ifndef SRC_SSLCERT_HPP_

2 #define SRC_SSLCERT_HPP_

3 

4 #include <Arduino.h>

5 

6 #ifndef HTTPS_DISABLE_SELFSIGNING

7 #include <string>

8 #include <mbedtls/rsa.h>

9 #include <mbedtls/entropy.h>

10 #include <mbedtls/ctr_drbg.h>

11 #include <mbedtls/pk.h>

12 #include <mbedtls/x509.h>

13 #include <mbedtls/x509_crt.h>

14 #include <mbedtls/x509_csr.h>

15 

16 #define HTTPS_SERVER_ERROR_KEYGEN 0x0F

17 #define HTTPS_SERVER_ERROR_KEYGEN_RNG 0x02

18 #define HTTPS_SERVER_ERROR_KEYGEN_SETUP_PK 0x03

19 #define HTTPS_SERVER_ERROR_KEYGEN_GEN_PK 0x04

20 #define HTTPS_SERVER_ERROR_KEY_WRITE_PK 0x05

21 #define HTTPS_SERVER_ERROR_KEY_OUT_OF_MEM 0x06

22 #define HTTPS_SERVER_ERROR_CERTGEN 0x1F

23 #define HTTPS_SERVER_ERROR_CERTGEN_RNG 0x12

24 #define HTTPS_SERVER_ERROR_CERTGEN_READKEY 0x13

25 #define HTTPS_SERVER_ERROR_CERTGEN_WRITE 0x15

26 #define HTTPS_SERVER_ERROR_CERTGEN_OUT_OF_MEM 0x16

27 #define HTTPS_SERVER_ERROR_CERTGEN_NAME 0x17

28 #define HTTPS_SERVER_ERROR_CERTGEN_SERIAL 0x18

29 #define HTTPS_SERVER_ERROR_CERTGEN_VALIDITY 0x19

30 

31 #endif // !HTTPS_DISABLE_SELFSIGNING

32 

34 

60 public:

76  unsigned char * certData = NULL,

77  uint16_t certLength = 0,

78  unsigned char * pkData = NULL,

79  uint16_t pkLength = 0

80  );

82 

87 

92 

97 

102 

114  void setPK(unsigned char * _pkData, uint16_t length);

115 

127  void setCert(unsigned char * _certData, uint16_t length);

128 

133 

134 private:

135  uint16_t _certLength;

136  unsigned char * _certData;

137  uint16_t _pkLength;

138  unsigned char * _pkData;

139 

140 };

141 

142 #ifndef HTTPS_DISABLE_SELFSIGNING

143 

156 };

157 

176 int createSelfSignedCert(SSLCert &certCtx, SSLKeySize keySize, std::string dn, std::string validFrom = "20190101000000", std::string validUntil = "20300101000000");

177 

178 #endif // !HTTPS_DISABLE_SELFSIGNING

179 

180 }

181 

182 #endif

uint16_t getPKLength()

Returns the length of the private key in byte.

Definition: SSLCert.cpp:22

void clear()

Clears the key buffers and deletes them.

Definition: SSLCert.cpp:44

RSA key with 2048 bit.

Definition: SSLCert.hpp:153

RSA key with 1024 bit.

Definition: SSLCert.hpp:151

unsigned char * getCertData()

Returns the certificate data.

Definition: SSLCert.cpp:26

Certificate and private key that can be passed to the HTTPSServer.

Definition: SSLCert.hpp:59

int createSelfSignedCert(SSLCert &certCtx, SSLKeySize keySize, std::string dn, std::string validFrom, std::string validUntil)

Creates a self-signed certificate on the ESP32.

Definition: SSLCert.cpp:287

SSLCert(unsigned char *certData=NULL, uint16_t certLength=0, unsigned char *pkData=NULL, uint16_t pkLength=0)

Creates a new SSLCert.

Definition: SSLCert.cpp:5

void setCert(unsigned char *_certData, uint16_t length)

Sets the certificate data in DER format.

Definition: SSLCert.cpp:39

unsigned char * getPKData()

Returns the private key data.

Definition: SSLCert.cpp:30

RSA key with 4096 bit.

Definition: SSLCert.hpp:155

uint16_t getCertLength()

Returns the length of the certificate in byte.

Definition: SSLCert.cpp:18

Definition: ConnectionContext.cpp:3

void setPK(unsigned char *_pkData, uint16_t length)

Sets the private key in DER format.

Definition: SSLCert.cpp:34

SSLKeySize

Defines the key size for key generation.

Definition: SSLCert.hpp:149