Hi kareem,
Thank you for your answer
It turned out that you don't need to use this function:
ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method())
at the point where we initialise Wolfssl with the WOLFSSL_STATIC_MEMORY flag. The question arose because on Linux, where I test if the configuration works, I had an error in the
wolfSSL_CTX_load_static_memory()
because I was initialising the client but the function I specified was wolfTLSv1_3_server_method_ex instead of wolfTLSv1_3_client_method_ex that was the reason why comunication between terminals did not work. So this made it possible to drop the
function which is recommended for static memory. But I have a problem because my processor doesn't support dynamic memory allocation, so once I create the "ctx" with wolfSSL_CTX_load_static_memory and load the certificate with wolfSSL_CTX_load_verify_buffer I proceed to initialize ssl with with
and I don't know if this function requires dynamic memory allocation and if I need it at all because I'm using a different physical layer than socket so I declare my read and write functions with wolfSSL_CTX_SetIORecv and wolfSSL_CTX_SetIOSend
I also checked the flags you gave me and got this error:
#error static memory does not support small stack please undefine
therefore I have abandoned this flag
now my log is:
Adding a CA
Getting Cert Name
Getting Cert Name
wolfSSL Entering GetAlgoId
wolfSSL Entering DecodeCertExtensions
wolfSSL Entering DecodeSubjKeyId
wolfSSL Entering DecodeAuthKeyId
wolfSSL Entering DecodeBasicCaConstraint
wolfSSL Entering DecodeAltNames
Unsupported name type, skipping
wolfSSL Entering DecodeExtKeyUsage
Parsed new CA
Freeing Parsed CA
Freeing der CA
OK Freeing der CA
wolfSSL Leaving AddCA, return 0
Processed a CA
Processed at least one valid CA. Other stuff OK
wolfSSL Leaving wolfSSL_CTX_load_verify_buffer_ex, return 1
wolfSSL_CTX_load_verify_buffer: PASS.
wolfSSL Entering wolfSSL_new
Setting fixed IO for SSL
Setting fixed IO for SSL
wolfSSL Entering ReinitSSL
RNG Init error
Free'ing server ssl
Freeing fixed IO buffer
Freeing fixed IO buffer
wolfSSL Leaving wolfSSL_new, return -199
wolfSSL_new error.
wolfSSL Entering wolfSSL_write
wolfSSL Entering wolfSSL_free
wolfSSL Leaving wolfSSL_free, return 0
wolfSSL Entering wolfSSL_CTX_free
CTX ref count down to 0, doing full free
wolfSSL Entering wolfSSL_CertManagerFree
wolfSSL Leaving wolfSSL_CTX_free, return 0
wolfSSL Entering wolfSSL_Cleanup
wolfSSL Entering wolfCrypt_Cleanup
And my code:
WOLFSSL_CTX* ctx = NULL; /* pass NULL to generate WOLFSSL_CTX */
#define MAX_CONCURRENT_TLS 0
#define MAX_CONCURRENT_IO 0
#define GEN_MEM_SIZE 200000
#define IO_MEM_SIZE 100000
unsigned char GEN_MEM[GEN_MEM_SIZE];
unsigned char IO_MEM[IO_MEM_SIZE ];
int ret;
if (wolfSSL_Debugging_ON() != 0) {
uart.write("debugin FAIL.\n");
}
ret = wolfSSL_CTX_load_static_memory(
&ctx, /* set NULL to ctx */
wolfTLSv1_3_client_method_ex, /* use function with "_ex" */
GEN_MEM, GEN_MEM_SIZE, /* buffer and its size */
WOLFMEM_GENERAL, /* general purpose */
MAX_CONCURRENT_TLS); /* max concurrent objects */
if (ret != SSL_SUCCESS)
uart.write("wolfSSL_CTX_load_static_memory: GEN_MEM: FAIL.\n");
else
uart.write("wolfSSL_CTX_load_static_memory: GEN_MEM: PASS.\n");
/* set up a I/O-purpose buffer on the second call. */
ret = wolfSSL_CTX_load_static_memory(
&ctx, /* make sure ctx is holding the object */
NULL, /* pass it to NULL this time */
IO_MEM, IO_MEM_SIZE, /* buffer and its size */
WOLFMEM_IO_POOL_FIXED, /* I/O purpose */
MAX_CONCURRENT_IO); /* max concurrent objects */
if (ret != SSL_SUCCESS)
uart.write("wolfSSL_CTX_load_static_memory: IO_MEM: FAIL.\n");
else
uart.write("wolfSSL_CTX_load_static_memory: IO_MEM: PASS.\n");
ret = wolfSSL_CTX_load_verify_buffer(ctx, certBuf, certBufSz, SSL_FILETYPE_PEM);
if (ret != SSL_SUCCESS)
uart.write("wolfSSL_CTX_load_verify_buffer: FAIL.\n");
else
uart.write("wolfSSL_CTX_load_verify_buffer: PASS.\n");
wolfSSL_CTX_SetIOSend(ctx, myCBIOSend);
wolfSSL_CTX_SetIORecv(ctx, myCBIORecv);
WOLFSSL* ssl;
if( (ssl = wolfSSL_new(ctx)) == NULL) {
uart.write("wolfSSL_new error.\n");
}
wolfSSL_write(ssl, "test", 5);
wolfSSL_free(ssl); /* Free SSL object */
wolfSSL_CTX_free(ctx); /* Free SSL_CTX object */
wolfSSL_Cleanup(); /* Free wolfSSL */
And from what I understand this is the correct way to use wolfssl to get encrypted transmission please correct me if I am wrong