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_CODE_H_
16 #define _SSL_CODE_H_
17 
18 #ifdef __cplusplus
19  extern "C" {
20 #endif
21 
22 #include "ssl3.h"
23 #include "tls1.h"
24 #include "x509_vfy.h"
25 
26 /* Used in SSL_set_mode() -- supported mode when using BIO */
27 #define SSL_MODE_ENABLE_PARTIAL_WRITE       0x00000001L
28 #define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
29 
30 /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
31 # define SSL_SENT_SHUTDOWN       1
32 # define SSL_RECEIVED_SHUTDOWN   2
33 
34 # define SSL_VERIFY_NONE                 0x00
35 # define SSL_VERIFY_PEER                 0x01
36 # define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
37 # define SSL_VERIFY_CLIENT_ONCE          0x04
38 
39 /*
40  * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
41  * should not need these
42  */
43 # define SSL_ST_READ_HEADER                      0xF0
44 # define SSL_ST_READ_BODY                        0xF1
45 # define SSL_ST_READ_DONE                        0xF2
46 
47 # define SSL_NOTHING            1
48 # define SSL_WRITING            2
49 # define SSL_READING            3
50 # define SSL_X509_LOOKUP        4
51 # define SSL_ASYNC_PAUSED       5
52 # define SSL_ASYNC_NO_JOBS      6
53 
54 
55 # define SSL_ERROR_NONE                  0
56 # define SSL_ERROR_SSL                   1
57 # define SSL_ERROR_WANT_READ             2
58 # define SSL_ERROR_WANT_WRITE            3
59 # define SSL_ERROR_WANT_X509_LOOKUP      4
60 # define SSL_ERROR_SYSCALL               5/* look at error stack/return value/errno */
61 # define SSL_ERROR_ZERO_RETURN           6
62 # define SSL_ERROR_WANT_CONNECT          7
63 # define SSL_ERROR_WANT_ACCEPT           8
64 # define SSL_ERROR_WANT_ASYNC            9
65 # define SSL_ERROR_WANT_ASYNC_JOB       10
66 
67 /* Message flow states */
68 typedef enum {
69     /* No handshake in progress */
70     MSG_FLOW_UNINITED,
71     /* A permanent error with this connection */
72     MSG_FLOW_ERROR,
73     /* We are about to renegotiate */
74     MSG_FLOW_RENEGOTIATE,
75     /* We are reading messages */
76     MSG_FLOW_READING,
77     /* We are writing messages */
78     MSG_FLOW_WRITING,
79     /* Handshake has finished */
80     MSG_FLOW_FINISHED
81 } MSG_FLOW_STATE;
82 
83 /* SSL subsystem states */
84 typedef enum {
85     TLS_ST_BEFORE,
86     TLS_ST_OK,
87     DTLS_ST_CR_HELLO_VERIFY_REQUEST,
88     TLS_ST_CR_SRVR_HELLO,
89     TLS_ST_CR_CERT,
90     TLS_ST_CR_CERT_STATUS,
91     TLS_ST_CR_KEY_EXCH,
92     TLS_ST_CR_CERT_REQ,
93     TLS_ST_CR_SRVR_DONE,
94     TLS_ST_CR_SESSION_TICKET,
95     TLS_ST_CR_CHANGE,
96     TLS_ST_CR_FINISHED,
97     TLS_ST_CW_CLNT_HELLO,
98     TLS_ST_CW_CERT,
99     TLS_ST_CW_KEY_EXCH,
100     TLS_ST_CW_CERT_VRFY,
101     TLS_ST_CW_CHANGE,
102     TLS_ST_CW_NEXT_PROTO,
103     TLS_ST_CW_FINISHED,
104     TLS_ST_SW_HELLO_REQ,
105     TLS_ST_SR_CLNT_HELLO,
106     DTLS_ST_SW_HELLO_VERIFY_REQUEST,
107     TLS_ST_SW_SRVR_HELLO,
108     TLS_ST_SW_CERT,
109     TLS_ST_SW_KEY_EXCH,
110     TLS_ST_SW_CERT_REQ,
111     TLS_ST_SW_SRVR_DONE,
112     TLS_ST_SR_CERT,
113     TLS_ST_SR_KEY_EXCH,
114     TLS_ST_SR_CERT_VRFY,
115     TLS_ST_SR_NEXT_PROTO,
116     TLS_ST_SR_CHANGE,
117     TLS_ST_SR_FINISHED,
118     TLS_ST_SW_SESSION_TICKET,
119     TLS_ST_SW_CERT_STATUS,
120     TLS_ST_SW_CHANGE,
121     TLS_ST_SW_FINISHED
122 } OSSL_HANDSHAKE_STATE;
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif
129