Skip to content
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
128 changes: 46 additions & 82 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,17 @@ on:
push:
branches:
- main
tags: ['*']
pull_request:

jobs:
linux_botan:
name: Linux with Botan
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Prepare
run: |
sudo apt-get update -qq
sudo apt-get install -y libcppunit-dev libbotan-2-dev p11-kit
- name: Build
env:
CXXFLAGS: -Werror -DBOTAN_NO_DEPRECATED_WARNINGS
run: |
./autogen.sh
./configure --with-crypto-backend=botan
make
- name: Test
run: |
make check || (find . -name test-suite.log -exec cat {} \; && false)

linux_ossl_1:
name: Linux with OpenSSL 1.1.1
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Prepare
run: |
sudo apt-get update -qq
sudo apt-get install -y libcppunit-dev p11-kit
# Replace installed OpenSSL with the supported version 1.1.1
curl -O http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.24_amd64.deb
curl -O http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl-dev_1.1.1f-1ubuntu2.24_amd64.deb
curl -O http://security.ubuntu.com/ubuntu/pool/main/o/openssl/openssl_1.1.1f-1ubuntu2.24_amd64.deb
sudo dpkg -i --force-confnew openssl_1.1.1f-1ubuntu2.24_amd64.deb \
libssl1.1_1.1.1f-1ubuntu2.24_amd64.deb \
libssl-dev_1.1.1f-1ubuntu2.24_amd64.deb
- name: Build
env:
CXXFLAGS: -Werror
run: |
./autogen.sh
./configure --with-crypto-backend=openssl
make
- name: Test
run: |
make check || (find . -name test-suite.log -exec cat {} \; && false)

linux_ossl_30:
name: Linux with OpenSSL 3.0
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, ubuntu-24.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Prepare
Expand All @@ -68,39 +26,21 @@ jobs:
# env:
# CXXFLAGS: -Werror
run: |
sudo chmod +x autogen.sh
./autogen.sh
./configure --with-crypto-backend=openssl
make
- name: Test
run: |
make check || (find . -name test-suite.log -exec cat {} \; && false)

macos:
name: macOS (${{ matrix.backend }})
runs-on: macos-14
strategy:
fail-fast: false
matrix:
include:
- backend: openssl
extra-options: --with-openssl=$(brew --prefix openssl@1.1)
- backend: botan
extra-options: --with-botan=$(brew --prefix botan@2)
steps:
- uses: actions/checkout@v4
- name: Prepare
- name: Prepare release
run: |
brew install automake libtool cppunit botan@2
- name: Build
env:
CXXFLAGS: -Werror -DBOTAN_NO_DEPRECATED_WARNINGS
run: |
./autogen.sh
./configure --with-crypto-backend=${{ matrix.backend }} ${{ matrix.extra-options }}
make
- name: Test
run: |
make check || (find . -name test-suite.log -exec cat {} \; && false)
tar -cvzf libsofthsm2-${{ matrix.os }}.tgz -C src/lib/.libs libsofthsm2.so
- name: Stage Artifact
uses: actions/upload-artifact@v4
with:
name: binaries-linux-${{ matrix.os }}
path: libsofthsm2-${{ matrix.os }}.tgz

windows:
name: Windows (${{ matrix.arch }}, ${{ matrix.backend }})
Expand All @@ -113,14 +53,6 @@ jobs:
backend: openssl
target-platform: x64
build-options:
- arch: x64
backend: botan
target-platform: x64
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
- arch: x86
backend: openssl
target-platform: Win32
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
Expand Down Expand Up @@ -148,3 +80,35 @@ jobs:
CTEST_OUTPUT_ON_FAILURE: 1
run: |
cmake --build build --target RUN_TESTS
- name: Prepare release
run: |
tar -cvzf libsofthsm2-win-${{ matrix.arch }}-${{ matrix.backend }}.tgz -C build/src/lib/Debug *.dll
- name: Stage Artifact
uses: actions/upload-artifact@v4
with:
name: binaries-windows-${{ matrix.arch }}-${{ matrix.backend }}
path: libsofthsm2-win-${{ matrix.arch }}-${{ matrix.backend }}.tgz

release:
needs: [linux_ossl_30, windows]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: binaries-*
path: dist
merge-multiple: true # Flattens all 'binaries-*' into the 'dist' folder

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}
name: Release ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} for ${{ matrix.os }}
draft: false
prerelease: ${{ github.event_name == 'pull_request' }} # Mark as prerelease if from a PR
fail_on_unmatched_files: true
files: dist/*
generate_release_notes: true
2 changes: 1 addition & 1 deletion src/lib/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/* #define SOFTHSM_LOG_FUNCTION_NAME */

/* Define this symbol (either here or in the build setup) to log to stderr */
/* #define DEBUG_LOG_STDERR */
#define DEBUG_LOG_STDERR

/* Logging errors */
#ifndef _WIN32
Expand Down
68 changes: 68 additions & 0 deletions src/lib/object_store/Generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "log.h"
#include "Generation.h"

#include <mutex>
#include <chrono>
#include <stdexcept>
#include <sstream>

// Factory
Generation* Generation::create(const std::string path, int umask, bool isToken)
{
Expand Down Expand Up @@ -85,6 +90,55 @@ bool Generation::sync(File &objectFile)
return objectFile.seek(0L);
}

std::string getenv_string(const char *name, const char *defaultValue /* = NULL */)
{
#ifdef _WIN32
size_t valueSize = 0;
char buffer[256];
getenv_s(&valueSize, buffer, 256, name);
buffer[valueSize] = '\0';
const char *pPath = buffer;
#else
const char *pPath = getenv(name);
#endif
if (pPath == nullptr || pPath[0] == '\0')
{
if(defaultValue == NULL)
{
std::stringstream msg("Missing env var: ");
msg << name;
throw std::logic_error(msg.str());
}
else
{
return std::string(defaultValue);
}
}
return std::string(pPath);
}

long stringToLong(const std::string value)
{
std::istringstream str(value);
long result;
str >> result;
if (!str) {
if (result == std::numeric_limits<int>::max()) {
throw std::logic_error("Overflow!");
} else if (result == std::numeric_limits<int>::min()) {
throw std::logic_error("Underflow!");
} else {
throw std::logic_error("Some other parse error");
}
}
return result;
}

bool cacheGeneration = getenv_string("SOFTHSM2_OBJECT_GENERATION_CACHE_ENABLE", "false") == "true";
std::chrono::milliseconds cacheGenerationPeriodMs(stringToLong(getenv_string("SOFTHSM2_OBJECT_GENERATION_CACHE_PERIOD", "1000")));
std::chrono::milliseconds cacheGenerationLastUpdate(0);
std::mutex cacheGenerationMutex;

// Check if the target was updated
bool Generation::wasUpdated()
{
Expand Down Expand Up @@ -118,6 +172,15 @@ bool Generation::wasUpdated()
}
else
{
if (cacheGeneration) {
std::lock_guard<std::mutex> lock(cacheGenerationMutex);
if (cacheGenerationLastUpdate > std::chrono::milliseconds(0) &&
(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()) - cacheGenerationLastUpdate) < cacheGenerationPeriodMs)
{
return false;
}
}
File objectFile(path, umask);

if (!objectFile.isValid())
Expand All @@ -134,6 +197,11 @@ bool Generation::wasUpdated()
return true;
}

if (cacheGeneration) {
std::lock_guard<std::mutex> lock(cacheGenerationMutex);
cacheGenerationLastUpdate = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch());
}
return (onDisk != currentValue);
}
}
Expand Down
Loading