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 "ssl_code.h" 23 #include <stddef.h> 24 #include <stdint.h> 25 26 typedef void SSL_CIPHER; 27 28 typedef void X509_STORE_CTX; 29 typedef void X509_STORE; 30 31 typedef void RSA; 32 33 typedef void STACK; 34 35 typedef void DH; 36 37 #define ossl_inline inline 38 39 #define SSL_METHOD_CALL(f, s, ...) s->method->func->ssl_##f(s, ##__VA_ARGS__) 40 #define X509_METHOD_CALL(f, x, ...) x->method->x509_##f(x, ##__VA_ARGS__) 41 #define EVP_PKEY_METHOD_CALL(f, k, ...) k->method->pkey_##f(k, ##__VA_ARGS__) 42 43 typedef int (*OPENSSL_sk_compfunc)(const void *, const void *); 44 typedef int (*openssl_verify_callback)(int, X509_STORE_CTX *); 45 struct stack_st; 46 typedef struct stack_st OPENSSL_STACK; 47 48 struct ssl_method_st; 49 typedef struct ssl_method_st SSL_METHOD; 50 51 struct ssl_method_func_st; 52 typedef struct ssl_method_func_st SSL_METHOD_FUNC; 53 54 struct record_layer_st; 55 typedef struct record_layer_st RECORD_LAYER; 56 57 struct ossl_statem_st; 58 typedef struct ossl_statem_st OSSL_STATEM; 59 60 struct ssl_session_st; 61 typedef struct ssl_session_st SSL_SESSION; 62 63 struct ssl_ctx_st; 64 typedef struct ssl_ctx_st SSL_CTX; 65 66 struct ssl_st; 67 typedef struct ssl_st SSL; 68 69 struct cert_st; 70 typedef struct cert_st CERT; 71 72 struct x509_st; 73 typedef struct x509_st X509; 74 75 struct X509_VERIFY_PARAM_st; 76 typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; 77 78 struct evp_pkey_st; 79 typedef struct evp_pkey_st EVP_PKEY; 80 81 struct x509_method_st; 82 typedef struct x509_method_st X509_METHOD; 83 84 struct pkey_method_st; 85 typedef struct pkey_method_st PKEY_METHOD; 86 87 struct ssl_alpn_st; 88 typedef struct ssl_alpn_st SSL_ALPN; 89 90 struct bio_st; 91 typedef struct bio_st BIO; 92 93 struct stack_st { 94 95 char **data; 96 97 int num_alloc; 98 99 OPENSSL_sk_compfunc c; 100 }; 101 102 struct evp_pkey_st { 103 104 void *pkey_pm; 105 106 const PKEY_METHOD *method; 107 108 int ref_counter; 109 }; 110 111 struct x509_st { 112 113 /* X509 certification platform private point */ 114 void *x509_pm; 115 116 const X509_METHOD *method; 117 118 int ref_counter; 119 }; 120 121 struct cert_st { 122 123 int sec_level; 124 125 X509 *x509; 126 127 EVP_PKEY *pkey; 128 129 }; 130 131 struct ossl_statem_st { 132 133 MSG_FLOW_STATE state; 134 135 int hand_state; 136 }; 137 138 struct record_layer_st { 139 140 int rstate; 141 142 int read_ahead; 143 }; 144 145 struct ssl_session_st { 146 147 long timeout; 148 149 long time; 150 151 X509 *peer; 152 }; 153 154 struct X509_VERIFY_PARAM_st { 155 156 int depth; 157 158 }; 159 160 struct bio_st { 161 162 unsigned char * data; 163 int dlen; 164 BIO* peer; 165 size_t offset; 166 size_t roffset; 167 size_t size; 168 size_t flags; 169 size_t type; 170 171 }; 172 173 typedef enum { ALPN_INIT, ALPN_ENABLE, ALPN_DISABLE, ALPN_ERROR } ALPN_STATUS; 174 struct ssl_alpn_st { 175 ALPN_STATUS alpn_status; 176 /* This is dynamically allocated */ 177 char *alpn_string; 178 /* This only points to the members in the string */ 179 #define ALPN_LIST_MAX 10 180 const char *alpn_list[ALPN_LIST_MAX]; 181 }; 182 183 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); 184 185 186 struct ssl_ctx_st 187 { 188 int version; 189 190 int references; 191 192 unsigned long options; 193 194 SSL_ALPN ssl_alpn; 195 196 const SSL_METHOD *method; 197 198 CERT *cert; 199 200 X509 *client_CA; 201 202 int verify_mode; 203 204 int (*default_verify_callback) (int ok, X509_STORE_CTX *ctx); 205 206 long session_timeout; 207 208 int read_ahead; 209 210 int read_buffer_len; 211 212 X509_VERIFY_PARAM param; 213 214 void *default_passwd_callback_userdata; 215 216 pem_password_cb *default_passwd_callback; 217 218 struct stack_st_X509 *extra_certs; 219 220 int max_version; 221 int min_version; 222 223 }; 224 225 struct ssl_st 226 { 227 /* protocol version(one of SSL3.0, TLS1.0, etc.) */ 228 int version; 229 230 unsigned long options; 231 232 /* shut things down(0x01 : sent, 0x02 : received) */ 233 int shutdown; 234 235 CERT *cert; 236 237 X509 *client_CA; 238 239 SSL_CTX *ctx; 240 241 const SSL_METHOD *method; 242 243 RECORD_LAYER rlayer; 244 245 /* where we are */ 246 OSSL_STATEM statem; 247 248 SSL_SESSION *session; 249 250 int verify_mode; 251 252 int (*verify_callback) (int ok, X509_STORE_CTX *ctx); 253 254 int rwstate; 255 256 long verify_result; 257 258 X509_VERIFY_PARAM param; 259 260 uint32_t mode; 261 262 void (*info_callback) (const SSL *ssl, int type, int val); 263 264 /* SSL low-level system arch point */ 265 void *ssl_pm; 266 void *bio; 267 }; 268 269 struct ssl_method_st { 270 /* protocol version(one of SSL3.0, TLS1.0, etc.) */ 271 int version; 272 273 /* SSL mode(client(0) , server(1), not known(-1)) */ 274 int endpoint; 275 276 const SSL_METHOD_FUNC *func; 277 }; 278 279 struct ssl_method_func_st { 280 281 int (*ssl_new)(SSL *ssl); 282 283 void (*ssl_free)(SSL *ssl); 284 285 int (*ssl_handshake)(SSL *ssl); 286 287 int (*ssl_shutdown)(SSL *ssl); 288 289 int (*ssl_clear)(SSL *ssl); 290 291 int (*ssl_read)(SSL *ssl, void *buffer, int len); 292 293 int (*ssl_send)(SSL *ssl, const void *buffer, int len); 294 295 int (*ssl_pending)(const SSL *ssl); 296 297 void (*ssl_set_fd)(SSL *ssl, int fd, int mode); 298 299 void (*ssl_set_hostname)(SSL *ssl, const char *hostname); 300 301 int (*ssl_get_fd)(const SSL *ssl, int mode); 302 303 void (*ssl_set_bufflen)(SSL *ssl, int len); 304 305 long (*ssl_get_verify_result)(const SSL *ssl); 306 307 OSSL_HANDSHAKE_STATE (*ssl_get_state)(const SSL *ssl); 308 }; 309 310 struct x509_method_st { 311 312 int (*x509_new)(X509 *x, X509 *m_x); 313 314 void (*x509_free)(X509 *x); 315 316 int (*x509_load)(X509 *x, const unsigned char *buf, int len); 317 318 int (*x509_show_info)(X509 *x); 319 }; 320 321 struct pkey_method_st { 322 323 int (*pkey_new)(EVP_PKEY *pkey, EVP_PKEY *m_pkey); 324 325 void (*pkey_free)(EVP_PKEY *pkey); 326 327 int (*pkey_load)(EVP_PKEY *pkey, const unsigned char *buf, int len); 328 }; 329 330 struct bio_method_st { 331 332 unsigned type; 333 334 unsigned size; 335 }; 336 337 338 typedef int (*next_proto_cb)(SSL *ssl, unsigned char **out, 339 unsigned char *outlen, const unsigned char *in, 340 unsigned int inlen, void *arg); 341 342 #ifdef __cplusplus 343 } 344 #endif 345 346 #endif 347