Skip to content

Commit

Permalink
Merge pull request wolfSSL#380 from philljj/add_curl_easy_sockets
Browse files Browse the repository at this point in the history
Add curl easy socket backend.
  • Loading branch information
embhorn authored Dec 11, 2023
2 parents bc7ac50 + 2945e1e commit 15ba2f2
Show file tree
Hide file tree
Showing 18 changed files with 758 additions and 60 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/ubuntu-check-curl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Ubuntu Build Test with Curl Support

on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Install dependencies
run: |
# Don't prompt for anything
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
# Install mosquitto
sudo apt-get install -y mosquitto bubblewrap
- name: Setup mosquitto broker
run: |
# Disable default broker daemon
sudo service mosquitto stop
sleep 1
# This is some debug info useful if something goes wrong
- name: Show network status
run: |
sudo ifconfig
sudo route
sudo netstat -tulpan
- uses: actions/checkout@master
with:
repository: wolfssl/wolfssl
path: wolfssl
- name: wolfssl autogen
working-directory: ./wolfssl
run: ./autogen.sh
- name: wolfssl configure
working-directory: ./wolfssl
run: ./configure --enable-curl
- name: wolfssl make
working-directory: ./wolfssl
run: make
- name: wolfssl make install
working-directory: ./wolfssl
run: sudo make install

- uses: actions/checkout@master
with:
repository: curl/curl
path: curl
- name: curl autoreconf
working-directory: ./curl
run: autoreconf -fi
- name: curl configure
working-directory: ./curl
run: ./configure --with-wolfssl
- name: curl make
working-directory: ./curl
run: make
- name: curl make install
working-directory: ./curl
run: sudo make install

- uses: actions/checkout@master
- name: wolfmqtt autogen
run: ./autogen.sh

- name: wolfmqtt configure
run: ./configure
- name: wolfmqtt make
run: make
# Note: this will run the external tests for this CI only
- name: wolfmqtt make check
run: make check

- name: wolfmqtt configure with libCurl Enabled
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
run: ./configure --enable-curl
- name: wolfmqtt make
run: make
- name: wolfmqtt make check
run: make check

- name: wolfmqtt configure with libCurl Enabled without TLS
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
run: ./configure --enable-curl --disable-tls
- name: wolfmqtt make
run: make
- name: wolfmqtt make check
run: make check

