Skip to content

Cryptoki etas integration - #49

Open
oeweda wants to merge 27 commits into
eclipse-score:mainfrom
Valeo-S-CORE-Organization:cryptoki_etas_integration
Open

Cryptoki etas integration#49
oeweda wants to merge 27 commits into
eclipse-score:mainfrom
Valeo-S-CORE-Organization:cryptoki_etas_integration

Conversation

@oeweda

@oeweda oeweda commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Key Changes:

Your Reviews will be appreciated @ChansAlive @PandaeDo @masc2023 @schreibwsag @OliverHeilwagen

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run --lockfile_mode=error //:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.3.0) and connecting to it...
INFO: Invocation ID: 794879c8-9898-4b5b-8115-dfbfdedf7e57
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
DEBUG: Rule 'abseil-cpp+' indicated that a canonical reproducible form can be obtained by modifying arguments integrity = "sha256-m3oGQwXp/ZTRJP+mzDWFkutCtdpYj7TgfQklSqQAhts="
DEBUG: Repository abseil-cpp+ instantiated at:
  <builtin>: in <toplevel>
Repository rule http_archive defined at:
  /home/runner/.bazel/external/bazel_tools/tools/build_defs/repo/http.bzl:394:31: in <toplevel>
DEBUG: Rule 'protobuf+' indicated that a canonical reproducible form can be obtained by modifying arguments integrity = "sha256-w6Cp7OiTLjHDtzbi2xixxC5wcM2biBOIsm0BqnHiTKI="
DEBUG: Repository protobuf+ instantiated at:
  <builtin>: in <toplevel>
Repository rule http_archive defined at:
  /home/runner/.bazel/external/bazel_tools/tools/build_defs/repo/http.bzl:394:31: in <toplevel>
Computing main repo mapping: 
DEBUG: Rule 'grpc+' indicated that a canonical reproducible form can be obtained by modifying arguments integrity = "sha256-CvN7gAlTEwtHwHW1ZoPuYL3D7aPDf8YAQZP1tWl1ggQ="
DEBUG: Repository grpc+ instantiated at:
  <builtin>: in <toplevel>
Repository rule http_archive defined at:
  /home/runner/.bazel/external/bazel_tools/tools/build_defs/repo/http.bzl:394:31: in <toplevel>
WARNING: For repository 'score_crates', the root module requires module version score_crates@0.0.7, but got score_crates@0.0.9 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
Computing main repo mapping: 
Loading: 
Loading: 1 packages loaded
Loading: 1 packages loaded
    currently loading: 
WARNING: Target pattern parsing failed.
ERROR: Skipping '//:license-check': no such target '//:license-check': target 'license-check' not declared in package '' defined by /home/runner/work/inc_security_crypto/inc_security_crypto/BUILD
Analyzing: 0 targets (2 packages loaded)
ERROR: no such target '//:license-check': target 'license-check' not declared in package '' defined by /home/runner/work/inc_security_crypto/inc_security_crypto/BUILD
INFO: Elapsed time: 10.394s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

Comment thread docs/crypto/architecture/index.rst
Comment thread docs/crypto/architecture/index.rst Outdated
Comment thread docs/crypto/architecture/dynamic_architecture.rst Outdated
Comment thread docs/crypto/architecture/dynamic_architecture.rst Outdated
@PandaeDo

Copy link
Copy Markdown
Contributor

80k lines. Sorry, but I'm not able to review that. Is it possible to create smaller, readable PR's?

@ChansAlive

Copy link
Copy Markdown
Contributor

Kindly check the PR again and resolve the merge conflicts.
It may then reflect the actual changes that is being brought in.
It currently shows the source code that is already present in the main as incoming changes.
Thanks

@oeweda
oeweda force-pushed the cryptoki_etas_integration branch 4 times, most recently from 4d92606 to cc51b96 Compare June 17, 2026 04:36
@schreibwsag

Copy link
Copy Markdown
Contributor

test_pkcs11_provider fails when compiled with USE_RUST_PKCS11 ("C_InitToken failed: 160").
test_pkcs11_provider tries to initialize the token which is apparently necessary for the SoftHSM2
case, but not for libcryptoki. Proposal: to get test_pkcs11_provider running, do the initialization
parts only if USE_RUST_PKCS11 is not defined. Then test_pkcs11_provider will run:

