Skip to content
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
51 changes: 14 additions & 37 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ python.toolchain(
)

# Foreign CC rules for building projects with external build systems (make, cmake, etc.)
bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
bazel_dep(name = "rules_foreign_cc", version = "0.16.0")

# rules_foreign_cc's cmake rule does not know the QNX target OS (CMAKE_SYSTEM_NAME "QNX")
single_version_override(
module_name = "rules_foreign_cc",
patch_strip = 1,
patches = ["//third_party/soft_hsm:rules_foreign_cc_qnx.patch"],
)

# Use the host's pkg-config and m4 instead of building them from source. The bundled glib of the
# source-built pkgconfig uses the GNU 'asm' keyword and fails with a strict -std=c11 host compiler.
Expand Down Expand Up @@ -155,28 +162,12 @@ use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm")
# which activates Rust coverage without any custom toolchain instance.
bazel_dep(name = "score_toolchains_rust", version = "0.10.1", dev_dependency = True)

bazel_dep(name = "score_crates", version = "0.0.15")

crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate", isolate = True)
crate.from_cargo(
name = "crates",
cargo_lockfile = "//score/cryptoki:Cargo.lock",
manifests = ["//score/cryptoki:Cargo.toml"],
supported_platform_triples = [
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-gnu",
"aarch64-unknown-nto-qnx710",
"x86_64-pc-nto-qnx710",
],
)
crate.annotation(
crate = "openssl-sys",
patch_args = ["-p1"],
patches = ["@@//third_party/patches:openssl_sys_build_rs.patch"],
rustc_flags = ["--cap-lints=allow"],
deps = ["@@//third_party/openssl:openssl_shared"],
bazel_dep(name = "score_crates", version = "0.0.7")
git_override(
module_name = "score_crates",
commit = "871234431b05bc99b249fb5db775bbe850ed7f0d",
remote = "https://github.com/eclipse-score/score-crates.git",
Comment on lines +165 to +169

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git_override only applies when this repository is the root module; it is ignored when score_crypto is consumed as a dependency. The published score_crates v0.0.7 does not expose most of the labels used by this PR, such as argon2, dirs, once_cell, parking_lot, parsec_client, serial_test, toml, zeroize, and openssl. The latest v0.0.15 also predates score-crates PR #79. As a result, this repository’s CI passes with the override, but a downstream consumer can fail during Bazel analysis. Could we publish a new score_crates version containing #79, depend on that version, and remove the temporary override?

)
use_repo(crate, "crates")

# *******************************************************************************
# QNX IFS (Image File System) toolchain for building boot images
Expand Down Expand Up @@ -214,21 +205,7 @@ use_repo(
# OpenSSL
# *******************************************************************************

http_archive(
name = "openssl_source",
build_file_content = """
filegroup(
name = "all",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
""",
patch_args = ["-p1"],
patches = ["//third_party/openssl:openssl_qnx_target.patch"],
sha256 = "b1bfedcd5b289ff22aee87c9d600f515767ebf45f77168cb6d64f231f518a82e",
strip_prefix = "openssl-3.6.1",
urls = ["https://www.openssl.org/source/openssl-3.6.1.tar.gz"],
)
bazel_dep(name = "score_openssl", version = "0.2.1")

# *******************************************************************************
# SoftHSMv2
Expand Down
2,747 changes: 45 additions & 2,702 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions score/crypto/src/backend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ cc_library(
# --//score/crypto/src/backend:pkcs11_backend=//external/vendor_hsm:backend
label_flag(
name = "pkcs11_backend",
build_setting_default = "//third_party/soft_hsm:soft_hsm",
visibility = ["//visibility:public"],
)

# Label flag allowing command-line override of the shared PKCS#11 implementation
# when dynamic linking is enabled (--@score_openssl//:use_dynamic_openssl=true).
# Default is SoftHSM's shared library target.
label_flag(
name = "pkcs11_shared_backend",
build_setting_default = "//third_party/soft_hsm:softhsm_shared",
visibility = ["//visibility:public"],
)
Expand Down
34 changes: 33 additions & 1 deletion score/crypto/src/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ via a `label_flag`:
# backend/BUILD
label_flag(
name = "pkcs11_backend",
build_setting_default = "//third_party/soft_hsm:softhsm_shared",
build_setting_default = "//third_party/soft_hsm:soft_hsm",
)
```

Expand All @@ -102,6 +102,38 @@ bazel build //score/crypto/src/daemon:crypto_daemon \
Config parsing (`Pkcs11Config::ParseConfig`) lives in `backend/pkcs11/` and is
independent of the selected library.

## Static vs. Dynamic Linking Behavior

By default (per S-CORE DR-002), all cryptographic backends and dependencies are linked **statically** into the binaries:
- OpenSSL static archives (`libcrypto.a`, `libssl.a`) are linked directly into the binary.
- SoftHSM compiles as a static archive (`libsofthsm2-static.a`) and is linked statically into `crypto_daemon`.

### How to Test Statically (Default)

```bash
bazel test //score/...
```

### How to Test Dynamically (Opt-In)

Dynamic shared library linking (`.so`) across OpenSSL and SoftHSM can be enabled via:

```bash
bazel test //score/... --@score_openssl//:use_dynamic_openssl=true
```

When this flag is active:
1. `@score_openssl//:openssl_shared` builds and exposes `libopenssl.so`.
2. `//third_party/soft_hsm:softhsm_shared` builds `libsofthsm2.so` via `cc_shared_library` with `dynamic_deps` referencing `openssl_shared`.
3. `crypto_daemon` activates `dynamic_deps` for both `openssl_shared` and `softhsm_shared`, resolving both libraries at runtime.

### Current Behavior & Transitive Dependency Invariants

Currently, the dynamic build of SoftHSM (PKCS#11 backend) is coupled to `--@score_openssl//:use_dynamic_openssl=true`.

* **Transitive Dependency Rule:** If a PKCS#11 backend (SoftHSM or Cryptoki) is dynamically linked, OpenSSL **must also be dynamically linked**. Otherwise, `crypto_daemon` would link static OpenSSL code directly while SoftHSM/Cryptoki dynamically loads another instance of OpenSSL, leading to duplicate static symbols and runtime memory collision.
* **Follow-Up Scope:** In an upcoming story, this coupling will be decoupled so that dynamic OpenSSL does not automatically force SoftHSM to be dynamic.

## Requirements for the PKCS#11 Library

The selected PKCS#11 library must successfully initialize when `C_Initialize`
Expand Down
7 changes: 7 additions & 0 deletions score/crypto/src/daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ cc_binary(
"-O1",
],
}),
dynamic_deps = select({
"@score_openssl//:dynamic_openssl_enabled": [
"@score_openssl//:openssl_shared",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need a combinaton of select switches?

  • Dynamic openssl enabled
    • openssl backend enabled -> add openssl_shared
    • pkcs11 enabled -> add pkcs11_shared_backend

@ShoroukRamzy ShoroukRamzy Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OliverHeilwagen, please note this PR is stacked on top of this PR #317 and previously we planned to open dedicated PR for this issue #317 (comment). and #348

The actual scope of this PR is only this commit 2c63e01.

So to keep PR scopes clean and maintain the release timeline I propose the following plan:
1-first PR to merge #317
2.second PR, this one.
3. I will create another PR (stacked on the first PR) to fix the current coupling issue between openssl and pkcs11
Both PR 2,3 depend on PR1 and I suggest to merge PR2 first to unblock the first release. What do you think?

"//score/crypto/src/backend:pkcs11_shared_backend",
],
"//conditions:default": [],
}),
includes = ["IPC"],
linkopts = select({
"//conditions:default": [],
Expand Down
12 changes: 6 additions & 6 deletions score/crypto/src/daemon/provider/score_provider/openssl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cc_library(
visibility = ["//score/crypto/src/daemon/provider:__subpackages__"],
deps = [
"//score/crypto/src/api/types:certificate_types",
"//third_party/openssl:openssl_shared",
"@score_openssl//:openssl",
],
)

Expand All @@ -90,7 +90,7 @@ cc_library(
srcs = ["cert_management/openssl_cert_parser.cpp"],
implementation_deps = [
":openssl_cert_utils",
"//third_party/openssl:openssl_shared",
"@score_openssl//:openssl",
],
target_compatible_with = select({
"//score/crypto/src/backend:openssl_backend_active": [],
Expand All @@ -117,7 +117,7 @@ cc_test(
":openssl_cert_management_headers",
":openssl_cert_parser_library",
"//score/crypto/src/daemon/cert_management:cert_management_headers",
"//third_party/openssl:openssl_shared",
"@score_openssl//:openssl",
"@googletest//:gtest_main",
],
)
Expand All @@ -126,7 +126,7 @@ cc_test(
cc_library(
name = "openssl_detail_headers",
hdrs = ["detail/openssl_algorithm_info.hpp"],
implementation_deps = ["//third_party/openssl:openssl_shared"],
implementation_deps = ["@score_openssl//:openssl"],
target_compatible_with = select({
"//score/crypto/src/backend:openssl_backend_active": [],
"//conditions:default": ["@platforms//:incompatible"],
Expand Down Expand Up @@ -205,7 +205,7 @@ cc_library(
"provider_openssl.cpp",
],
implementation_deps = [
"//third_party/openssl:openssl_shared",
"@score_openssl//:openssl",
],
includes = ["."],
linkstatic = True,
Expand Down Expand Up @@ -245,7 +245,7 @@ cc_test(
":provider_openssl_library",
"//score/crypto/src/daemon/common:algorithm_catalog",
"//score/crypto/src/daemon/common:algorithm_info",
"//third_party/openssl:openssl_shared",
"@score_openssl//:openssl",
"@googletest//:gtest_main",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cc_test(
"//score/crypto/src/daemon/provider/handler:hash_handler_operations",
"//score/crypto/src/daemon/provider/score_provider/openssl:provider_openssl_library",
"//score/tests/utility",
"//third_party/openssl:openssl_shared",
"@score_openssl//:openssl",
"@googletest//:gtest",
],
)
Expand Down
10 changes: 7 additions & 3 deletions score/crypto/src/ipc/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ integration_test(
configs = ["//score/tests/config:logging.json"],
data = ["conftest.py"],
libraries = [
"//third_party/soft_hsm:softhsm_so",
"//score/crypto/src/backend:pkcs11_shared_backend",
"//score/crypto/src/api/control_plane:control_plane_hdr",
"//third_party/openssl:openssl_so",
],
] + select({
"@score_openssl//:dynamic_openssl_enabled": [
"@score_openssl//:openssl_shared",
],
"//conditions:default": [],
}),
deps = [
"//score/tests:common_fixtures",
"//score/tests/utility/process_runner",
Expand Down
2 changes: 1 addition & 1 deletion score/crypto/tests/openssl/block_cipher/ECB-AES128/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cc_test(
],
deps = [
"//score/tests/utility",
"//third_party/openssl:openssl_shared",
"@score_openssl//:openssl",
"@googletest//:gtest",
],
)
2 changes: 1 addition & 1 deletion score/crypto/tests/softhsm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cc_library(
includes = ["."],
visibility = ["//:__subpackages__"],
deps = [
"//third_party/soft_hsm:softhsm_shared",
"//third_party/soft_hsm:soft_hsm",
"@googletest//:gtest",
],
)
2 changes: 1 addition & 1 deletion score/crypto/tests/softhsm/block_cipher/ECB-AES128/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cc_test(
linkstatic = True,
deps = [
"//score/tests/utility",
"//third_party/soft_hsm:softhsm_shared",
"//third_party/soft_hsm:soft_hsm",
"@googletest//:gtest",
],
)
21 changes: 9 additions & 12 deletions score/cryptoki/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,20 @@ filegroup(

DEPS = [
# --- Company Approved (Score Ecosystem) ---
"@score_crates//:argon2",
"@score_crates//:dirs",
"@score_crates//:libc",
"@score_crates//:once_cell",
"@score_crates//:openssl",
"@score_crates//:parking_lot",
"@score_crates//:parsec_client",
"@score_crates//:serde",
"@score_crates//:serde_json",
"@score_crates//:tempfile",
"@score_crates//:toml",
"@score_crates//:zeroize",
"@score_baselibs//score/log_rust/score_log",
"@score_logging//score/mw/log/rust/score_log_bridge",

# --- Community Fallback (Crate Universe) ---
"@crates//:argon2",
"@crates//:dirs",
"@crates//:once_cell",
"@crates//:parking_lot",
"@crates//:parsec-client",
"@crates//:tempfile",
"@crates//:toml",
"@crates//:zeroize",
"@crates//:openssl",
"//third_party/openssl:openssl_shared",
]

# Shared C/C++ linker flags required by score_log_bridge
Expand Down
Loading
Loading