|
70 | 70 | /* @todo: which includes are really needed? */ |
71 | 71 | #include "mbedtls/entropy.h" |
72 | 72 | #include "mbedtls/ctr_drbg.h" |
73 | | -#include "mbedtls/certs.h" |
74 | 73 | #include "mbedtls/x509.h" |
75 | 74 | #include "mbedtls/ssl.h" |
76 | 75 | #include "mbedtls/net_sockets.h" |
|
80 | 79 | #include "mbedtls/ssl_cache.h" |
81 | 80 | #include "mbedtls/ssl_ticket.h" |
82 | 81 |
|
83 | | -#include "mbedtls/ssl_internal.h" /* to call mbedtls_flush_output after ERR_MEM */ |
84 | | - |
85 | 82 | #include <string.h> |
86 | 83 |
|
87 | 84 | #ifndef ALTCP_MBEDTLS_ENTROPY_PTR |
@@ -133,11 +130,13 @@ static int altcp_mbedtls_bio_send(void *ctx, const unsigned char *dataptr, size_ |
133 | 130 |
|
134 | 131 |
|
135 | 132 | static void |
136 | | -altcp_mbedtls_flush_output(altcp_mbedtls_state_t* state) |
| 133 | +altcp_mbedtls_flush_output(altcp_mbedtls_state_t *state) |
137 | 134 | { |
138 | | - int flushed = mbedtls_ssl_flush_output(&state->ssl_context); |
139 | | - if (flushed) { |
140 | | - LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_flush_output failed: %d\n", flushed)); |
| 135 | + if (state->ssl_context.MBEDTLS_PRIVATE(out_left) != 0) { |
| 136 | + int flushed = mbedtls_ssl_send_alert_message(&state->ssl_context, 0, 0); |
| 137 | + if (flushed) { |
| 138 | + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_send_alert_message failed: %d\n", flushed)); |
| 139 | + } |
141 | 140 | } |
142 | 141 | } |
143 | 142 |
|
@@ -532,7 +531,7 @@ altcp_mbedtls_lower_sent(void *arg, struct altcp_pcb *inner_conn, u16_t len) |
532 | 531 | LWIP_ASSERT("state", state != NULL); |
533 | 532 | LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn); |
534 | 533 | /* calculate TLS overhead part to not send it to application */ |
535 | | - overhead = state->overhead_bytes_adjust + state->ssl_context.out_left; |
| 534 | + overhead = state->overhead_bytes_adjust + state->ssl_context.MBEDTLS_PRIVATE(out_left); |
536 | 535 | if ((unsigned)overhead > len) { |
537 | 536 | overhead = len; |
538 | 537 | } |
@@ -692,7 +691,7 @@ altcp_tls_set_session(struct altcp_pcb *conn, struct altcp_tls_session *session) |
692 | 691 | if (session && conn && conn->state) { |
693 | 692 | altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; |
694 | 693 | int ret = -1; |
695 | | - if (session->data.start) |
| 694 | + if (session->data.MBEDTLS_PRIVATE(start)) |
696 | 695 | ret = mbedtls_ssl_set_session(&state->ssl_context, &session->data); |
697 | 696 | return ret < 0 ? ERR_VAL : ERR_OK; |
698 | 697 | } |
@@ -786,7 +785,7 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav |
786 | 785 | struct altcp_tls_config *conf; |
787 | 786 | mbedtls_x509_crt *mem; |
788 | 787 |
|
789 | | - if (TCP_WND < MBEDTLS_SSL_MAX_CONTENT_LEN) { |
| 788 | + if (TCP_WND < MBEDTLS_SSL_IN_CONTENT_LEN || TCP_WND < MBEDTLS_SSL_OUT_CONTENT_LEN) { |
790 | 789 | LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS, |
791 | 790 | ("altcp_tls: TCP_WND is smaller than the RX decrypion buffer, connection RX might stall!\n")); |
792 | 791 | } |
@@ -910,7 +909,7 @@ err_t altcp_tls_config_server_add_privkey_cert(struct altcp_tls_config *config, |
910 | 909 | return ERR_VAL; |
911 | 910 | } |
912 | 911 |
|
913 | | - ret = mbedtls_pk_parse_key(pkey, (const unsigned char *) privkey, privkey_len, privkey_pass, privkey_pass_len); |
| 912 | + ret = mbedtls_pk_parse_key(pkey, (const unsigned char *) privkey, privkey_len, privkey_pass, privkey_pass_len, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg); |
914 | 913 | if (ret != 0) { |
915 | 914 | LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_pk_parse_public_key failed: %d\n", ret)); |
916 | 915 | mbedtls_x509_crt_free(srvcert); |
@@ -1013,7 +1012,7 @@ altcp_tls_create_config_client_2wayauth(const u8_t *ca, size_t ca_len, const u8_ |
1013 | 1012 | } |
1014 | 1013 |
|
1015 | 1014 | mbedtls_pk_init(conf->pkey); |
1016 | | - ret = mbedtls_pk_parse_key(conf->pkey, privkey, privkey_len, privkey_pass, privkey_pass_len); |
| 1015 | + ret = mbedtls_pk_parse_key(conf->pkey, privkey, privkey_len, privkey_pass, privkey_pass_len, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg); |
1017 | 1016 | if (ret != 0) { |
1018 | 1017 | LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_pk_parse_key failed: %d 0x%x\n", ret, -1*ret)); |
1019 | 1018 | altcp_tls_free_config(conf); |
@@ -1199,7 +1198,7 @@ altcp_mbedtls_sndbuf(struct altcp_pcb *conn) |
1199 | 1198 | size_t ret; |
1200 | 1199 | #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) |
1201 | 1200 | /* @todo: adjust ssl_added to real value related to negotiated cipher */ |
1202 | | - size_t max_frag_len = mbedtls_ssl_get_max_frag_len(&state->ssl_context); |
| 1201 | + size_t max_frag_len = mbedtls_ssl_get_max_in_record_payload(&state->ssl_context); |
1203 | 1202 | max_len = LWIP_MIN(max_frag_len, max_len); |
1204 | 1203 | #endif |
1205 | 1204 | /* Adjust sndbuf of inner_conn with what added by SSL */ |
@@ -1242,9 +1241,9 @@ altcp_mbedtls_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t |
1242 | 1241 | /* HACK: if there is something left to send, try to flush it and only |
1243 | 1242 | allow sending more if this succeeded (this is a hack because neither |
1244 | 1243 | returning 0 nor MBEDTLS_ERR_SSL_WANT_WRITE worked for me) */ |
1245 | | - if (state->ssl_context.out_left) { |
| 1244 | + if (state->ssl_context.MBEDTLS_PRIVATE(out_left)) { |
1246 | 1245 | altcp_mbedtls_flush_output(state); |
1247 | | - if (state->ssl_context.out_left) { |
| 1246 | + if (state->ssl_context.MBEDTLS_PRIVATE(out_left)) { |
1248 | 1247 | return ERR_MEM; |
1249 | 1248 | } |
1250 | 1249 | } |
@@ -1294,6 +1293,8 @@ altcp_mbedtls_bio_send(void *ctx, const unsigned char *dataptr, size_t size) |
1294 | 1293 | while (size_left) { |
1295 | 1294 | u16_t write_len = (u16_t)LWIP_MIN(size_left, 0xFFFF); |
1296 | 1295 | err_t err = altcp_write(conn->inner_conn, (const void *)dataptr, write_len, apiflags); |
| 1296 | + /* try to send data... */ |
| 1297 | + altcp_output(conn->inner_conn); |
1297 | 1298 | if (err == ERR_OK) { |
1298 | 1299 | written += write_len; |
1299 | 1300 | size_left -= write_len; |
|
0 commit comments