@@ -53,6 +53,7 @@ static int verify_digest(SSL *ssl, int mode, const uint8_t *buf, int read_len);
53
53
static void * crypt_new (SSL * ssl , uint8_t * key , uint8_t * iv , int is_decrypt , void * cached );
54
54
static int send_raw_packet (SSL * ssl , uint8_t protocol );
55
55
static void certificate_free (SSL * ssl );
56
+ static int increase_bm_data_size (SSL * ssl );
56
57
57
58
/**
58
59
* The server will pick the cipher based on the order that the order that the
@@ -258,10 +259,11 @@ EXP_FUNC void STDCALL ssl_free(SSL *ssl)
258
259
*/
259
260
EXP_FUNC int STDCALL ssl_read (SSL * ssl , uint8_t * * in_data )
260
261
{
261
- if (ssl -> hs_status == SSL_OK ) {
262
- certificate_free (ssl );
262
+ int ret = increase_bm_data_size (ssl );
263
+ if (ret != SSL_OK ) {
264
+ return ret ;
263
265
}
264
- int ret = basic_read (ssl , in_data );
266
+ ret = basic_read (ssl , in_data );
265
267
266
268
/* check for return code so we can send an alert */
267
269
if (ret < SSL_OK && ret != SSL_CLOSE_NOTIFY )
@@ -285,8 +287,9 @@ EXP_FUNC int STDCALL ssl_read(SSL *ssl, uint8_t **in_data)
285
287
EXP_FUNC int STDCALL ssl_write (SSL * ssl , const uint8_t * out_data , int out_len )
286
288
{
287
289
int n = out_len , nw , i , tot = 0 ;
288
- if (ssl -> hs_status == SSL_OK ) {
289
- certificate_free (ssl );
290
+ int ret = increase_bm_data_size (ssl );
291
+ if (ret != SSL_OK ) {
292
+ return ret ;
290
293
}
291
294
/* maximum size of a TLS packet is around 16kB, so fragment */
292
295
do
@@ -549,6 +552,7 @@ SSL *ssl_new(SSL_CTX *ssl_ctx, int client_fd)
549
552
ssl -> flag = SSL_NEED_RECORD ;
550
553
ssl -> bm_data = ssl -> bm_all_data + BM_RECORD_OFFSET ; /* space at the start */
551
554
ssl -> hs_status = SSL_NOT_OK ; /* not connected */
555
+ ssl -> can_increase_data_size = false;
552
556
#ifdef CONFIG_ENABLE_VERIFICATION
553
557
ssl -> ca_cert_ctx = ssl_ctx -> ca_cert_ctx ;
554
558
#endif
@@ -1405,21 +1409,25 @@ int basic_read(SSL *ssl, uint8_t **in_data)
1405
1409
return ret ;
1406
1410
}
1407
1411
1408
- void increase_bm_data_size (SSL * ssl )
1412
+ int increase_bm_data_size (SSL * ssl )
1409
1413
{
1410
- if (ssl -> max_plain_length == RT_MAX_PLAIN_LENGTH ) {
1411
- return ;
1414
+ if (!ssl -> can_increase_data_size ||
1415
+ ssl -> max_plain_length == RT_MAX_PLAIN_LENGTH ) {
1416
+ return SSL_OK ;
1412
1417
}
1413
-
1418
+ ssl -> can_increase_data_size = false;
1419
+ certificate_free (ssl );
1414
1420
free (ssl -> bm_all_data );
1415
1421
ssl -> bm_data = 0 ;
1416
1422
ssl -> bm_all_data = malloc (RT_MAX_PLAIN_LENGTH + RT_EXTRA );
1417
1423
if (!ssl -> bm_all_data ) {
1418
1424
printf ("failed to grow plain buffer\r\n" );
1419
- return ;
1425
+ ssl -> hs_status == SSL_ERROR_DEAD ;
1426
+ return SSL_ERROR_CONN_LOST ;
1420
1427
}
1421
1428
ssl -> max_plain_length = RT_MAX_PLAIN_LENGTH ;
1422
1429
ssl -> bm_data = ssl -> bm_all_data + BM_RECORD_OFFSET ;
1430
+ return SSL_OK ;
1423
1431
}
1424
1432
1425
1433
/**
@@ -1686,7 +1694,6 @@ static void certificate_free(SSL* ssl)
1686
1694
ssl -> x509_ctx = 0 ;
1687
1695
}
1688
1696
#endif
1689
- increase_bm_data_size (ssl );
1690
1697
}
1691
1698
1692
1699
#ifndef CONFIG_SSL_SKELETON_MODE /* no session resumption in this mode */
0 commit comments