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

Add wolfSSL support for realm-core #204

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Each project port included in this repository is contained in its own subdirecto
| Python | Python language and interpreter | [Link](https://www.python.org/) | | [README](./Python/README.txt) |
| qt | Qt | [Link](https://www.qt.io/) | [Link](https://www.wolfssl.com/building-qt-with-wolfssl/) | [README](./qt/README.md) |
| rsyslog | rocket-fast Syslog Server | [Link](https://www.rsyslog.com/) | [Link](https://www.wolfssl.com/wolfssl-ported-rsyslog-8-2106-0/) | [README](./rsyslog/8.2106.0/README.md) |
| realm-core | Database that runs on phones, tablets or wearables | [Link](https://github.com/realm/realm-core/) | | [README](./realm/README.md) |
| sblim-sfcb | SBLIM Small-footprint CIM Broker | [Link](http://sblim.sourceforge.net/wiki/index.php/Sfcb) | | [README](./sblim-sfcb/1.4.9/README.md) |
| socat | socat Multipurpose relay | [Link](http://www.dest-unreach.org/socat/) | [Link](https://www.wolfssl.com/open-source-project-ports-socat/) | 1.7.3.4 [README](./socat/1.7.3.4/README.md)<br/>1.7.4.1 [README](./socat/1.7.4.1/README.md) |
| stunnel | stunnel Proxy | [Link](https://www.stunnel.org/) | [Link](https://www.wolfssl.com/securing-stunnel-tls-1-3/) | 5.57 Unix [README](./stunnel/5.57/README_UNIX.md)<br/>5.57 Windows [README](./stunnel/5.57/README_WIN.md) |
Expand Down
31 changes: 31 additions & 0 deletions realm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
To configure wolfSSL, use the following command:

```
./configure --enable-static --enable-opensslall --enable-enckeys --enable-certgen --enable-context-extra-user-data
sudo make install
```

Configuring wolfSSL for local installation can be specified with `--prefix=/path/to/install`

Downloading and applying the patch for realm-core git commit a5e87a39:

```
git clone https://github.com/realm/realm-core.git
cd realm-core
git reset --hard HEAD
git checkout a5e87a39
git submodule update --init --recursive
git apply ../realm-v13.26.0.patch
```

Building realm-core:

```
mkdir build
cmake -B build -DREALM_ENABLE_ENCRYPTION=1 -DREALM_ENABLE_SYNC=1 -DREALM_USE_WOLFSSL=1 -DREALM_WOLFSSL_ROOT_DIR=/usr/local/lib
cmake --build build
./build/test/realm-tests
```

You can also use the build_wolfssl_with_realm.sh script after adjusting the global variables as needed.

166 changes: 166 additions & 0 deletions realm/build_wolfssl_with_realm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/bin/bash

#bash -x ./build_wolfssl_with_realm.sh


# While the support to build from a tarball is included,
# Please note that to successfully build,
# you will need to manually download and set up Catch2 to match the Git
# repository structure when using the tarball. For example,
# mkdir -p test/external/generated/catch2
# curl -L -O
# https://github.com/catchorg/Catch2/archive/refs/tags/v2.13.9.tar.gz
# tar -xvf v2.13.9.tar.gz --strip-components=1 -C
# test/external/generated/catch2


# Commit hashes for specific versions when using git
WOLFSSL_COMMIT="e814d1ba"
#REALM_CORE_COMMIT="c729fc80"
REALM_CORE_COMMIT="a5e87a39" # Adjust if necessary

# Variables
WOLFSSL_VERSION="v5.7.2-stable"
REALM_CORE_VERSION="v13.26.0"
WOLFSSL_TAR="${WOLFSSL_VERSION}.tar.gz"
REALM_TAR="${REALM_CORE_VERSION}.tar.gz"
WOLFSSL_URL="https://github.com/wolfSSL/wolfssl/archive/refs/tags/${WOLFSSL_TAR}"
REALM_URL="https://github.com/realm/realm-core/archive/refs/tags/${REALM_TAR}"
OSP_REALM_DIR="realm"
WOLFSSL_DIR="wolfssl"
REALM_CORE_DIR="realm-core"
BUILD_DIR="build"
TEST_EXECUTABLE="$BUILD_DIR/test/realm-tests"
WOLFSSL_INSTALL_DIR="$HOME/wolfssl-install-dir"
USE_SYSTEM_INSTALL=true # Change this to true if you want to use system-wide wolfSSL installation
USE_GIT=true # Default method is using git, set this to false to use curl for tarball

# Patch file based on REALM_CORE_COMMIT or REALM_CORE_VERSION
PATCH_FILE=""

# Check if user wants to use git
while getopts ":t" opt; do
case $opt in
t)
USE_GIT=false
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done

# Step 2: Download or clone wolfSSL
if [ "$USE_GIT" = true ]; then
if [ ! -d "$WOLFSSL_DIR" ]; then
echo "Cloning the wolfSSL repository..."
git clone https://github.com/wolfSSL/wolfssl.git "$WOLFSSL_DIR"
cd "$WOLFSSL_DIR" || exit
echo "Checking out commit $WOLFSSL_COMMIT..."
git checkout "$WOLFSSL_COMMIT"
else
cd "$WOLFSSL_DIR" || exit
git fetch
echo "Checking out commit $WOLFSSL_COMMIT..."
git checkout "$WOLFSSL_COMMIT"
fi
else
if [ ! -d "$WOLFSSL_DIR" ]; then
echo "Downloading wolfSSL..."
curl -L -O "$WOLFSSL_URL"
echo "Extracting wolfSSL..."
tar -xvf "$WOLFSSL_TAR"

EXTRACTED_WOLFSSL_DIR=$(tar -tzf "$WOLFSSL_TAR" | head -1 | cut -f1 -d"/")
if [ -d "$EXTRACTED_WOLFSSL_DIR" ]; then
mv "$EXTRACTED_WOLFSSL_DIR" "$WOLFSSL_DIR"
else
echo "Error: Failed to extract or find the wolfSSL directory."
exit 1
fi
fi
cd "$WOLFSSL_DIR" || exit
fi

# Step 3: Build and install wolfSSL
if [ "$USE_SYSTEM_INSTALL" = true ]; then
echo "Configuring wolfSSL for system-wide installation..."
./autogen.sh
./configure --enable-static --enable-opensslall --enable-enckeys --enable-certgen --enable-context-extra-user-data
else
./autogen.sh
echo "Configuring wolfSSL for local installation at $WOLFSSL_INSTALL_DIR..."
./configure --enable-static --enable-opensslall --enable-enckeys --enable-certgen --enable-context-extra-user-data --prefix="$WOLFSSL_INSTALL_DIR"
fi

echo "Building and installing wolfSSL..."
make -j$(nproc)
sudo make install

# Step 4: Download or clone realm-core
cd ..
if [ "$USE_GIT" = true ]; then
PATCH_FILE="realm-commit-${REALM_CORE_COMMIT}.patch"
if [ ! -d "$REALM_CORE_DIR" ]; then
echo "Cloning the realm-core repository..."
git clone https://github.com/realm/realm-core.git "$REALM_CORE_DIR"
cd "$REALM_CORE_DIR" || exit
else
cd "$REALM_CORE_DIR" || exit
fi
# Reset the branch before checking out the specific commit and applying patch
git reset --hard HEAD
git checkout "$REALM_CORE_COMMIT"
git submodule update --init --recursive
else
PATCH_FILE="realm-${REALM_CORE_VERSION}.patch"
if [ ! -d "$REALM_CORE_DIR" ]; then
echo "Downloading realm-core..."
curl -L -O "$REALM_URL"
echo "Extracting realm-core..."
tar -xvf "$REALM_TAR"

EXTRACTED_REALM_DIR=$(tar -tzf "$REALM_TAR" | head -1 | cut -f1 -d"/")
if [ -d "$EXTRACTED_REALM_DIR" ]; then
mv "$EXTRACTED_REALM_DIR" "$REALM_CORE_DIR"
else
echo "Error: Failed to extract or find the realm-core directory."
exit 1
fi

cd "$REALM_CORE_DIR" || exit
else
cd "$REALM_CORE_DIR" || exit
fi
fi

# Step 5: Apply patch if patch file exists for realm-core
if [ -f "$PATCH_FILE" ]; then
echo "Applying patch to realm-core..."
git apply "$PATCH_FILE"
fi

# Step 6: Build realm-core
if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi

if [ "$USE_SYSTEM_INSTALL" = true ]; then
echo "Configuring realm-core to use system-wide wolfSSL installation..."
cmake -B "$BUILD_DIR" -DREALM_ENABLE_ENCRYPTION=1 -DREALM_ENABLE_SYNC=1 -DREALM_USE_WOLFSSL=1 -DREALM_WOLFSSL_ROOT_DIR=/usr/local/lib
else
echo "Configuring realm-core to use local wolfSSL installation from $WOLFSSL_INSTALL_DIR..."
cmake -B "$BUILD_DIR" -DREALM_ENABLE_ENCRYPTION=1 -DREALM_ENABLE_SYNC=1 -DREALM_USE_WOLFSSL=1 -DREALM_WOLFSSL_ROOT_DIR="$WOLFSSL_INSTALL_DIR"
fi

echo "Building realm-core..."
cmake --build "$BUILD_DIR"

# Step 7: Run the tests
if [ -f "$TEST_EXECUTABLE" ]; then
echo "Running the test: $TEST_EXECUTABLE"
"$TEST_EXECUTABLE"
else
echo "Test executable not found. Make sure the build was successful."
fi
Loading