Go to the documentation of this file.
35 #include "est_config.h"
62 #ifndef GPL_LICENSE_TERMS_ACCEPTED
63 #error Before compiling CycloneEST Open, you must accept the terms of the GPL license
67 #define CYCLONE_EST_VERSION_STRING "2.5.4"
69 #define CYCLONE_EST_MAJOR_VERSION 2
71 #define CYCLONE_EST_MINOR_VERSION 5
73 #define CYCLONE_EST_REV_NUMBER 4
76 #ifndef EST_CLIENT_SUPPORT
77 #define EST_CLIENT_SUPPORT DISABLED
78 #elif (EST_CLIENT_SUPPORT != ENABLED && EST_CLIENT_SUPPORT != DISABLED)
79 #error EST_CLIENT_SUPPORT parameter is not valid
83 #ifndef EST_CLIENT_RSA_SUPPORT
84 #define EST_CLIENT_RSA_SUPPORT ENABLED
85 #elif (EST_CLIENT_RSA_SUPPORT != ENABLED && EST_CLIENT_RSA_SUPPORT != DISABLED)
86 #error EST_CLIENT_RSA_SUPPORT parameter is not valid
90 #ifndef EST_CLIENT_ECDSA_SUPPORT
91 #define EST_CLIENT_ECDSA_SUPPORT ENABLED
92 #elif (EST_CLIENT_ECDSA_SUPPORT != ENABLED && EST_CLIENT_ECDSA_SUPPORT != DISABLED)
93 #error EST_CLIENT_ECDSA_SUPPORT parameter is not valid
97 #ifndef EST_CLIENT_DEFAULT_TIMEOUT
98 #define EST_CLIENT_DEFAULT_TIMEOUT 20000
99 #elif (EST_CLIENT_DEFAULT_TIMEOUT < 1000)
100 #error EST_CLIENT_DEFAULT_TIMEOUT parameter is not valid
104 #ifndef EST_CLIENT_BUFFER_SIZE
105 #define EST_CLIENT_BUFFER_SIZE 4096
106 #elif (EST_CLIENT_BUFFER_SIZE < 512)
107 #error EST_CLIENT_BUFFER_SIZE parameter is not valid
111 #ifndef EST_CLIENT_MAX_HOST_LEN
112 #define EST_CLIENT_MAX_HOST_LEN 64
113 #elif (EST_CLIENT_MAX_HOST_LEN < 1)
114 #error EST_CLIENT_MAX_HOST_LEN parameter is not valid
118 #ifndef EST_CLIENT_MAX_URI_LEN
119 #define EST_CLIENT_MAX_URI_LEN 64
120 #elif (EST_CLIENT_MAX_URI_LEN < 1)
121 #error EST_CLIENT_MAX_URI_LEN parameter is not valid
125 #ifndef EST_CLIENT_MAX_CONTENT_TYPE_LEN
126 #define EST_CLIENT_MAX_CONTENT_TYPE_LEN 40
127 #elif (EST_CLIENT_MAX_CONTENT_TYPE_LEN < 1)
128 #error EST_CLIENT_MAX_CONTENT_TYPE_LEN parameter is not valid
132 #ifndef EST_CLIENT_MAX_CSR_LEN
133 #define EST_CLIENT_MAX_CSR_LEN 1024
134 #elif (EST_CLIENT_MAX_CSR_LEN < 1)
135 #error EST_CLIENT_MAX_CSR_LEN parameter is not valid
139 #ifndef EST_CLIENT_MAX_CERT_LEN
140 #define EST_CLIENT_MAX_CERT_LEN 2048
141 #elif (EST_CLIENT_MAX_CERT_LEN < 1)
142 #error EST_CLIENT_MAX_CERT_LEN parameter is not valid
146 #ifndef EST_CLIENT_MAX_CA_CERTS_LEN
147 #define EST_CLIENT_MAX_CA_CERTS_LEN 4096
148 #elif (EST_CLIENT_MAX_CA_CERTS_LEN < 1)
149 #error EST_CLIENT_MAX_CA_CERTS_LEN parameter is not valid
153 #ifndef EST_CLIENT_PRIVATE_CONTEXT
154 #define EST_CLIENT_PRIVATE_CONTEXT
159 #define EstClientContext struct _EstClientContext
238 #if (EST_CLIENT_RSA_SUPPORT == ENABLED)
242 #if (EST_CLIENT_ECDSA_SUPPORT == ENABLED)
281 const char_t *pathPrefix);
293 const IpAddr *serverIpAddr, uint16_t serverPort);
296 const char_t *publicKey,
size_t publicKeyLen,
const char_t *privateKey,
297 size_t privateKeyLen,
const char_t *password);
305 char_t *output,
size_t *written);
311 char_t *output,
size_t *written);
#define EST_CLIENT_MAX_CA_CERTS_LEN
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
#define EST_CLIENT_MAX_URI_LEN
EstClientState state
EST client state.
X509KeyType keyType
Public key type.
error_t estClientReEnroll(EstClientContext *context)
Certificate re-enrollment.
EstClientTlsInitCallback tlsInitCallback
TLS initialization callback function.
char_t caCerts[EST_CLIENT_MAX_CA_CERTS_LEN]
CA certificates.
uint_t allowedAuthModes
Allowed HTTP authentication modes.
uint8_t cert[EST_CLIENT_MAX_CERT_LEN]
Client's certificate.
error_t estClientSetAuthInfo(EstClientContext *context, const char_t *username, const char_t *password)
Set authentication information.
@ EST_CLIENT_STATE_CONNECTED
@ EST_CLIENT_STATE_DISCONNECTED
error_t estClientSetHost(EstClientContext *context, const char_t *host)
Set the domain name of the EST server.
@ EST_REQ_STATE_FORMAT_BODY
@ EST_CLIENT_STATE_REENROLL
error_t estClientBindToInterface(EstClientContext *context, NetInterface *interface)
Bind the EST client to a particular network interface.
size_t bufferLen
Length of the buffer, in bytes.
NetInterface * interface
Underlying network interface.
@ EST_CLIENT_STATE_CSR_GEN
char_t contentType[EST_CLIENT_MAX_CONTENT_TYPE_LEN+1]
Content type of the response.
#define EST_CLIENT_BUFFER_SIZE
#define EST_CLIENT_MAX_CERT_LEN
error_t estClientEnroll(EstClientContext *context)
Certificate enrollment.
HttpClientContext httpClientContext
HTTP client context.
void * prngContext
Pseudo-random number generator context.
EstRequestState
HTTP request states.
error_t(* EstClientTlsInitCallback)(EstClientContext *context, TlsContext *tlsContext)
TLS initialization callback function.
error_t estClientClose(EstClientContext *context)
Close the connection with the EST server.
#define HttpClientContext
uint8_t csr[EST_CLIENT_MAX_CSR_LEN]
CSR.
@ EST_REQ_STATE_PARSE_HEADER
error_t estClientSetTimeout(EstClientContext *context, systime_t timeout)
Set communication timeout.
HttpAuthMode selectedAuthMode
Selected HTTP authentication mode.
error_t estClientSetPrng(EstClientContext *context, const PrngAlgo *prngAlgo, void *prngContext)
Set the pseudo-random number generator to be used.
EstClientCsrGenCallback csrGenCallback
CSR generation callback function.
uint_t statusCode
HTTP status code.
RsaPublicKey rsaPublicKey
RSA public key.
error_t estClientLoadCert(EstClientContext *context, const char_t *input, size_t length)
Load client's certificate.
EstRequestState requestState
HTTP request state.
#define EST_CLIENT_MAX_HOST_LEN
bool_t useExplicitTa
Use of explicit TA database.
error_t estClientGetCaCerts(EstClientContext *context)
Get CA certificates.
@ EST_REQ_STATE_FORMAT_HEADER
#define EST_CLIENT_MAX_CSR_LEN
RsaPrivateKey rsaPrivateKey
RSA private key.
error_t estClientDisconnect(EstClientContext *context)
Gracefully disconnect from the EST server.
@ EST_REQ_STATE_RECEIVE_HEADER
EstClientState
EST client states.
error_t(* EstClientCsrGenCallback)(EstClientContext *context, const char_t *challengePwd, uint8_t *buffer, size_t size, size_t *length)
CSR generation callback function.
HTTP client (HyperText Transfer Protocol)
char_t pathPrefix[EST_CLIENT_MAX_URI_LEN+1]
Path prefix.
error_t estClientLoadCaCerts(EstClientContext *context, const char_t *input, size_t length)
Load implicit TA database.
@ EST_CLIENT_STATE_CONNECTING
uint32_t systime_t
System time.
#define EST_CLIENT_PRIVATE_CONTEXT
size_t bufferPos
Current position in the buffer.
@ EST_REQ_STATE_CLOSE_BODY
void estClientDeinit(EstClientContext *context)
Release EST client context.
@ EST_REQ_STATE_RECEIVE_BODY
error_t estClientStoreCaCerts(EstClientContext *context, char_t *output, size_t *written)
Store CA certificates.
uint8_t buffer[EST_CLIENT_BUFFER_SIZE]
Memory buffer for input/output operations.
@ EST_REQ_STATE_SEND_BODY
systime_t timeout
Timeout value.
error_t estClientRegisterCsrGenCallback(EstClientContext *context, EstClientCsrGenCallback callback)
Register CSR generation callback function.
size_t certLen
Length of the client's certificate, in bytes.
error_t estClientLoadKeyPair(EstClientContext *context, const char_t *publicKey, size_t publicKeyLen, const char_t *privateKey, size_t privateKeyLen, const char_t *password)
Load public/private key pair.
uint16_t serverPort
TCP port number.
error_t estClientStoreCert(EstClientContext *context, char_t *output, size_t *written)
Store client's certificate.
EcPublicKey ecPublicKey
EC public key.
error_t estClientInit(EstClientContext *context)
EST client initialization.
#define EST_CLIENT_MAX_CONTENT_TYPE_LEN
@ EST_CLIENT_STATE_GET_CA
@ EST_REQ_STATE_SEND_HEADER
size_t caCertsLen
Length of the CA certificates, in bytes.
void estClientUnloadKeyPair(EstClientContext *context)
Unload public/private key pair.
error_t estClientSetPathPrefix(EstClientContext *context, const char_t *pathPrefix)
Set path prefix.
X509KeyType
Public Key types.
HttpAuthMode
HTTP authentication schemes.
@ EST_CLIENT_STATE_DISCONNECTING
EcPrivateKey ecPrivateKey
EC private key.
error_t estClientSetAllowedAuthModes(EstClientContext *context, uint_t allowedAuthModes)
Set allowed HTTP authentication modes.
@ EST_CLIENT_STATE_ENROLL
error_t estClientConnect(EstClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Specify the address of the EST server.
char_t serverName[EST_CLIENT_MAX_HOST_LEN+1]
Host name of the EST server.
size_t csrLen
Length of the CSR, in bytes.
error_t estClientRegisterTlsInitCallback(EstClientContext *context, EstClientTlsInitCallback callback)
Register TLS initialization callback function.