-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct ssl recv #1
Changes from all commits
8ba895c
9afaed5
fff596b
4e39b7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,13 @@ | |
* Compatibility for AxTLS with LWIP raw tcp mode (http://lwip.wikia.com/wiki/Raw/TCP) | ||
* Original Code and Inspiration: Slavey Karadzhov | ||
*/ | ||
|
||
// To handle all the definitions needed for debug printing, we need to delay | ||
// macro definitions till later. | ||
#define DEBUG_SKIP__DEBUG_PRINT_MACROS 1 | ||
#include <async_config.h> | ||
#undef DEBUG_SKIP__DEBUG_PRINT_MACROS | ||
|
||
#if ASYNC_TCP_SSL_ENABLED | ||
|
||
#include "lwip/opt.h" | ||
|
@@ -34,6 +40,13 @@ | |
#include <stdbool.h> | ||
#include <tcp_axtls.h> | ||
|
||
// ets_uart_printf is defined in esp8266_undocumented.h, in newer Arduino ESP8266 Core. | ||
extern int ets_uart_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); | ||
#include <DebugPrintMacros.h> | ||
#ifndef TCP_SSL_DEBUG | ||
#define TCP_SSL_DEBUG(...) do { (void)0;} while(false) | ||
#endif | ||
|
||
uint8_t * default_private_key = NULL; | ||
uint16_t default_private_key_len = 0; | ||
|
||
|
@@ -377,7 +390,8 @@ int tcp_ssl_read(struct tcp_pcb *tcp, struct pbuf *p) { | |
|
||
do { | ||
read_bytes = ssl_read(fd_data->ssl, &read_buf); | ||
//TCP_SSL_DEBUG("tcp_ssl_ssl_read: %d\n", read_bytes); | ||
TCP_SSL_DEBUG("tcp_ssl_ssl_read: %d\n", read_bytes); | ||
|
||
if(read_bytes < SSL_OK) { | ||
if(read_bytes != SSL_CLOSE_NOTIFY) { | ||
TCP_SSL_DEBUG("tcp_ssl_read: read error: %d\n", read_bytes); | ||
|
@@ -387,20 +401,31 @@ int tcp_ssl_read(struct tcp_pcb *tcp, struct pbuf *p) { | |
} else if(read_bytes > 0){ | ||
if(fd_data->on_data){ | ||
fd_data->on_data(fd_data->arg, tcp, read_buf, read_bytes); | ||
// fd_data may have been freed in callback | ||
fd_data = tcp_ssl_get(tcp); | ||
if(NULL == fd_data) | ||
return SSL_CLOSE_NOTIFY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you comment on where the actual fix is? I see a lot of changed lines, but I'd like to know where the fixed happened so that I can review this accurately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fix is at line 418 through 420 and 404 through 407. |
||
} | ||
total_bytes+= read_bytes; | ||
} else { | ||
if(fd_data->handshake != SSL_OK) { | ||
fd_data->handshake = ssl_handshake_status(fd_data->ssl); | ||
if(fd_data->handshake == SSL_OK){ | ||
//TCP_SSL_DEBUG("tcp_ssl_read: handshake OK\n"); | ||
// fd_data may be freed in callbacks. | ||
int handshake = fd_data->handshake = ssl_handshake_status(fd_data->ssl); | ||
if(handshake == SSL_OK){ | ||
TCP_SSL_DEBUG("tcp_ssl_read: handshake OK\n"); | ||
if(fd_data->on_handshake) | ||
fd_data->on_handshake(fd_data->arg, fd_data->tcp, fd_data->ssl); | ||
} else if(fd_data->handshake != SSL_NOT_OK){ | ||
TCP_SSL_DEBUG("tcp_ssl_read: handshake error: %d\n", fd_data->handshake); | ||
fd_data = tcp_ssl_get(tcp); | ||
if(NULL == fd_data) | ||
return SSL_CLOSE_NOTIFY; | ||
} else if(handshake != SSL_NOT_OK){ | ||
TCP_SSL_DEBUG("tcp_ssl_read: handshake error: %d\n", handshake); | ||
if(fd_data->on_error) | ||
fd_data->on_error(fd_data->arg, fd_data->tcp, fd_data->handshake); | ||
return fd_data->handshake; | ||
fd_data->on_error(fd_data->arg, fd_data->tcp, handshake); | ||
return handshake; | ||
// With current code APP gets called twice at onError handler. | ||
// Once here and again after return when handshake != SSL_CLOSE_NOTIFY. | ||
// As always APP must never free resources at onError only at onDisconnect. | ||
} | ||
} | ||
} | ||
|
@@ -525,13 +550,13 @@ int ax_port_write(int fd, uint8_t *data, uint16_t len) { | |
TCP_SSL_DEBUG("ax_port_write: No memory %d (%d)\n", tcp_len, len); | ||
return err; | ||
} | ||
TCP_SSL_DEBUG("ax_port_write: tcp_write error: %d\n", err); | ||
TCP_SSL_DEBUG("ax_port_write: tcp_write error: %ld\n", err); | ||
return err; | ||
} else if (err == ERR_OK) { | ||
//TCP_SSL_DEBUG("ax_port_write: tcp_output: %d / %d\n", tcp_len, len); | ||
err = tcp_output(fd_data->tcp); | ||
if(err != ERR_OK) { | ||
TCP_SSL_DEBUG("ax_port_write: tcp_output err: %d\n", err); | ||
TCP_SSL_DEBUG("ax_port_write: tcp_output err: %ld\n", err); | ||
return err; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these changes relating to logging?
I'd prefer them to be filed in a separate PR to make reviewing easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes were needed to generalize the debug print macro a little more so I could get them to work from tcp_axtls.c.