# capture logs on failure
- name: Show logs on failure
if: failure() || cancelled()
run: |
cat test-suite.log
cat scripts/*.log
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,32 @@ Since the broker and subscriber are still running, you can use `mqttclient` to p

Congratulations! You have just published an MQTT message using TLS 1.3 with the `KYBER_LEVEL1` KEM and `FALCON_LEVEL1` signature scheme. To use the hybrid group, replace `KYBER_LEVEL1` with `P256_KYBER_LEVEL1`.


## Curl Easy Socket Support

wolfMQTT now supports using libcurl's easy socket interface as a backend.
When enabled, wolfMQTT will use the libcurl API for the socket backend,
and libcurl will use wolfSSL to negotiate TLS.
This can be enabled with `--enable-curl`.

At this time wolfMQTT's libcurl option supports both TLS and mTLS, but not Post-Quantum TLS.

### How to use libcurl with wolfMQTT

To use wolfMQTT with libcurl and wolfSSL:
- build wolfssl with `--enable-curl` and install to `/usr/local`.
- build libcurl with `--with-wolfssl` and install to `/usr/local`.

Finally, build wolfMQTT with `--enable-curl`.

### Supported Build Options

The `--enable-curl` option works with these combinations:
- `--enable-mt`
- `--enable-nonblock`
- `--enable-tls` (default enabled)
- `--enable-timeout` (default enabled)

However `--enable-curl` is incompatible and not supported with these options:
- `--enable-all`
- `--enable-sn`
24 changes: 24 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ then
fi


# libcurl support
AC_ARG_ENABLE([curl],
[AS_HELP_STRING([--enable-curl],[Enable curl easy socket backend (default: disabled)])],
[ ENABLED_CURL=$enableval ],
[ ENABLED_CURL=no ]
)

if test "x$ENABLED_CURL" = "xyes"; then
if test "x$ENABLED_ALL" = "xyes"; then
AC_MSG_ERROR([--enable-all and --enable-curl are incompatible])
fi

if test "x$ENABLED_SN" = "xyes"; then
AC_MSG_ERROR([--enable-sn and --enable-curl are incompatible])
fi

AM_CFLAGS="$AM_CFLAGS -DENABLE_MQTT_CURL"

AC_CHECK_LIB([curl],[curl_easy_init],,[AC_MSG_ERROR([libcurl is required and wasn't found on the system. It can be obtained from https://curl.se/download.html.])])
fi


# MQTT v5.0
AC_ARG_ENABLE([v5],
[AS_HELP_STRING([--enable-v5],[Enable MQTT v5.0 support (default: disabled)])],
Expand Down Expand Up @@ -310,6 +332,7 @@ fi


AM_CONDITIONAL([HAVE_LIBWOLFSSL], [test "x$ENABLED_TLS" = "xyes"])
AM_CONDITIONAL([HAVE_LIBCURL], [test "x$ENABLED_CURL" = "xyes"])
AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$ENABLED_EXAMPLES" = "xyes"])
AM_CONDITIONAL([BUILD_STDINCAP], [test "x$ENABLED_STDINCAP" = "xyes"])
AM_CONDITIONAL([BUILD_SN], [test "x$ENABLED_SN" = "xyes"])
Expand Down Expand Up @@ -440,4 +463,5 @@ echo " * Examples: $ENABLED_EXAMPLES"
echo " * Non-Blocking: $ENABLED_NONBLOCK"
echo " * STDIN Capture: $ENABLED_STDINCAP"
echo " * TLS: $ENABLED_TLS"
echo " * CURL: $ENABLED_CURL"
echo " * Multi-thread: $ENABLED_MULTITHREAD"
5 changes: 3 additions & 2 deletions examples/aws/awsiot.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#include "wolfmqtt/mqtt_client.h"


/* This example only works with ENABLE_MQTT_TLS (wolfSSL library) */
#if defined(ENABLE_MQTT_TLS)
/* This example only works with ENABLE_MQTT_TLS (wolfSSL library),
* and without ENABLE_MQTT_CURL. */
#if defined(ENABLE_MQTT_TLS) && !defined(ENABLE_MQTT_CURL)
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(USE_WINDOWS_API)
#include <wolfssl/options.h>
#endif
Expand Down
5 changes: 3 additions & 2 deletions examples/azure/azureiothub.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#include "wolfmqtt/mqtt_client.h"


/* This example only works with ENABLE_MQTT_TLS (wolfSSL library) */
/* This example only works with ENABLE_MQTT_TLS (wolfSSL library)
* and without ENABLE_MQTT_CURL. */
/* Notes:
* The wolfSSL library must be built with
* #define WOLFSSL_BASE64_ENCODE
Expand All @@ -39,7 +40,7 @@
*/

/* This example requires features in wolfSSL 3.9.1 or later */
#if defined(ENABLE_MQTT_TLS)
#if defined(ENABLE_MQTT_TLS) && !defined(ENABLE_MQTT_CURL)
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(USE_WINDOWS_API)
#include <wolfssl/options.h>
#endif
Expand Down
1 change: 1 addition & 0 deletions examples/firmware/fwclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "wolfmqtt/mqtt_client.h"

/* This example only works with ENABLE_MQTT_TLS (wolfSSL library). */
#if defined(ENABLE_MQTT_TLS)
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(USE_WINDOWS_API)
#include <wolfssl/options.h>
Expand Down
Loading

0 comments on commit 15ba2f2

Please sign in to comment.