Including OpenSSL in Ardupilot source code

I am having trouble integrating the OpenSSL libraries into my ardupilot source code to be used in the Rover folder under the GCS_Mavlink.cpp file.

So far I have done:

  1. In the root wscript file, under def configure() added:
    cfg.env.INCLUDES_OPENSSL = [‘C:/Users/smt5965/Documents/OpenSSL/include’]
    cfg.env.LIB_OPENSSL = [‘crypto’, ‘ssl’]
    cfg.env.LIBPATH_OPENSSL = [‘C:/Users/smt5965/Documents/OpenSSL’]

  2. Then, specifically in the wscript file in the Rover folder, added:
    ‘OPENSSL’ in
    bld.ap_program(
    program_name=‘ardurover’,
    program_groups=[‘bin’, ‘rover’],
    use=vehicle + ‘_libs OPENSSL’,
    )

  3. I added this as I saw in stack over flow under configure() but I am not sure if this is the correct way to implement:
    cfg.check_cfg(
    package= ‘openssl’,
    args=[‘–cflags’, ‘–libs’],
    uselib_store=‘OPENSSL’,
    mandatory=TRUE
    )

Now I have tried to ./waf rover and build the firmware, however, I always get a file not found error at the beginning of my GCS_Mavlink.cpp in Rover folder, at the line #include <openssl/pem.h>.
This means that the waf system is properly pointing to the correct headers even though it is explicitly stated under the INCLUDES. One other reason is that I have not set a proper build dependency in the build part of the wscript inside the Rover folder itself. I think its a simple fix but I just need to figure out how I can link this external OpenSSL library to my ardupilot source code.

What board are you building for?

You can see how I added CMSIS to chibios in this PR: In-flight dynamic FFT analysis by andyp1per · Pull Request #11886 · ArduPilot/ardupilot · GitHub

I am building for Pixhawk1.

Yeah so a lot of this stuff needs to go in the chibios waf stuff so my PR above is a good starting point

Gotcha, I will try this out in the next couple days. Thank you for the lead I’ll let you know how it goes.

I am now getting this error:
In file included from …/…/…/OpenSSL/include/openssl/pem.h:20,
from …/…/Rover/GCS_Mavlink.cpp:6:
…/…/…/OpenSSL/include/openssl/bio.h:707:17: error: ‘FILE’ was not declared in this scope
707 | BIO *BIO_new_fp(FILE *stream, int close_flag);
| ^~~~
compilation terminated due to -Wfatal-errors.

This means that my OpenSSL library is being correctly found, but I am missing FILE not declared.
I added #include <stdio.h> into my GCS_Mavlink.cpp file, however, I am still getting the same error in Cygwin. Do you know why this is?

the posix implementation in ChibiOS is incomplete

Within the boards.py, under the class ChibiOS, I added:
env.INLUDES += ‘path/to/openssl/include’
env.LIB += ‘path/to/openssl/lib’

This found the OpenSSL libraries but resulted in the BIO_new_fp error FILE not found error.

Where can I look at the posix implementation within ChibiOS? I tried looking at the PR but am confused as to where to proceed.

All of this seems to be the same on my source code in terms of the posix_compat.h file. I also added #include <stdio.h> into the GCS_Mavlink.cpp file where I am implementing the OpenSSL library, but still get the same FILE error. I am wondering if this is because Stdio.h might be looking on the Windows side meanwhile I am trying to build on Cygwin and cygwin is looking at a potential stdio.h file inside Cygwin?

Maybe, you’ll have to nut it out

Seems like OpenSSL will not work since it is such a big system to compile into Pixhawk1. Tried a different library, Tinycrypt, and that worked without errors.