1 (edited by karanbanthia 2020-07-04 03:51:02)

Topic: PIC32MZ controller restart during SSL handshake

Hi,
I am just getting started with WolfSSL library in MPLAB Harmony v2.06 using PIC32MZ curiosity development board with MRF24WN Wi-Fi module. During the negotiation phase, pic32mz controller gets restarted. Kindly help to find root cause and suggest solution.

Below are some checks in place:
I have extended the demo project to connect to https://test.mosquitto.org/ over secured port 8883.
I have downloaded PEM certificate file from official website (http://test.mosquitto.org/), converted to ASCII and loaded using buffer.

Below are some configuration details:

#define MICROCHIP_MPLAB_HARMONY
#define MICROCHIP_TCPIP
#define MICROCHIP_PIC32
#define WOLFSSL_HAVE_MIN
#define WOLFSSL_HAVE_MAX


#define MICROCHIP_PIC32_RNG
#define NEED_AES_TABLES
#define SIZEOF_LONG_LONG 8
#define WOLFSSL_USER_IO
#define NO_WRITEV
#define NO_DEV_RANDOM
#define NO_FILESYSTEM
#define WOLFSSL_STATIC_RSA


#define SINGLE_THREADED

#define USE_FAST_MATH
#define TFM_TIMING_RESISTANT
#define NO_WOLFSSL_SERVER
#define NO_DES3
#define NO_MD4
#define NO_RC4
#define NO_RABBIT
#define NO_HC128
#define HAVE_AESGCM

#define DEBUG_WOLFSSL

#define NO_OLD_TLS

#define WOLFSSL_TRUST_PEER_CERT

Below is the console log

>openurl https://test.mosquitto.org/
>Connecting to host
Connection Opened: Starting SSL Negotiation
Waiting for completion of secure negotiation
wolfSSL (2): wolfSSL Entering WOLFSSL_CTX_new_ex
wolfSSL (2): wolfSSL Entering wolfSSL_CertManagerNew
wolfSSL (2): wolfSSL Entering wolfSSL_CTX_load_verify_buffer
wolfSSL (1): Adding a CA
wolfSSL (2): wolfSSL Entering GetExplicitVersion
wolfSSL (2): wolfSSL Entering GetSerialNumber
wolfSSL (1): Got Cert Header
wolfSSL (2): wolfSSL Entering GetAlgoId
wolfSSL (2): wolfSSL Entering GetObjectId()
wolfSSL (1): Got Algo ID
wolfSSL (1): Getting Cert Name
wolfSSL (1): Getting Cert Name
wolfSSL (1): Got Subject Name
wolfSSL (2): wolfSSL Entering GetAlgoId
wolfSSL (2): wolfSSL Entering GetObjectId()
wolfSSL (1): Got Key
wolfSSL (1): Parsed Past Key
wolfSSL (2): wolfSSL Entering DecodeCertExtensions
wolfSSL (2): wolfSSL Entering GetObjectId()
wolfSSL (2): wolfSSL Entering GetAlgoId
wolfSSL (1):    Freeing der CA
wolfSSL (2): wolfSSL Entering GetExplicitVersion
wolfSSL (2): wolfSSL Entering GetObjectId()
wolfSSL (1): Got Subject Name
wolfSSL (1): Parsed Past Key
wolfSSL (2): wolfSSL Entering GetObjectId()
wolfSSL (2): wolfSSL Entering GetAlgoId
wolfSSL (1):    Freeing der trusted peer cert
wolfSSL (2): wolfSSL Entering SSL_set_fd
wolfSSL (1): growing output buffer


wolfSSL (2): wolfSSL Entering SSL_connect()
wolfSSL (2): wolfSSL Entering SSL_connect()
wolfSSL (2): wolfSSL Entering SSL_get_error
wolfSSL (2): wolfSSL Entering SSL_get_error
wolfSSL (2): wolfSSL Entering DoHandShakeMsg()
wolfSSL (1): growing input buffer

wolfSSL (1): processing server hello
wolfSSL (2): wolfSSL Entering SSL_connect()
wolfSSL (2): wolfSSL Entering SSL_connect()

After this, the controller restarts.
P.S.: I have deleted repeated console debug output messages.

Share

Re: PIC32MZ controller restart during SSL handshake

karanbanthia,

This kind of restart is most often due to a collision between the heap and stack. Can you try increasing the stack or the heap or both and let us know if the reset issue resolves?

Warm Regards,

K

Re: PIC32MZ controller restart during SSL handshake

Hi Kaleb,
I have tried increasing the stack and heap (both) but it did not help. Micro-controller is still restarting with the same debug log.
Stack: 8192
Heap: 131072

I am using Microchip's TCP/IP Stack with below settings
TCP/IP Stack Dynamic RAM size: 51200
TCP/IP Stack Dynamic RAM lower limit: 4096
Max. TCP TX segment size: 3072
Deafult TCP TX & RX segment size: 1024

I am using Berkeley API for socket management, connection and Microchip's Network Presentation Layer for interaction with wolfSSL. connect() function internally manages Network Presentation Socket as part of BSD socket and this assignment is working fine.

Are there any additional settings I need to dig into ?

Share

Re: PIC32MZ controller restart during SSL handshake

karanbanthia,

Are you using the USE_FAST_MATH setting? If so you should configure more stack, try around 23k and make sure you have ALT_ECC_SIZE defined when USE_FAST_MATH is also defined.

Heap you should only need 16-30k depending on optimizations. If you don't want to set the stack higher you can try using the setting WOLFSSL_SMALL_STACK to shift memory usage to the HEAP and remove the setting USE_FAST_MATH and compile integer.c instead of tfm.c to use mostly HEAP.

- KH