Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable Curve and Libsodium support #682

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
docker/*.dockerfile
.dockerignore
.git/
build
docs
lib
tmp
**/node_modules
**/yarn.lock
**/yarn-error.log
**/package-lock.json
**/lib/binary/*.node
**/lib/binary/napi-v*/*.node
**/build-tmp-napi-v*
prebuilds
**/test.js
**/.cache/
**/test/typings-compatibility/
script/*.d.ts
script/*.d.*ts
script/*js.map
**/tsconfig.tsbuildinfo
**/tsconfig.*.tsbuildinfo
doc-unminified
**/.DS_Store
**/.idea
staging
!lib/load-addon.js
!lib/load-addon.js.map

**/compile_commands.json

smoke-test-*
*.tgz

61 changes: 23 additions & 38 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ jobs:
- x64
cpp_arch:
- x64
docker:
- ""
docker_cmd:
dockerfile:
- ""

include:
Expand All @@ -44,12 +42,7 @@ jobs:

# Alpine
- os: ubuntu-22.04
docker: node:18-alpine
docker_cmd:
apk add --no-cache bash build-base curl git g++ make ninja-build
pkgconfig unzip zip python3 tar cmake ninja musl-dev && cp
/usr/lib/ninja-build/bin/ninja /usr/bin/ninja && npm i -g pnpm &&
pnpm install && pnpm run build
dockerfile: docker/alpine.dockerfile
node_arch: x64
cpp_arch: x64

Expand Down Expand Up @@ -82,7 +75,7 @@ jobs:
shell: bash

- name: Setup Cpp
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
uses: aminya/setup-cpp@v1
with:
vcvarsall: ${{ contains(matrix.os, 'windows') }}
Expand All @@ -92,48 +85,40 @@ jobs:
vcpkg: true
architecture: ${{ matrix.cpp_arch }}

- name: Install Mac-OS x86_64 Dependencies
if: ${{ contains(matrix.os, 'macos') && matrix.node_arch == 'x64' }}
run: |
brew install libsodium gnutls

- name: Install Mac-OS arm64 Dependencies
if: ${{ contains(matrix.os, 'macos') && matrix.node_arch == 'arm64' }}
- name: Install Mac-OS Dependencies
if: ${{ contains(matrix.os, 'macos') }}
run: |
brew uninstall libsodium --force --ignore-dependencies
source ./script/macos-arm-deps.sh
echo "PATH=$PATH" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV
brew install gnutls autoconf automake libtool

- uses: pnpm/action-setup@v4
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
with:
version: 9

- name: Install Node 20
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
uses: actions/setup-node@v4
with:
node-version: 20
architecture: ${{ env.setup_node_arch }}

- name: Install and Build Native
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
run: pnpm install

- name: Build JavaScript
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
run: pnpm run build.js

- name: Install Node 10
if: ${{ !matrix.docker && matrix.os != 'macos-14' }}
if: ${{ !matrix.dockerfile && matrix.os != 'macos-14' }}
uses: actions/setup-node@v4
with:
node-version: 10
architecture: ${{ env.setup_node_arch }}

- name: Build Native
if: ${{ !matrix.docker && matrix.node_arch != 'ia32' }}
if: ${{ !matrix.dockerfile && matrix.node_arch != 'ia32' }}
run: npm run build.native

- name: Build Native Windows 32
Expand All @@ -143,19 +128,19 @@ jobs:
windows-x86

- name: Use Node 20
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
uses: actions/setup-node@v4
with:
node-version: 20
architecture: ${{ env.setup_node_arch }}

- name: Prebuild Docker
if: ${{ matrix.docker }}
if: ${{ matrix.dockerfile }}
run: |
docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io
docker pull ${{ matrix.docker }}
docker tag ${{ matrix.docker }} builder
docker run --volume ${{ github.workspace }}:/app --workdir /app --privileged builder sh -c "${{ matrix.docker_cmd }}"
docker build -t zeromq -f ${{ matrix.dockerfile }} .
docker create --name zeromq-temp zeromq
docker cp zeromq-temp:/app/build ./build
docker rm -f zeromq-temp

