36 #ifndef HEADER_SSL_LIB_H 37 #define HEADER_SSL_LIB_H 47 #define SSL_PROTOCOL_MIN_VERSION 0x31 48 #define SSL_PROTOCOL_MINOR_VERSION 0x02 49 #define SSL_PROTOCOL_VERSION_MAX 0x32 50 #define SSL_PROTOCOL_VERSION1_1 0x32 51 #define SSL_RANDOM_SIZE 32 52 #define SSL_SECRET_SIZE 48 53 #define SSL_FINISHED_HASH_SIZE 12 54 #define SSL_RECORD_SIZE 5 55 #define SSL_SERVER_READ 0 56 #define SSL_SERVER_WRITE 1 57 #define SSL_CLIENT_READ 2 58 #define SSL_CLIENT_WRITE 3 59 #define SSL_HS_HDR_SIZE 4 62 #define SSL_NEED_RECORD 0x0001 63 #define SSL_TX_ENCRYPTED 0x0002 64 #define SSL_RX_ENCRYPTED 0x0004 65 #define SSL_SESSION_RESUME 0x0008 66 #define SSL_IS_CLIENT 0x0010 67 #define SSL_HAS_CERT_REQ 0x0020 68 #define SSL_SENT_CLOSE_NOTIFY 0x0040 71 #define SET_SSL_FLAG(A) (ssl->flag |= A) 72 #define CLR_SSL_FLAG(A) (ssl->flag &= ~A) 73 #define IS_SET_SSL_FLAG(A) (ssl->flag & A) 75 #define MAX_KEY_BYTE_SIZE 512 76 #define RT_MAX_PLAIN_LENGTH 16384 78 #define BM_RECORD_OFFSET 5 80 #ifdef CONFIG_SSL_SKELETON_MODE 81 #define NUM_PROTOCOLS 1 83 #define NUM_PROTOCOLS 4 86 #define PARANOIA_CHECK(A, B) if (A < B) { \ 87 ret = SSL_ERROR_INVALID_HANDSHAKE; goto error; } 92 PT_CHANGE_CIPHER_SPEC = 20,
94 PT_HANDSHAKE_PROTOCOL,
107 HS_SERVER_HELLO_DONE,
118 uint8_t key_block_size;
119 uint8_t padding_size;
137 uint8_t session_id[SSL_SESSION_ID_SIZE];
138 uint8_t master_secret[SSL_SECRET_SIZE];
154 uint8_t final_finish_mac[SSL_FINISHED_HASH_SIZE];
156 uint8_t master_secret[SSL_SECRET_SIZE];
157 uint8_t client_random[SSL_RANDOM_SIZE];
158 uint8_t server_random[SSL_RANDOM_SIZE];
159 uint16_t bm_proc_index;
169 uint8_t sess_id_size;
171 uint8_t client_version;
179 uint8_t bm_all_data[RT_MAX_PLAIN_LENGTH+RT_EXTRA];
182 uint16_t bm_read_index;
186 #ifndef CONFIG_SSL_SKELETON_MODE 187 uint16_t session_index;
190 #ifdef CONFIG_SSL_CERT_VERIFICATION 194 uint8_t session_id[SSL_SESSION_ID_SIZE];
195 uint8_t client_mac[SHA1_SIZE];
196 uint8_t server_mac[SHA1_SIZE];
197 uint8_t read_sequence[8];
198 uint8_t write_sequence[8];
199 uint8_t hmac_header[SSL_RECORD_SIZE];
202 typedef struct _SSL SSL;
209 #ifdef CONFIG_SSL_CERT_VERIFICATION 216 #ifndef CONFIG_SSL_SKELETON_MODE 217 uint16_t num_sessions;
220 #ifdef CONFIG_SSL_CTX_MUTEXING 221 SSL_CTX_MUTEX_TYPE mutex;
223 #ifdef CONFIG_OPENSSL_COMPATIBLE 233 extern const uint8_t ssl_prot_prefs[NUM_PROTOCOLS];
235 SSL *ssl_new(SSL_CTX *ssl_ctx,
void* client_fd);
239 const uint8_t *in,
int length);
240 int do_svr_handshake(SSL *ssl,
int handshake_type, uint8_t *buf,
int hs_len);
241 int do_clnt_handshake(SSL *ssl,
int handshake_type, uint8_t *buf,
int hs_len);
243 int process_sslv23_client_hello(SSL *ssl);
251 void add_packet(SSL *ssl,
const uint8_t *pkt,
int len);
252 int add_cert(SSL_CTX *ssl_ctx,
const uint8_t *buf,
int len);
253 int add_private_key(SSL_CTX *ssl_ctx, SSLObjLoader *ssl_obj);
254 void ssl_obj_free(SSLObjLoader *ssl_obj);
255 int pkcs8_decode(SSL_CTX *ssl_ctx, SSLObjLoader *ssl_obj,
const char *password);
256 int pkcs12_decode(SSL_CTX *ssl_ctx, SSLObjLoader *ssl_obj,
const char *password);
257 int load_key_certs(SSL_CTX *ssl_ctx);
258 #ifdef CONFIG_SSL_CERT_VERIFICATION 259 int add_cert_auth(SSL_CTX *ssl_ctx,
const uint8_t *buf,
int len);
262 #ifdef CONFIG_SSL_ENABLE_CLIENT 263 int do_client_connect(SSL *ssl);
266 #ifdef CONFIG_SSL_FULL_MODE 267 void DISPLAY_STATE(SSL *ssl,
int is_send, uint8_t state,
int not_ok);
268 void DISPLAY_BYTES(SSL *ssl,
const char *format,
269 const uint8_t *data,
int size, ...);
270 void DISPLAY_CERT(SSL *ssl,
const X509_CTX *x509_ctx);
271 void DISPLAY_RSA(SSL *ssl,
const RSA_CTX *rsa_ctx);
272 void DISPLAY_ALERT(SSL *ssl,
int alert);
274 #define DISPLAY_STATE(A,B,C,D) 275 #define DISPLAY_CERT(A,B) 276 #define DISPLAY_RSA(A,B) 277 #define DISPLAY_ALERT(A, B) 279 void DISPLAY_BYTES(SSL *ssl,
const char *format,
280 const uint8_t *data,
int size, ...);
282 void DISPLAY_BYTES(SSL *ssl,
const char *format,
283 const uint8_t *data,
int size, ...);
287 #ifdef CONFIG_SSL_CERT_VERIFICATION 288 int process_certificate(SSL *ssl,
X509_CTX **x509_ctx);
293 const uint8_t *session_id);
int add_cert(SSL_CTX *ssl_ctx, const uint8_t *buf, int len)
Add a certificate to the certificate chain.
Definition: tls1.c:358
int send_finished(SSL *ssl)
Send a "finished" message.
Definition: tls1.c:1527
int send_change_cipher_spec(SSL *ssl)
Sends the change cipher spec message.
Definition: tls1.c:1511
void finished_digest(SSL *ssl, const char *label, uint8_t *digest)
Calculate the digest used in the finished message.
Definition: tls1.c:951
void add_packet(SSL *ssl, const uint8_t *pkt, int len)
Add a packet to the end of our sent and received packets, so that we may use it to calculate the hash...
Definition: tls1.c:835
void generate_master_secret(SSL *ssl, const uint8_t *premaster_secret)
Generate a master secret based on the client/server random data and the premaster secret...
Definition: tls1.c:924
int send_alert(SSL *ssl, int error_code)
Send an alert message.
Definition: tls1.c:1554
void disposable_free(SSL *ssl)
Remove the temporary blob of memory.
Definition: tls1.c:1705
int process_finished(SSL *ssl, uint8_t *buf, int hs_len)
Process a client finished message.
Definition: tls1.c:1627
Definition: crypto_misc.h:68
int basic_read(SSL *ssl, uint8_t **in_data)
Read the SSL connection.
Definition: tls1.c:1267
int send_certificate(SSL *ssl)
Send a certificate.
Definition: tls1.c:1657
int send_packet(SSL *ssl, uint8_t protocol, const uint8_t *in, int length)
Send an encrypted packet with padding bytes if necessary.
Definition: tls1.c:1084
SSL_SESSION * ssl_session_update(int max_sessions, SSL_SESSION *ssl_sessions[], SSL *ssl, const uint8_t *session_id)
Find if an existing session has the same session id.
Definition: tls1.c:1722
void kill_ssl_session(SSL_SESSION **ssl_sessions, SSL *ssl)
This ssl object doesn't want this session anymore.
Definition: tls1.c:1810
void disposable_new(SSL *ssl)
Create a blob of memory that we'll get rid of once the handshake is complete.
Definition: tls1.c:1692