Skip to content

crypto: support runtime backend configuration - #357

Open
kssim wants to merge 5 commits into
eclipse-score:mainfrom
autocrypt-dot-io:feat/issue-149-runtime-backend-config
Open

kssim wants to merge 5 commits into
eclipse-score:mainfrom
autocrypt-dot-io:feat/issue-149-runtime-backend-config

Conversation

@kssim

@kssim kssim commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add runtime backend configuration references to the common Crypto daemon configuration.
  • Add a versioned, backend-owned PKCS#11 FlatBuffer schema.
  • Parse and validate PKCS#11 token, provider, PIN, and cleanup settings during daemon startup.
  • Resolve relative backend configuration paths from the main configuration directory.
  • Pass the parsed configuration to the PKCS#11 provider factory.
  • Add unit tests, integration test vectors, and architecture documentation.

Backend configuration is loaded once at startup. Existing defaults are retained when no PKCS#11 configuration is referenced, while explicitly configured invalid files cause startup parsing to fail.

Closes #149

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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.8.2) and connecting to it...
INFO: Invocation ID: 2b100376-4507-486a-943c-5a1e2f361379
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 1 packages loaded
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
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/crypto/crypto/BUILD
ERROR: no such target '//:license-check': target 'license-check' not declared in package '' defined by /home/runner/work/crypto/crypto/BUILD
INFO: Elapsed time: 14.381s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Documentation preview for this pull request is available at:
pr-357: https://eclipse-score.github.io/inc_security_crypto/pr-357/

@kssim kssim self-assigned this Nov 2, 2026
@kssim
kssim force-pushed the feat/issue-149-runtime-backend-config branch from 00b284e to 940e5fc Compare November 12, 2026 14:38
@kssim
kssim force-pushed the feat/issue-149-runtime-backend-config branch from 940e5fc to 0869885 Compare November 12, 2026 18:44
@kssim
kssim force-pushed the feat/issue-149-runtime-backend-config branch from 0869885 to 63da2e0 Compare November 17, 2026 14:16
@kssim
kssim force-pushed the feat/issue-149-runtime-backend-config branch from 63da2e0 to 6aceb37 Compare November 17, 2026 15:47
@kssim
kssim force-pushed the feat/issue-149-runtime-backend-config branch from 6aceb37 to 21a4fed Compare November 23, 2026 15:44
@GuruprasadBhatL
GuruprasadBhatL requested a lite review from Copilot and removed request for abdullahelmarghany November 27, 2026 17:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active correctness issues remain: the documentation uses the wrong ownership-transfer API, missing PKCS#11 configuration drops defaults, the provider retains an unintended PIN copy, and invalid referenced files do not enforce fail-closed startup.

4 open issues
What changed in this PR

This pull request adds startup-time runtime configuration for backend-specific settings, currently implemented for PKCS#11. The common Crypto configuration references versioned backend-owned FlatBuffers, which are resolved relative to the main configuration file and securely parsed before provider creation.

Changes:

  • Adds provider-neutral backend configuration references and relative-path resolution.
  • Adds versioned PKCS#11 schema, validation, parsing, secure file loading, and PIN handling.
  • Updates provider-factory wiring, integration fixtures, tests, build targets, and architecture documentation.