- name: Upload build
uses: actions/upload-artifact@v4
Expand All @@ -165,11 +150,11 @@ jobs:
overwrite: true

- name: Lint
if: "${{ contains(matrix.os, 'ubuntu') && !matrix.docker }}"
if: "${{ contains(matrix.os, 'ubuntu') && !matrix.dockerfile }}"
run: pnpm run lint-test

- name: Test
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
Expand All @@ -183,7 +168,7 @@ jobs:
shell: bash

- name: Test Compatibility
if: ${{ !matrix.docker }}
if: ${{ !matrix.dockerfile }}
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
Expand All @@ -197,7 +182,7 @@ jobs:
shell: bash

- name: Test Electron Windows/MacOS
if: "${{ !matrix.docker }}"
if: "${{ !matrix.dockerfile }}"
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
Expand All @@ -207,7 +192,7 @@ jobs:
continue-on-error: true

- name: Test Electron Linux
if: "${{ contains(matrix.os, 'ubuntu') && !matrix.docker }}"
if: "${{ contains(matrix.os, 'ubuntu') && !matrix.dockerfile }}"
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ endmacro()
option(ZMQ_DRAFT "Build and install draft APIs" OFF)
set_option_from_env(ZMQ_DRAFT)

option(ZMQ_CURVE "Enable CURVE security" OFF)
option(ZMQ_CURVE "Enable CURVE security" ON)
set_option_from_env(ZMQ_CURVE)

option(ZMQ_SODIUM "Using libsodium for CURVE security" OFF)
option(ZMQ_SODIUM "Using libsodium for CURVE security" ON)
set_option_from_env(ZMQ_SODIUM)

if(ZMQ_SODIUM AND APPLE)
message(STATUS "building libsodium requires running `brew install autoconf automake libtool`")
endif()

option(ZMQ_WEBSOCKETS "Enable WebSocket transport" OFF)
set_option_from_env(ZMQ_WEBSOCKETS)

Expand Down
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
- [Prebuilt binaries](#prebuilt-binaries)
- [Building from source](#building-from-source)
- [Available Build Options](#available-build-options)
- [Curve support](#curve-support)
- [Libsodium for Curve](#libsodium-for-curve)
- [Curve with Libsodium support](#curve-with-libsodium-support)
- [Draft support](#draft-support)
- [Websocket support](#websocket-support)
- [Secure Websocket support](#secure-websocket-support)
Expand Down Expand Up @@ -117,25 +116,17 @@ When building from source, you can also specify additional build options in a
<details>
<summary>👉🏻 Options</summary>

### Curve support
### Curve with Libsodium support

Enables CURVE security for encrypted communications. To enable CURVE support,
add the following to your .npmrc:
Enables CURVE security for encrypted communications. Zeromq uses libsodium for CURVE security. To enable CURVE support, add the following to your .npmrc:

```ini
zmq_curve="true"
```

### Libsodium for Curve

Enable libsodium for CURVE security instead of the built-in tweetnacl
implementation. This can provide better performance for CURVE operations. To use
libsodium, add the following to your .npmrc:

```ini
zmq_sodium="true"
```

Building libsodium requires these dependencies on Linux/MacOS: `autoconf automake libtool`, which can be installed via `apt-get` or `brew`, etc.

#### Draft support

By default `libzmq` is built with support for `Draft` patterns (e.g.
Expand Down
28 changes: 28 additions & 0 deletions docker/alpine.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:18-alpine

WORKDIR /app
COPY ./ ./
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
RUN apk add --no-cache \
bash \
build-base \
curl \
git \
g++ \
make \
ninja-build \
pkgconfig \
unzip \
zip \
python3 \
tar \
cmake \
ninja \
musl-dev \
automake \
autoconf \
libtool && \
cp /usr/lib/ninja-build/bin/ninja /usr/bin/ninja && \
npm i -g pnpm && \
pnpm install && \
pnpm run build
File renamed without changes.
Loading