./bazel-bin/tests/provider_test/test_pkcs11_provider
[==========] Running 4 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 4 tests from Pkcs11ProviderHashTest
[ RUN ] Pkcs11ProviderHashTest.SHA256SingleShotHash
mw::log initialization error: Error No logging configuration files could be found. occurred with context information: Failed to load configuration files. Fallback to console logging.
mw::log initialization error: Error No logging configuration files could be found. occurred with context information: Failed to load configuration files. Fallback to console logging.
2026/06/18 05:17:33.9853564 2801418324 000 ECU1 NONE DFLT log warn verbose 4 [PKCS#11] Warning: token label autodetect failed for ' SoftHSM '. Falling back to first present slot id= 0
[ OK ] Pkcs11ProviderHashTest.SHA256SingleShotHash (126 ms)
[ RUN ] Pkcs11ProviderHashTest.SHA256StreamingHash
2026/06/18 05:17:33.9853692 2801419597 000 ECU1 NONE DFLT log warn verbose 4 [PKCS#11] Warning: token label autodetect failed for ' SoftHSM '. Falling back to first present slot id= 0
[ OK ] Pkcs11ProviderHashTest.SHA256StreamingHash (122 ms)
[ RUN ] Pkcs11ProviderHashTest.StreamStateViolation
2026/06/18 05:17:33.9853802 2801420698 000 ECU1 NONE DFLT log warn verbose 4 [PKCS#11] Warning: token label autodetect failed for ' SoftHSM '. Falling back to first present slot id= 0
[ OK ] Pkcs11ProviderHashTest.StreamStateViolation (110 ms)
[ RUN ] Pkcs11ProviderHashTest.TrueConcurrentStreamingOnSeparateSessions
2026/06/18 05:17:33.9853925 2801421927 000 ECU1 NONE DFLT log warn verbose 4 [PKCS#11] Warning: token label autodetect failed for ' SoftHSM '. Falling back to first present slot id= 0
[ OK ] Pkcs11ProviderHashTest.TrueConcurrentStreamingOnSeparateSessions (123 ms)
[----------] 4 tests from Pkcs11ProviderHashTest (482 ms total)

[----------] Global test environment tear-down
[==========] 4 tests from 1 test suite ran. (482 ms total)
[ PASSED ] 4 tests.

@oeweda
oeweda force-pushed the cryptoki_etas_integration branch 4 times, most recently from 4e95a25 to 0f08964 Compare June 22, 2026 09:41
@github-actions

Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

@ShoroukRamzy
ShoroukRamzy force-pushed the cryptoki_etas_integration branch 7 times, most recently from ab068a8 to 09800f7 Compare July 7, 2026 14:31
@sunildevda
sunildevda requested a review from ChansAlive July 8, 2026 08:30

@ChansAlive ChansAlive left a comment

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.

Review done on the daemon changes as part of integrating the rust pkcs11 provider

":use_rust_pkcs11": [
"//score/cryptoki:cryptoki_cdylib",
"//score/cryptoki:cryptoki_headers",
"//third_party/openssl",

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.

I believe this would any way be a transitive dependency when depending on cryptoki_cdylib right?

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.

Thanks @ChansAlive, yes you are right, Done!

Comment on lines 18 to +23

#include <cryptoki.h>
#include <pkcs11.h>
#ifdef USE_RUST_PKCS11
#include <pkcs11.h>
#else
#include <cryptoki.h>
#endif

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.

I think it was unnecessary to include the cryptoki.h header in the first place.
You may ignore this comment, I will raise a separate fix later.

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.

Changes planned in #92

Comment on lines +141 to +160
#ifdef USE_RUST_PKCS11
{
CK_ULONG slot_count{0U};
CK_FUNCTION_LIST* const fl = m_module->GetFunctionList();
CK_RV rv = fl->C_GetSlotList(CK_TRUE, nullptr, &slot_count);
if ((rv == CKR_OK) && (slot_count > 0U))
{
std::vector<CK_SLOT_ID> slots(slot_count);
rv = fl->C_GetSlotList(CK_TRUE, slots.data(), &slot_count);
if ((rv == CKR_OK) && !slots.empty())
{
m_config.slotId = slots.front();
score::mw::log::LogWarn() << "[PKCS#11] Warning: token label autodetect failed for '"
<< m_config.tokenLabel
<< "'. Falling back to first present slot id=" << m_config.slotId;
return true;
}
}
}
#endif

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.

What would be the rationale behind this callback?

The intention would be to use the correct token represented by the label (plus Model).

The overall idea of identifying the correct provider would be based on the provider name which is then mapped to the token label in the config to match with the pkcs11 token. If this is not honored, how can we ensure that we are communicating with the correct token when multiple tokens are present in the pkcs11 module?

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.

yes @ChansAlive, I agree with you. I removed this.

Comment thread score/crypto/daemon/src/daemon.cpp Outdated
Comment on lines +74 to +91
#ifdef USE_RUST_PKCS11
{
// Hack to modify slot entries since GetSlotEntries returns const
auto& slot_entries = const_cast<std::vector<score::crypto::daemon::config::KeyConfig::KeySlotEntry>&>(
config.GetKeyConfig().GetSlotEntries()
);
for (auto& slot : slot_entries)
{
for (auto& provider_name : slot.provider_names)
{
if (provider_name == "SOFTHSM")
{
provider_name = "SCORE_CRYPTO_PROVIDER";
}
}
}
}
#endif

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.

I think this is not the right way to use the keyslots for the rust pkcs11 provider. Infact there are three better alternatives

  1. Use a common provider name for both softhsm and cryptoki. You can then change the pkcs11_token_config.cpp
  2. Second option is to switch the integration_test_config.json (https://github.com/eclipse-score/inc_security_crypto/blob/main/tests/test_vectors/config/integration_test_config.json) in the BUILD file to use the modified keyslot entries.
  3. Add new keyslot entries in the existing json. Adapt the test to use the new keyslot resource identifier when rust pkcs11 is selected.

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.

Thanks @ChansAlive for your feedback, yes I agree with you. refactoring is ready now for generic provider name

}
auto& km = km_result.value();

auto slot_result = ctx->ResolveResource("HMAC_SHA256_IntegrationTestKey_SoftHSM", ResourceType::kKeySlot);

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.

Since we want to choose either softHSM or cryptoki, it may be better to rename the keyslot resourceId to have a generic name. Else it is bit confusing. The change requires updating the config json.

Comment thread third_party/patches/BUILD

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.

Are these patch files really required to be merged?

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.

Hi @ChansAlive, Yes, these patches are required to compile successfully:

  1. openssl_sys patch: Bypasses host filesystem scanning (which is blocked by Bazel's secure sandbox) to link directly to our built-in //third_party/openssl library.
  2. Other patches: Fix outdated Rust syntax and Cargo workspace README paths so S-CORE compiles cleanly on modern stable toolchains

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.

Hi @ShoroukRamzy ,
Thanks for the response.

  1. Currently, if I understand correctly, the patch hardcodes the version to 3.4 and we already are using 3.6.1, shouldn't we check which version of openssl we are using and adapt the patch to maintain consistency?
  2. Regarding the score_logging.patch, if this is some change that should ideally be present in the respective module, we should not be patching it here right? Probably if we are using a third_party exclusively used sources, it may be fine. But from the middleware perspective, considering the modules could be shared by multiple modules, how do we expect this patching to work?

Ideally we should try to reduce patches as this might cause issues in the reference integration.
cc: @OliverHeilwagen

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.

Hi @ChansAlive,

Thank you for your feedback. Regarding the first point, Let me clarify some points:

  1. OpenSSL (C++) vs openssl-sys (Rust): S-CORE compiles OpenSSL 3.6.1 (the actual C++ binary), but our Rust bindings crate openssl-sys has no 3.6.x or ossl360 flags in its source code; its highest defined 3.x flag is ossl350.

  2. Why we patch (Bazel Sandbox): The unpatched crate’s script scans host paths (like /usr/include), which is blocked inside Bazel's secure sandbox. Our patch simply bypasses this scan to prevent a compile-time crash.

  3. Backward Compatibility: If the unpatched script could scan our 3.6.1 dynamically, it would automatically fall back to ossl350. OpenSSL strictly guarantees ABI backward compatibility, making this 3.5.0 compiled subset 100% compatible and safe to run against S-CORE's compiled 3.6.1 binary at runtime.

To maintain perfect consistency, we have updated the patch to output ossl350 and version number 30500000 (3.5.0 fallback).

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.

@ShoroukRamzy,
I agree with the reason for patching the openssl-sys crate. Please check if all other patches are necessary.

The open point I have is on how to maintain consistency with openssl-sys crate patch and the openssl what we are building automatically. Else we might change (upgrade or downgrade) the openssl version without upgrading the patch.

It would be great if we have a possibility to patch with the maximum supported version of openssl (either of what is supported by crate or what we build) and throw necessary error in case of incompatibility.
Thanks.

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.

@ChansAlive,
I removed all other patches, I tested without them and they are not needed

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.

@ChansAlive, Regarding the openssl point, I fully agree with it and I updated the patch to maintain this consistency. Thanks!

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.

@ChansAlive, Regarding the openssl point, I fully agree with it and I updated the patch to maintain this consistency. Thanks!

@ChansAlive, Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@oeweda any update on the PR?

@ShoroukRamzy
ShoroukRamzy force-pushed the cryptoki_etas_integration branch from ce954fc to ad1619a Compare July 19, 2026 15:54
@ShoroukRamzy
ShoroukRamzy force-pushed the cryptoki_etas_integration branch from ad1619a to d029311 Compare July 19, 2026 16:05
@ShoroukRamzy
ShoroukRamzy force-pushed the cryptoki_etas_integration branch from d029311 to 7918321 Compare July 19, 2026 16:10
@ShoroukRamzy
ShoroukRamzy force-pushed the cryptoki_etas_integration branch from 7918321 to 23a7102 Compare July 19, 2026 16:21
Refactor the openssl_sys_build_rs.patch build script to dynamically parse the compiled OpenSSL version number from S-CORE's opensslv.h header inside the sandboxed build environment.
@ShoroukRamzy
ShoroukRamzy force-pushed the cryptoki_etas_integration branch from 95cc948 to 8e1dc3d Compare July 20, 2026 12:21
Update openssl_sys_build_rs.patch to emit the ossl350 configuration flags and version number 30500000. This provides the correct backward-compatible fallback configuration for S-CORE's compiled OpenSSL 3.6.1.
+ println!("cargo:rustc-cfg=openssl");
+
+ // 1. Declare S-CORE's compiled OpenSSL version and the highest supported crate version
+ const S_CORE_OPENSSL_VERSION: &str = "3.6.1";

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.

@ShoroukRamzy Please create a follow up work item, to explore how we can keep this in sync with the actual used openssl version.

Later it should be possible that reference_integration is able to overwrite the openssl version, doing the manual sync will then only be valid in the security_crypto module scope.

Comment thread MODULE.bazel
# *******************************************************************************
git_override(
module_name = "rules_rust",
commit = "2b171a7376e69cb1207eced1f66904ce4ae0c819",

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.

What is the difference to "0.68.2-score" ?
Is this a upcomming score version?

Comment thread MODULE.bazel
# *******************************************************************************
# Valeo - Cryptoki
# *******************************************************************************
git_override(

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.

Please move the rust toolchain specific parts to section within this file.

# *******************************************************************************
# Rust toolchains
# *******************************************************************************

Comment thread MODULE.bazel

# s-core baselibs
bazel_dep(name = "score_baselibs", version = "0.2.7")
bazel_dep(name = "score_baselibs_rust", version = "0.1.2")

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.

score_baselibs_rust is deprecated and got merged into score_baselibs with version 0.2.9 please create a follow up issue to bump the version and drop the score_baselibs_rust dependency.

Comment thread BUILD
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

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.

please check if this is really needed.

Suggested change
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

Comment thread BUILD
source_dir = ".",
)

package(default_visibility = ["//visibility:public"])

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.

Please apply target specific and keep the default private, also for other BUILD files accordingly.

Comment thread .bazelrc
Comment on lines +90 to 97
# -------------------------------------------------------------------------------
# Different toolchain configuration for x86_64-qnx
# -------------------------------------------------------------------------------
build:target_config_1 --config=x86_64-qnx
build:target_config_1 --extra_toolchains=@score_qcc_x86_64_toolchain//:x86_64-qnx-sdp_8.0.0
build:target_config_1 --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_x86_64_unknown_linux_gnu
build:target_config_1 --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_x86_64_pc_nto_qnx800

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.

With the updated bazelrc from main these changes should not longer be necessary.
The build should work with --config=x86_64-qnx.

Suggested change
# -------------------------------------------------------------------------------
# Different toolchain configuration for x86_64-qnx
# -------------------------------------------------------------------------------
build:target_config_1 --config=x86_64-qnx
build:target_config_1 --extra_toolchains=@score_qcc_x86_64_toolchain//:x86_64-qnx-sdp_8.0.0
build:target_config_1 --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_x86_64_unknown_linux_gnu
build:target_config_1 --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_x86_64_pc_nto_qnx800

Comment thread .bazelrc
test:aarch64-qnx --test_lang_filters=cc,rust
test:aarch64-qnx --test_timeout=180,900,2700,10800 # Increase default test timeout by factor 3

# -------------------------------------------------------------------------------

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.

Same point as above the aarch64-qnx config should already be valid.

Comment thread .bazelignore
Comment on lines +4 to +8
# ignore Bazel's own output symlinks
bazel-inc_security_crypto
bazel-bin
bazel-out
bazel-testlogs

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.

Shouldn't this be default bazel behaviour?

Comment thread MODULE.bazel
Comment on lines +294 to +295
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate", isolate = True)
crate.from_cargo(

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.

Direct create_universe usage in modules seems invalid looking at:
https://github.com/eclipse-score/score-crates

Which raises the question how we handle the openssl dependency in future.
It seems to make more and more sense to move it into a separate repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

PKCS11 (Cryptoki) Integration with SCORE Have only one version of OpenSSL on target Integrate PKCS11 (Cryptoki) to SCORE

8 participants