Topic: Porting wolfSSL to ch32v307

Hi,

I am working on a project trying to port wolfSSL 4.4 to ch32v307, one RISC-V MCU designed by WCH company. This embed board will work as one ssl client. The mcu has its own protocol library for tcp/udp communication task. I copied wolfssl/wolfcrypt source and header files to mcu project, using user-defined setting file for wolfSSL. Now the compilation is successful and firmware can run in embed board. But from the debug message it is failed during SSL handshake. By wireshark tool, I can observe that ssl client send Client Hello to ssl server and server returns Server Hello, but it has problem when paring the Server Hello packet. I debugged the wolfSSL program, its call stack is like this:

ssl.c wolfSSL_connect()
internal.c ProcessReply()
internal.c GetInputData()
internal.c wolfSSLReceive()
wolfio.c EmbedReceive()
wolfio.c wolfIO_Recv()

From the log the function wolfIO_Recv() reads the whole Server Hello packet which is 1427 bytes, but the wolfSSL expects 5 bytes at first time, then parse the remaining contents of Server Hello. I mean it seems that wolfSSL is trying to parse Server Hello packet by two parts, but wolfIO_Recv() read the packet by one calling.

Here is the log information (some are wolfSSL messages, some are from my mcu project.)

wolfSSL Entering wolfSSL_Init
wolfSSL Entering wolfCrypt_Init
wolfSSL Entering TLSv1_2_client_method_ex
wolfSSL Entering wolfSSL_CTX_new_ex
wolfSSL Entering wolfSSL_CertManagerNew
wolfSSL Leaving WOLFSSL_CTX_new, return 0
wolfSSL Entering wolfSSL_CTX_set_verify
WCHNET_SocketCreat 0
wolfSSL Entering SSL_new
wolfSSL Leaving SSL_new, return 0
wolfSSL Entering SSL_set_fd
wolfSSL Entering SSL_set_read_fd
wolfSSL Leaving SSL_set_read_fd, return 1
wolfSSL Entering SSL_set_write_fd
wolfSSL Leaving SSL_set_write_fd, return 1
ssl:20000404
MACAddr:200003f8
maclen:20017fcc
PHY Link Success
TCP Connect Success
wolfSSL Entering SSL_connect()
wolfSSL Entering SendClientHello
Adding signature algorithms extension
growing output buffer

Signature Algorithms extension to write
Point Formats extension to write
Supported Groups extension to write
Encrypt-Then-Mac extension to write
EMS extension to write
sz:142
@sz:142 sent:142
Shrinking output buffer

wolfSSL Leaving SendClientHello, return 0
enter solfSSL_ETHRx
recv data len:1427

connect state: CLIENT_HELLO_SENT
ProcessReply
AA
GetInputData, size:5

EmbedReceive: 5
wolfIO_Recv: 1427 flag:0
@sz:1427 recvd:1427
buf:16 03 03 05 FFFFFF8E
wolfSSL error occurred, error = -376

Could anyone give me some suggestions for this problem?

Does wolfSSL really need to parse Server Hello packet by two parts/calling wolfIO_Recv() twice?
Or my user-defined setting header file for wolfSSL has something wrong?

Thanks,
Rick

Share