1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef _SSL_TYPES_H_ 16 #define _SSL_TYPES_H_ 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 //#include "private-lib-core.h" 23 #include <lws_config.h> 24 #if defined(LWS_PLAT_FREERTOS) 25 /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ 26 #if !defined(LWS_AMAZON_RTOS) 27 #undef MBEDTLS_CONFIG_FILE 28 #define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h> 29 #endif 30 #endif 31 32 #include "ssl_code.h" 33 34 #include <mbedtls/x509_crt.h> 35 36 #include "private-jit-trust.h" 37 38 typedef void SSL_CIPHER; 39 40 typedef void X509_STORE_CTX; 41 typedef void X509_STORE; 42 43 typedef void RSA; 44 45 typedef void STACK; 46 typedef void BIO; 47 48 #if defined(WIN32) || defined(_WIN32) 49 #define ossl_inline __inline 50 #else 51 #define ossl_inline inline 52 #endif 53 54 #define SSL_METHOD_CALL(f, s, ...) s->method->func->ssl_##f(s, ##__VA_ARGS__) 55 #define X509_METHOD_CALL(f, x, ...) x->method->x509_##f(x, ##__VA_ARGS__) 56 #define EVP_PKEY_METHOD_CALL(f, k, ...) k->method->pkey_##f(k, ##__VA_ARGS__) 57 58 typedef int (*OPENSSL_sk_compfunc)(const void *, const void *); 59 60 struct stack_st; 61 typedef struct stack_st OPENSSL_STACK; 62 63 struct ssl_method_st; 64 typedef struct ssl_method_st SSL_METHOD; 65 66 struct ssl_method_func_st; 67 typedef struct ssl_method_func_st SSL_METHOD_FUNC; 68 69 struct record_layer_st; 70 typedef struct record_layer_st RECORD_LAYER; 71 72 struct ossl_statem_st; 73 typedef struct ossl_statem_st OSSL_STATEM; 74 75 struct ssl_session_st; 76 typedef struct ssl_session_st SSL_SESSION; 77 78 struct ssl_ctx_st; 79 typedef struct ssl_ctx_st SSL_CTX; 80 81 struct ssl_st; 82 typedef struct ssl_st SSL; 83 84 struct cert_st; 85 typedef struct cert_st CERT; 86 87 struct x509_st; 88 typedef struct x509_st X509; 89 90 struct X509_VERIFY_PARAM_st; 91 typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; 92 93 struct evp_pkey_st; 94 typedef struct evp_pkey_st EVP_PKEY; 95 96 struct x509_method_st; 97 typedef struct x509_method_st X509_METHOD; 98 99 struct pkey_method_st; 100 typedef struct pkey_method_st PKEY_METHOD; 101 102 struct stack_st { 103 104 char **data; 105 106 int num_alloc; 107 108 OPENSSL_sk_compfunc c; 109 }; 110 111 struct evp_pkey_st { 112 113 void *pkey_pm; 114 115 const PKEY_METHOD *method; 116 }; 117 118 struct x509_st { 119 120 /* X509 certification platform private point */ 121 void *x509_pm; 122 123 const X509_METHOD *method; 124 }; 125 126 struct cert_st { 127 128 int sec_level; 129 130 X509 *x509; 131 132 EVP_PKEY *pkey; 133 134 }; 135 136 struct ossl_statem_st { 137 138 MSG_FLOW_STATE state; 139 140 int hand_state; 141 }; 142 143 struct record_layer_st { 144 145 int rstate; 146 147 int read_ahead; 148 }; 149 150 struct ssl_session_st { 151 152 long timeout; 153 154 long time; 155 156 X509 *peer; 157 }; 158 159 struct X509_VERIFY_PARAM_st { 160 161 int depth; 162 163 }; 164 165 typedef int (*next_proto_cb)(SSL *ssl, const unsigned char **out, 166 unsigned char *outlen, const unsigned char *in, 167 unsigned int inlen, void *arg); 168 169 170 struct ssl_ctx_st 171 { 172 int version; 173 174 int references; 175 176 unsigned long options; 177 178 const SSL_METHOD *method; 179 180 CERT *cert; 181 182 X509 *client_CA; 183 184 const char **alpn_protos; 185 186 next_proto_cb alpn_cb; 187 188 int verify_mode; 189 190 int (*default_verify_callback) (SSL *, mbedtls_x509_crt *); 191 192 long session_timeout; 193 194 int read_ahead; 195 196 int read_buffer_len; 197 198 X509_VERIFY_PARAM param; 199 200 void *rngctx; 201 }; 202 203 struct ssl_st 204 { 205 /* protocol version(one of SSL3.0, TLS1.0, etc.) */ 206 int version; 207 208 unsigned long options; 209 210 /* shut things down(0x01 : sent, 0x02 : received) */ 211 int shutdown; 212 213 CERT *cert; 214 215 X509 *client_CA; 216 217 SSL_CTX *ctx; 218 219 const SSL_METHOD *method; 220 221 const char **alpn_protos; 222 223 RECORD_LAYER rlayer; 224 225 /* where we are */ 226 OSSL_STATEM statem; 227 228 SSL_SESSION *session; 229 230 int verify_mode; 231 232 int (*verify_callback) (SSL *, mbedtls_x509_crt *); 233 234 #if defined(LWS_WITH_TLS_JIT_TRUST) 235 lws_tls_kid_chain_t kid_chain; 236 #endif 237 238 int rwstate; 239 int interrupted_remaining_write; 240 241 long verify_result; 242 243 X509_VERIFY_PARAM param; 244 245 int err; 246 247 void (*info_callback) (const SSL *ssl, int type, int val); 248 249 /* SSL low-level system arch point */ 250 void *ssl_pm; 251 }; 252 253 struct ssl_method_st { 254 /* protocol version(one of SSL3.0, TLS1.0, etc.) */ 255 int version; 256 257 /* SSL mode(client(0) , server(1), not known(-1)) */ 258 int endpoint; 259 260 const SSL_METHOD_FUNC *func; 261 }; 262 263 struct ssl_method_func_st { 264 265 int (*ssl_new)(SSL *ssl); 266 267 void (*ssl_free)(SSL *ssl); 268 269 int (*ssl_handshake)(SSL *ssl); 270 271 int (*ssl_shutdown)(SSL *ssl); 272 273 int (*ssl_clear)(SSL *ssl); 274 275 int (*ssl_read)(SSL *ssl, void *buffer, int len); 276 277 int (*ssl_send)(SSL *ssl, const void *buffer, int len); 278 279 int (*ssl_pending)(const SSL *ssl); 280 281 void (*ssl_set_fd)(SSL *ssl, int fd, int mode); 282 283 int (*ssl_get_fd)(const SSL *ssl, int mode); 284 285 void (*ssl_set_bufflen)(SSL *ssl, int len); 286 287 long (*ssl_get_verify_result)(const SSL *ssl); 288 289 OSSL_HANDSHAKE_STATE (*ssl_get_state)(const SSL *ssl); 290 }; 291 292 struct x509_method_st { 293 294 int (*x509_new)(X509 *x, X509 *m_x); 295 296 void (*x509_free)(X509 *x); 297 298 int (*x509_load)(X509 *x, const unsigned char *buf, int len); 299 300 int (*x509_show_info)(X509 *x); 301 }; 302 303 struct pkey_method_st { 304 305 int (*pkey_new)(EVP_PKEY *pkey, EVP_PKEY *m_pkey, void *rngctx); 306 307 void (*pkey_free)(EVP_PKEY *pkey); 308 309 int (*pkey_load)(EVP_PKEY *pkey, const unsigned char *buf, int len); 310 }; 311 312 #define OPENSSL_NPN_NEGOTIATED 1 313 314 int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); 315 int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); 316 317 #ifdef __cplusplus 318 } 319 #endif 320 321 #endif 322