Hi Jeff,
1. Unable to verify host cert.
To verify the host you need at a minimum a copy of the Host's ROOT CA. You can easily load this in PEM or DER format without a file system. Just use:
wolfSSL_CTX_load_verify_buffer(ssl_object, cert_buffer, sizeof(cert_buffer), SSL_FILETYPE_PEM);
Then format your cert like this:
const unsigned char cert_buffer[] = { "\n\
-----BEGIN CERTIFICATE-----\n\
MIICVzCCAd2gAwIBAgIBKDAKBggqhkjOPQQDAzBBMRMwEQYKCZImiZPyLGQBGRYD\n\
bWlsMRgwFgYKCZImiZPyLGQBGRYIVHlwZTFQS0kxEDAOBgNVBAsTB1BLSUNBMDEw\n\
HhcNMTcwNDE0MTgxMjM3WhcNMjIwNDE0MTgxMjM3WjA3MRUwEwYDVQQFEwxBMDAw\n\
MTAwMDAwMTExHjAcBgNVBAMTFTIuMTYuODQwLjEuMTAxLjIuMS4xNzB2MBAGByqG\n\
SM49AgEGBSuBBAAiA2IABDLKAVvq5fRxDwtVNWczivw7dPECc0I6d6V/+poMFGTC\n\
OhJ+1jubn6VwWGqE5oGm22vJ2CjXC8yTwt+HJ/NVN/oylXGRRAjH0kghGzBP7Zr8\n\
S85cmtn3lP7ygUx7WGNK5qOBsjCBrzATBgNVHSMEDDAKgAhx+thUesQIQzARBgNV\n\
HQ4ECgQI8oFMe1hjSuYwDgYDVR0PAQH/BAQDAgeAMBYGA1UdIAQPMA0wCwYJYIZI\n\
AWUCAQsGMCsGA1UdEQQkMCKgIAYIKwYBBQUHCASgFDASBghghkgBZQIBEQQGoAAQ\n\
AAARMDAGA1UdHwQpMCcwJaAjoCGGH2h0dHBzOi8vUHJpbWFyeVBERS9wa2kvMTAw\n\
MTI3MzkwCgYIKoZIzj0EAwMDaAAwZQIxANMDtwbS4vD+zrge2vuTLwt0cy0J6j9P\n\
LldPMuKrAxRMVQ0fTgDMlxjGyV7onb0NxAIwXW2qCXjEvZBzgOx+IQnCHOjxDLp2\n\
/bDPlrF8llEDzjYvTLmN0cUZ5bwcOQygi3Xo\n\
-----END CERTIFICATE-----\n\n"
};
2. Failure in the Encrypt() function
Yes my first thought here was that you have no encryption configured IE no aes, no 3des, no camellia... etc. The MQTT user_settings example is quite sophisticated but intended to try and present all the available options for customizing our library. You have resolved this already based on the above.
Finally I see you are calling wolfSSL_write() which will call wolfSSL_connect() if the handshake has not completed already, however the downside to doing this is that you will not be able to debug if something goes wrong in the handshake.
I would recommend trying this BEFORE calling wolfSSL_write():
return_value = wolfSSL_connect(xWolfSSL_Object);
if (return_value != SSL_SUCCESS) {
printf("Handshake failed with error code: %d\n", return_value);
}
Is there an error code returned? If so what is the value? If it is -300 or less it is a TLS error and the definition can be found in <wolf-root>/wolfssl/error-ssl.h otherwise if it is in the -200 to 0 range the definition is crypto related and can be found in <wolf-root>/wolfssl/wolfcrypt/error-crypt.h
Regards,
Kaleb