File Description
score/​tests/​test_vectors/​config/​integration_test_config.json References the runtime PKCS#11 configuration and updates provider names.
score/​tests/​test_vectors/​config/​integration_pkcs11_config.json Defines the PKCS#11 integration token configuration.
score/​tests/​test_vectors/​config/​BUILD Builds and packages the versioned PKCS#11 configuration vector.
score/​tests/​bazel/​integration.bzl Packages integration configuration files with owner-only permissions.
score/​crypto/​src/​daemon/​provider/​tests/​provider_test/​test_pkcs11_provider.cpp Tests secure PIN transfer during provider construction.
score/​crypto/​src/​daemon/​provider/​tests/​provider_test/​test_pkcs11_multi_token.cpp Updates multi-token provider construction for consumed configuration objects.
score/​crypto/​src/​daemon/​provider/​src/​provider_manager_factory.cpp Resolves backend references and passes parsed PKCS#11 configuration to the provider factory.
score/​crypto/​src/​daemon/​provider/​pkcs11/​src/​pkcs11_token_config.cpp Implements PKCS#11 configuration ownership transfer and PIN cleanup.
score/​crypto/​src/​daemon/​provider/​pkcs11/​src/​pkcs11_provider.cpp Updates provider construction to consume configuration and handle PIN cleanup.
score/​crypto/​src/​daemon/​provider/​pkcs11/​src/​pkcs11_provider_factory.cpp Converts parsed token entries into providers and registers them with configured provider types.
score/​crypto/​src/​daemon/​provider/​pkcs11/​src/​pkcs11_module.cpp Adds secure PIN ownership and cleanup to token authentication guards.
score/​crypto/​src/​daemon/​provider/​pkcs11/​pkcs11_token_config.hpp Defines the PKCS#11 backend identifier and transferable configuration API.
score/​crypto/​src/​daemon/​provider/​pkcs11/​pkcs11_provider.hpp Updates provider constructors to consume configuration objects.
score/​crypto/​src/​daemon/​provider/​pkcs11/​pkcs11_provider_factory.hpp Updates factory ownership and registration result documentation.
score/​crypto/​src/​daemon/​provider/​pkcs11/​pkcs11_module.hpp Documents token authentication guard PIN ownership and lifetime.
score/​crypto/​src/​daemon/​provider/​pkcs11/​BUILD Adds secure-memory dependencies for PKCS#11 targets.
score/​crypto/​src/​daemon/​config/​src/​flatbuffer_config_parser.hpp Declares parsing for provider-neutral backend configuration references.
score/​crypto/​src/​daemon/​config/​src/​flatbuffer_config_parser.cpp Parses and validates common backend configuration references.
score/​crypto/​src/​daemon/​config/​src/​config.cpp Resolves backend paths relative to the main configuration file and integrates backend parsing.
score/​crypto/​src/​daemon/​config/​src/​backend_config_test.cpp Tests backend-reference parsing, validation, and path normalization.
score/​crypto/​src/​daemon/​config/​inc/​config.hpp Adds the provider-neutral backend configuration catalog.
score/​crypto/​src/​daemon/​config/​crypto_config.fbs Extends the common configuration schema with backend references.
score/​crypto/​src/​daemon/​config/​BUILD Adds generated schema and backend configuration test targets.
score/​crypto/​src/​daemon/​common/​storage/​owner_only_file_io_test.cpp Tests secure owner-only configuration file loading.
score/​crypto/​src/​daemon/​common/​storage/​file_io.hpp Declares secure owner-only file reading.
score/​crypto/​src/​daemon/​common/​storage/​file_io.cpp Implements descriptor-based secure file validation and reading.
score/​crypto/​src/​daemon/​common/​storage/​BUILD Adds the owner-only file I/O test target.
score/​crypto/​src/​daemon/​common/​secure_memory.hpp Adds secure string and scoped byte-buffer zeroization helpers.
score/​crypto/​src/​common/​flatbuffer_config_utils.hpp Provides shared FlatBuffers text validation utilities.
score/​crypto/​src/​common/​BUILD Builds the shared FlatBuffers configuration utility library.
score/​crypto/​src/​backend/​README.md Documents runtime backend configuration and PKCS#11 security requirements.
score/​crypto/​src/​backend/​pkcs11/​pkcs11_token_config_parser.cpp Reads, versions, validates, and securely parses PKCS#11 configuration files.
score/​crypto/​src/​backend/​pkcs11/​pkcs11_token_config_parser_test.cpp Tests PKCS#11 schema handling, semantic validation, permissions, and failure behavior.
score/​crypto/​src/​backend/​pkcs11/​pkcs11_config.fbs Defines the versioned backend-owned PKCS#11 schema.
score/​crypto/​src/​backend/​pkcs11/​BUILD Generates PKCS#11 schema artifacts and builds parser tests.
score/​crypto/​docs/​architecture/​provider_architecture.rst Documents backend-owned runtime configuration flow and PKCS#11 parsing.
score/​crypto/​docs/​architecture/​provider_architecture.puml Updates the provider architecture diagram with backend configuration components.
score/​crypto/​docs/​architecture/​key_management_class_diagram.puml Updates PKCS#11 configuration and factory interfaces in the class diagram.
score/​crypto/​docs/​architecture/​index.rst Documents configured provider types and factory registration behavior.
score/​crypto/​docs/​architecture/​component_overview.puml Updates the component overview for runtime PKCS#11 configuration and factory interfaces.

Review effort: Lite

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.

Need an issue to bring improvements in this fbs.

  1. To perform json schema validation before flatbuffer bin file generation.
  2. To generate checks in json schema using comments in fbs, refer, Crypto configuration concept , extend crypto configuration schema and add JSON validation before serialization #483
  3. We may add a TODO and may create an issue.

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.

Created a separate issue.
#485

Comment thread score/crypto/src/backend/README.md Resolved
/// @return Byte vector on success; kResourceNotAllocated if the path is absent,
/// kAccessDenied for an insecure or inaccessible file, kInvalidArgument
/// if path/size is invalid, or kInternalError for another I/O failure.
[[nodiscard]] score::crypto::Expected<std::vector<std::uint8_t>, DaemonErrorCode> ReadOwnerOnlyFile(

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.

Do we read any file via this class / in general in score::crypto daemon side ? if not we don't need ReadFile, only ReadOwnerOnlyFile

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.

ReadFile() is still used by certificate management, key management, and the KV deployment loader. ReadOwnerOnlyFile() is the stricter variant intended for files containing sensitive backend configuration, so both functions are required.

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.

Do we have an issue to take care of exhaustive test cases for the implementation done in this scope?

Not sure how is exhaustive testing planned.

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.

The required coverage has been added or confirmed:

  • Added a test verifying that an explicitly configured invalid PKCS#11 file causes daemon startup to fail.
  • Changed Pkcs11Provider to move its configuration instead of copying it, avoiding an unnecessary PIN copy. Existing constructor tests verify that the source PIN is cleared.
  • Existing tests verify that no PKCS#11 provider is configured when no runtime configuration is referenced.

The parser tests already cover versions, malformed input, permissions, transactional failures, and PIN transfer. Broader cross-provider and real-HSM tests can be tracked separately.

// Forward declarations for FlatBuffers-generated types (key slot config)
class CryptoConfig;
class KeySlotConfig;
struct CryptoConfig;

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.

why this change ?

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.

FlatBuffers generated code declares the corresponding table type as a struct, so the forward declaration has been updated to match. This does not change any behaviour. It simply prevents mismatched declaration warnings.

# Conflicts:
#	score/crypto/src/backend/pkcs11/pkcs11_token_config_parser.cpp
#	score/crypto/src/daemon/provider/pkcs11/BUILD
#	score/crypto/src/daemon/provider/tests/provider_test/test_pkcs11_multi_token.cpp

This branch is waiting to be deployed

1 waiting deployment
workflow-approval — d5335ae0 Waiting Nov 29, 2026 by kssim via Build and Test x86_64-qnx-itf / approval #1265
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Runtime configuration parser for backend

4 participants