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
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
@@ -19,9 +19,7 @@ jobs:
- x64
cpp_arch:
- x64
docker:
- ""
docker_cmd:
dockerfile:
- ""

include:
@@ -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

@@ -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') }}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
@@ -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.
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.

Unchanged files with check annotations Beta

for await (const [sender, _blank, header, ...rest] of this.socket) {
switch (header.toString()) {
case Header.Client:
this.handleClient(sender, ...rest)

Check warning on line 24 in examples/majordomo/broker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Unsafe argument of type `Router` assigned to a parameter of type `Buffer`

Check warning on line 24 in examples/majordomo/broker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Unsafe spread of an `any` type
break
case Header.Worker:
this.handleWorker(sender, ...rest)

Check warning on line 27 in examples/majordomo/broker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Unsafe argument of type `Router` assigned to a parameter of type `Buffer`

Check warning on line 27 in examples/majordomo/broker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Unsafe spread of an `any` type
break
default:
console.error(`invalid message header: ${header}`)
register(worker: Buffer, service: Buffer) {
this.setWorkerService(worker, service)
this.getService(service).register(worker)

Check warning on line 81 in examples/majordomo/broker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
dispatchRequest(client: Buffer, service: Buffer, ...req: Buffer[]) {
this.getService(service).dispatchRequest(client, ...req)

Check warning on line 85 in examples/majordomo/broker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
dispatchReply(worker: Buffer, client: Buffer, ...rep: Buffer[]) {
deregister(worker: Buffer) {
const service = this.getWorkerService(worker)
this.getService(service).deregister(worker)

Check warning on line 95 in examples/majordomo/broker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
getService(name: Buffer): Service {
_blank2,
...req
] of this.socket) {
const rep = await this.process(...req)

Check warning on line 27 in examples/majordomo/worker.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Unsafe spread of an `any` type
try {
await this.socket.send([
null,
await sock.bind("tcp://127.0.0.1:3000")
console.log("Publisher bound to port 3000")
while (true) {

Check warning on line 9 in examples/pub-sub/publisher.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Unnecessary conditional, value is always truthy

Check warning on line 9 in examples/pub-sub/publisher.ts

GitHub Actions / Build (ubuntu-20.04, x64, x64)

Unexpected constant condition
console.log("sending a multipart message envelope")
await sock.send(["kitty cats", "meow!"])
await new Promise(resolve => {