I’m looking into integrating DTLS into my application using mbedtls as well.
A lot of learning to do! If anyone else working on this stuff wants to start a discussion group or slack PM me. It would be interesting to see how others are approaching the problem.
I tried to integrate and compile the mbedtls for my project but get the following missing headers:
net.c:64:24: fatal error: sys/socket.h: No such file or directory
I am on a mac and installed the arm-gcc via brew. I followed the comments by @cwingrav and use the following make command:
make CFLAGS="-I$PWD -DMBEDTLS_CONFIG_FILE='<configs/config-ccm-psk-tls1_2.h>'" CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld lib
Any idea where I can get the socket.h?
Does anyone have any links for some guides on trying this out. I am sorely in need of getting HTTPS comms to feed data back to a collector on an internal network.
Glowfi.sh examples haven’t worked for me at all.
I really don’t want to have to switch to a Raspberry Pi solution and would much prefer to stick with the particle.io devices.
I’d also like to see system level TSL added to the Photon partially for doing secure MQTT
The Adafruit WICED WiFi Feather https://www.adafruit.com/product/3056 has system level TSL
I believe even the esp8266 has TSL support.
I understand that the focus for secure communications with the Photon is through the particle cloud but there are plenty of applications where additional secure connections are also required.
Now I try to use mbedTLS with MQTT library on Particle Dev, but I got same error on particle firmware mbedTLS source. mbedTLS -> net.c : #include <sys/socket.h>
is really used?
And I try same include line on WebIDE #include <sys/socket.h>
but I got same error!!
I think it have to use socket_hal.h, inet_hal.h....etc, instead of sys/socket.h, netinet/in.h, arpa/inet.h
include line.
I’m here to update my previous post about how to compile and use mbedtls. This is a MUCH simpler method that has only one modification to the existing build process. I went back through and read about how they want us to build apps locally. Turns out they have quite a bit of machinery in their makefiles that almost works.
First, build the local firmware following these great instructions:
https://github.com/spark/firmware/blob/develop/docs/gettingstarted.md
Second, be aware this link exists for further reading:
https://github.com/spark/firmware/blob/develop/docs/build.md
Third, let’s get started. To locally build an app and flash it, create the following directory structure:
$(MYCODEDIR)/Makefile
$(MYCODEDIR)/myapp/<all source code>
$(MYCODEDIR)/myapp/myapp.mk
Fourth, let’s create that Makefile. Here’s what the Makefile entry is to build ‘myapp’. Notice MY_COMMANDLINE_DEFINE, which you can use to inject cpp preprocessor defines (but add to myapp.mk as well, see below). The LIB_MINE is set to include libcommunication.a which has mbedtls complied in:
FIRMWARE=/path/to/where/you/compiled/firmware/in/step/1
MYCODEDIR=/path/to/my/code,/i.e./application.cpp
myapp :
@echo "... making $@"
cd $(FIRMWARE)/main && make all PLATFORM=$(PLATFORM) APP=$@ APPDIR=$(MYCODEDIR)/myapp \
LIB_MINE=$(FIRMWARE)/build/target/communication/platform-$(PLATFORM_ID)-prod-$(PLATFORM_ID)/libcommunication.a \
MY_COMMANDLINE_DEFINE=3 \
program-dfu
@echo "... flashed $@"
Fifth, let’s create that myapp.mk file. This is included in the build process. Notice the INCLUDE_DIRS will add directories for CFLAGS to search down, and in this case, the mbedtls includes. Also, see we can add to CFLAGS, and we pass MY_COMMANDLINE_DEFINE from above to here.
FIRMWARE=/path/to/where/you/compiled/firmware/in/step/1
INCLUDE_DIRS += $(FIRMWARE)/communication/lib/mbedtls/include
CFLAGS += -DMY_COMMANDLINE_DEFINE=\"$(MY_COMMANDLINE_DEFINE)\"
Sixth, and this is absolutely critical. We need to modify a build rule in the particle firmware so LIB_MINE will be linked. I could not figure out how to get the APPLIBS, LIBS or LIB_DEPS mentioned in their build.md documentation to work, so this sixth rule became necessary. Modify the $(TARGET_BASE).elf rule and update the 6th line to:
$(TARGET_BASE).elf : build_dependencies $(ALLOBJ) $(LIB_DEPS) $(LINKER_DEPS)
...
$(VERBOSE)$(CPP) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) $(LIB_MINE) # HACKED
...
Seventh, build. Go to you $(MYCODEDIR) directory and type make myapp PLATFORM=photon
, assuming you are on a photon.
I have this working on my machine but wrote these instructions to be generic so please let me know if they do or don’t work for you so I can make corrections. Also, for mbedtls, I believe the configuration file is in communication/src/mbedtls_config.h
. Cheers!