|
| 1 | + |
| 2 | +name: Secure WebSocket Client Test with wolfSSL |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [ main, master ] |
| 7 | + pull_request: |
| 8 | + branches: [ main, master ] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + test-websocket: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Install Act dependencies |
| 17 | + if: ${{ env.ACT }} |
| 18 | + run: | |
| 19 | + apt-get update && apt-get install sudo git wget nmap netcat -y |
| 20 | +
|
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + sudo apt-get update |
| 24 | + sudo apt-get install -y build-essential autoconf automake libtool cmake |
| 25 | + sudo apt-get install -y mosquitto-clients |
| 26 | +
|
| 27 | + - uses: actions/checkout@master |
| 28 | + with: |
| 29 | + repository: wolfssl/wolfssl |
| 30 | + path: wolfssl |
| 31 | + - name: wolfssl autogen |
| 32 | + working-directory: ./wolfssl |
| 33 | + run: ./autogen.sh |
| 34 | + - name: wolfssl configure with libwebsocket and mosquitto |
| 35 | + working-directory: ./wolfssl |
| 36 | + run: ./configure --enable-libwebsockets --enable-mosquitto --enable-alpn |
| 37 | + - name: wolfssl make |
| 38 | + working-directory: ./wolfssl |
| 39 | + run: make |
| 40 | + - name: wolfssl make install |
| 41 | + working-directory: ./wolfssl |
| 42 | + run: sudo make install |
| 43 | + |
| 44 | + - name: Download libwebsockets |
| 45 | + run: | |
| 46 | + git clone https://libwebsockets.org/repo/libwebsockets |
| 47 | +
|
| 48 | + - name: Build libwebsockets with wolfSSL |
| 49 | + run: | |
| 50 | + cd libwebsockets |
| 51 | + mkdir build |
| 52 | + cd build |
| 53 | + cmake .. -DLWS_WITH_WOLFSSL=1 -DLWS_WOLFSSL_INCLUDE_DIRS=/usr/local/include/wolfssl -DLWS_WOLFSSL_LIBRARIES=/usr/local/lib/libwolfssl.so -DLWS_WITH_EXTERNAL_POLL=1 .. |
| 54 | + make |
| 55 | + sudo make install |
| 56 | +
|
| 57 | + - name: Download mosquitto and apply wolfSSL OSP patch |
| 58 | + run: | |
| 59 | + git clone https://github.com/eclipse/mosquitto.git --branch v2.0.18 --single-branch |
| 60 | + cd mosquitto |
| 61 | + wget https://raw.githubusercontent.com/wolfSSL/osp/refs/heads/master/mosquitto/2.0.18.patch |
| 62 | + patch -p1 < 2.0.18.patch |
| 63 | +
|
| 64 | + - name: Build mosquitto with wolfSSL and websocket support |
| 65 | + run: | |
| 66 | + cd mosquitto |
| 67 | + make WITH_TLS=wolfssl WITH_WEBSOCKETS=yes WITH_DOCS=no WITH_CJSON=no |
| 68 | + sudo make WITH_TLS=wolfssl WITH_WEBSOCKETS=yes WITH_DOCS=no WITH_CJSON=no install |
| 69 | +
|
| 70 | + - uses: actions/checkout@master |
| 71 | + with: |
| 72 | + repository: wolfssl/wolfmqtt |
| 73 | + path: wolfmqtt |
| 74 | + - name: wolfmqtt autogen |
| 75 | + working-directory: ./wolfmqtt |
| 76 | + run: ./autogen.sh |
| 77 | + - name: Configure and build wolfMQTT |
| 78 | + working-directory: ./wolfmqtt |
| 79 | + run: | |
| 80 | + ./configure --enable-websocket |
| 81 | + make |
| 82 | +
|
| 83 | + - name: Create Mosquitto config |
| 84 | + run: | |
| 85 | + echo "listener 11883" > mosquitto.conf |
| 86 | + echo "protocol mqtt" >> mosquitto.conf |
| 87 | + echo "listener 18080" >> mosquitto.conf |
| 88 | + echo "protocol websockets" >> mosquitto.conf |
| 89 | + echo "listener 18081" >> mosquitto.conf |
| 90 | + echo "protocol websockets" >> mosquitto.conf |
| 91 | + echo "cafile scripts/broker_test/ca-cert.pem" >> mosquitto.conf |
| 92 | + echo "certfile scripts/broker_test/server-cert.pem" >> mosquitto.conf |
| 93 | + echo "keyfile scripts/broker_test/server-key.pem" >> mosquitto.conf |
| 94 | + echo "allow_anonymous true" >> mosquitto.conf |
| 95 | +
|
| 96 | + - name: Start Mosquitto broker |
| 97 | + working-directory: ./wolfmqtt |
| 98 | + run: | |
| 99 | + mosquitto -c ../mosquitto.conf -v -d |
| 100 | + # Wait for broker to start |
| 101 | + sleep 2 |
| 102 | +
|
| 103 | + - name: Verify broker is running |
| 104 | + run: | |
| 105 | + # Check if mosquitto is running |
| 106 | + pgrep mosquitto || (echo "Mosquitto failed to start" && exit 1) |
| 107 | + # Check if port 18081 is open |
| 108 | + nc -z localhost 18081 || (echo "WebSocket port 18081 is not open" && exit 1) |
| 109 | +
|
| 110 | + - name: Publish test message |
| 111 | + run: | |
| 112 | + # Start a background process to publish messages |
| 113 | + ( |
| 114 | + # Wait for client to connect and subscribe |
| 115 | + sleep 5 |
| 116 | + # Publish a test message |
| 117 | + mosquitto_pub -t "test/topic" -m "Hello from WebSocket test" -p 11883 |
| 118 | + # Publish a few more messages |
| 119 | + for i in {1..5}; do |
| 120 | + sleep 1 |
| 121 | + mosquitto_pub -t "test/topic" -m "Test message $i" -p 11883 |
| 122 | + done |
| 123 | + ) & |
| 124 | +
|
| 125 | + - name: Run Secure WebSocket client |
| 126 | + working-directory: ./wolfmqtt |
| 127 | + run: | |
| 128 | + # Run the client with a timeout |
| 129 | + timeout 15s ./examples/websocket/websocket_client -t -h localhost -p 18081 -A scripts/broker_test/ca-cert.pem || exit_code=$? |
| 130 | +
|
| 131 | + # Check if client received messages (exit code 124 means timeout occurred, which is expected) |
| 132 | + if [ "$exit_code" -eq 124 ]; then |
| 133 | + echo "Client ran successfully until timeout" |
| 134 | + exit 0 |
| 135 | + elif [ "$exit_code" -ne 0 ]; then |
| 136 | + echo "Client failed with exit code $exit_code" |
| 137 | + exit 1 |
| 138 | + fi |
| 139 | +
|
| 140 | + - name: Stop Mosquitto broker |
| 141 | + run: | |
| 142 | + sudo killall mosquitto |
0 commit comments