Repository navigation
feat(crypto): pin keys to one permitted algorithm - #352
abdullahelmarghany wants to merge 2 commits into
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
7c11511 to
cf7de3d
Compare
cf7de3d to
4d3abb2
Compare
4d3abb2 to
80cda41
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The integration suite fails in PKCS#11-only builds because capability tests unconditionally require RANDOM and asymmetric operations that the backend does not support.
3 open issues
What changed in this PR
Adds optional, daemon-enforced algorithm pins to generated and slot-loaded keys, preventing cross-algorithm reuse while preserving existing behavior for unpinned keys. The PR also introduces typed algorithm handling and provider capability discovery.
Changes:
- Carries permitted-algorithm policy through generation requests, slot configuration, validation, and key metadata.
- Migrates provider interfaces to algorithm descriptors and adds enumerator-based API selection.
- Expands tests, integration wiring, build dependencies, and architecture documentation.
This pull request requires changes.
The following issues must be addressed before approval:
- Critical · 1 vote —
score/tests/integration_tests/integration_test.py:245: Capability tests unconditionally expect RANDOM and RSA/Ed25519 support, causing failures in PKCS#11-only builds. Make expectations conditional on the software backend or restrict execution to OpenSSL configurations. - Moderate · 3 votes —
score/crypto/src/daemon/provider/pkcs11/detail/pkcs11_algorithm_info_test.cpp:26:Row()returns a reference into a temporary optional, leaving a dangling reference and undefined behavior. ReturnAlgorithmDescriptorby value. - Moderate · 3 votes —
score/crypto/src/daemon/provider/pkcs11/operations/factory/pkcs11_handler_factory.cpp:46: HASH discovery checks only static mappings, whereas handler creation also requires token mechanism support withCKF_DIGEST. Apply the same token support gate to discovery.
| File | Description |
|---|---|
score/tests/test_vectors/config/integration_test_config.json |
Adds pinned HMAC slots and resource mappings. |
score/tests/integration_tests/score_api_mac_test.cpp |
Tests typed MAC selection and unknown algorithms. |
score/tests/integration_tests/score_api_hash_test.cpp |
Tests typed hash selection and invalid enumerators. |
score/tests/integration_tests/score_api_ecdsa_test.cpp |
Tests curve mismatches and additional digest pairings. |
score/tests/integration_tests/integration_test.py |
Runs capability-discovery integration tests. |
score/tests/integration_tests/BUILD |
Builds and deploys capability-discovery tests. |
score/tests/demo/mac_multi_provider_demo.cpp |
Updates demo calls to algorithm descriptors. |
score/crypto/src/daemon/provider/tests/provider_test/test_provider.cpp |
Migrates hash tests to catalog descriptors. |
score/crypto/src/daemon/provider/tests/provider_test/test_provider_signature.cpp |
Migrates signature tests to catalog descriptors. |
score/crypto/src/daemon/provider/tests/provider_test/test_pkcs11_provider.cpp |
Migrates PKCS#11 hash tests to descriptors. |
score/crypto/src/daemon/provider/score_provider/operations/verify/src/score_verify_handler.cpp |
Derives signature size from descriptor metadata. |
score/crypto/src/daemon/provider/score_provider/operations/verify/score_verify_handler.hpp |
Stores typed verification algorithms. |
score/crypto/src/daemon/provider/score_provider/operations/sign/src/score_sign_handler.cpp |
Derives signature size from descriptor metadata. |
score/crypto/src/daemon/provider/score_provider/operations/sign/score_sign_handler.hpp |
Stores typed signing algorithms. |
score/crypto/src/daemon/provider/score_provider/operations/random/src/score_random_handler.cpp |
Accepts random-algorithm descriptors. |
score/crypto/src/daemon/provider/score_provider/operations/random/score_random_handler.hpp |
Stores typed random algorithms. |
score/crypto/src/daemon/provider/score_provider/operations/mac/src/score_mac_handler.cpp |
Accepts MAC-algorithm descriptors. |
score/crypto/src/daemon/provider/score_provider/operations/mac/score_mac_handler.hpp |
Stores typed MAC algorithms. |
score/crypto/src/daemon/provider/score_provider/operations/hash/src/score_hash_handler.cpp |
Reads digest size from catalog metadata. |
score/crypto/src/daemon/provider/score_provider/operations/hash/score_hash_handler.hpp |
Stores typed hash algorithms. |
score/crypto/src/daemon/provider/score_provider/operations/factory/src/score_handler_factory.cpp |
Routes descriptor-based handler creation. |
score/crypto/src/daemon/provider/score_provider/operations/factory/score_handler_factory.hpp |
Separates key-management creation from algorithm hooks. |
score/crypto/src/daemon/provider/score_provider/operations/cipher/src/score_cipher_handler.cpp |
Reads block and IV sizes from descriptors. |
score/crypto/src/daemon/provider/score_provider/operations/cipher/score_cipher_handler.hpp |
Stores typed cipher algorithms. |
score/crypto/src/daemon/provider/score_provider/operations/cipher/score_cipher_handler_test.cpp |
Updates descriptor-based output-size tests. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/verify/openssl_rsa_pss_verify_handler.hpp |
Updates RSA-PSS verification interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/verify/openssl_rsa_pss_verify_handler.cpp |
Uses typed RSA-PSS digest and size metadata. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/verify/openssl_ed25519_verify_handler.hpp |
Updates Ed25519 verification interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/verify/openssl_ed25519_verify_handler.cpp |
Uses typed Ed25519 support checks. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/verify/openssl_ecdsa_verify_handler.hpp |
Updates ECDSA verification interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/verify/openssl_ecdsa_verify_handler.cpp |
Uses typed digest and curve metadata. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/sign/openssl_rsa_pss_sign_handler.hpp |
Updates RSA-PSS signing interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/sign/openssl_ed25519_sign_handler.hpp |
Updates Ed25519 signing interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/sign/openssl_ed25519_sign_handler.cpp |
Uses typed Ed25519 support checks. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/sign/openssl_ecdsa_sign_handler.hpp |
Updates ECDSA signing interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/sign/openssl_ecdsa_sign_handler.cpp |
Uses typed digest and signature-buffer metadata. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/random/openssl_random_handler.hpp |
Updates RNG descriptor interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/random/openssl_random_handler.cpp |
Delegates typed RNG support checks. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/mac/openssl_hmac_handler.hpp |
Updates HMAC descriptor interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/mac/openssl_hmac_handler.cpp |
Replaces string lists with typed HMAC checks. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/hash/openssl_hash_handler.hpp |
Updates hash validation interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/hash/openssl_hash_handler.cpp |
Uses typed hash validation and EVP mapping. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/factory/openssl_handler_factory.hpp |
Declares capability queries and descriptor hooks. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/factory/openssl_handler_factory.cpp |
Implements typed creation and capability reporting. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/cipher/openssl_cipher_handler.hpp |
Updates cipher descriptor interfaces. |
score/crypto/src/daemon/provider/score_provider/openssl/operations/cipher/openssl_cipher_handler.cpp |
Uses typed cipher selection and key sizing. |
score/crypto/src/daemon/provider/score_provider/openssl/key_management/openssl_key_handler_test.cpp |
Migrates key tests to catalog descriptors. |
score/crypto/src/daemon/provider/score_provider/openssl/key_management/openssl_key_factory.hpp |
Declares typed sizing and generation support. |
score/crypto/src/daemon/provider/score_provider/openssl/detail/signature_common.hpp |
Updates signature helpers to descriptors. |
score/crypto/src/daemon/provider/score_provider/openssl/detail/signature_common.cpp |
Uses typed key-family, curve, and digest checks. |
score/crypto/src/daemon/provider/score_provider/openssl/BUILD |
Adds algorithm-catalog dependencies. |
score/crypto/src/daemon/provider/pkcs11/operations/mac/pkcs11_mac_handler.hpp |
Updates MAC descriptor interfaces. |
score/crypto/src/daemon/provider/pkcs11/operations/mac/pkcs11_mac_handler.cpp |
Uses typed mechanism and MAC-size mapping. |
score/crypto/src/daemon/provider/pkcs11/operations/key_management/pkcs11_key_management_handler.hpp |
Updates key-algorithm support interfaces. |
score/crypto/src/daemon/provider/pkcs11/operations/key_management/pkcs11_key_management_handler.cpp |
Uses typed key-management support checks. |
score/crypto/src/daemon/provider/pkcs11/operations/key_management/pkcs11_key_management_handler_test.cpp |
Uses separate key-management factory entry point. |
score/crypto/src/daemon/provider/pkcs11/operations/hash/pkcs11_hash_handler.hpp |
Updates hash descriptor interfaces. |
score/crypto/src/daemon/provider/pkcs11/operations/hash/pkcs11_hash_handler.cpp |
Uses typed mechanisms and digest sizes. |
score/crypto/src/daemon/provider/pkcs11/operations/factory/pkcs11_handler_factory.hpp |
Declares capability queries and key-management creation. |
score/crypto/src/daemon/provider/pkcs11/operations/factory/pkcs11_handler_factory.cpp |
Implements descriptor-based creation and support reporting. |
score/crypto/src/daemon/provider/pkcs11/key_management/pkcs11_key_store.hpp |
Updates key-registration descriptor interfaces. |
score/crypto/src/daemon/provider/pkcs11/key_management/pkcs11_key_store.cpp |
Registers typed key metadata. |
score/crypto/src/daemon/provider/pkcs11/key_management/pkcs11_key_slot_handler.cpp |
Resolves slot algorithms before registration. |
score/crypto/src/daemon/provider/pkcs11/key_management/pkcs11_key_factory.hpp |
Declares key-generation capability reporting. |
score/crypto/src/daemon/provider/pkcs11/key_management/pkcs11_key_factory.cpp |
Reports descriptor-based generation support. |
score/crypto/src/daemon/provider/pkcs11/detail/pkcs11_algorithm_info_test.cpp |
Tests typed mechanism and key mappings. |
score/crypto/src/daemon/provider/pkcs11/BUILD |
Adds catalog dependencies and mapping tests. |
score/crypto/src/daemon/provider/handler/i_crypto_handler_factory.hpp |
Defines typed creation and capability contracts. |
score/crypto/src/daemon/provider/handler/BUILD |
Adds algorithm-descriptor dependencies. |
score/crypto/src/daemon/provider/executors/src/key_mgmt_executor.cpp |
Validates generation pins and registers policy. |
score/crypto/src/daemon/provider/executors/key_mgmt_request_parser.hpp |
Resolves key algorithms and optional wire pins. |
score/crypto/src/daemon/provider/executors/BUILD |
Adds key-compatibility dependencies. |
score/crypto/src/daemon/mediator/src/mediator_impl.hpp |
Updates binding interfaces and discovery declarations. |
score/crypto/src/daemon/mediator/mediator_operations.hpp |
Defines algorithm resolution and discovery operations. |
score/crypto/src/daemon/mediator/context_algorithm_test.cpp |
Tests context algorithm-resolution rules. |
score/crypto/src/daemon/mediator/BUILD |
Adds catalog dependencies and resolution tests. |
score/crypto/src/daemon/key_management/slot/slot_registry.hpp |
Adds permitted algorithms to registration parameters. |
score/crypto/src/daemon/key_management/slot/file_backed_slot_handler.cpp |
Resolves algorithms before importing slot material. |
score/crypto/src/daemon/key_management/slot/config_driven_slot_catalog.cpp |
Skips unknown or incompatible slot pins. |
score/crypto/src/daemon/key_management/interfaces/key_types.hpp |
Adds typed key metadata and pin fields. |
score/crypto/src/daemon/key_management/interfaces/key_slot_config.hpp |
Adds slot-level permitted-algorithm policy. |
score/crypto/src/daemon/key_management/interfaces/i_key_factory.hpp |
Defines key-generation capability queries. |
score/crypto/src/daemon/key_management/core/key_management_service.cpp |
Preserves pins during loading and metadata lookup. |
score/crypto/src/daemon/key_management/core/key_entry.hpp |
Stores daemon-owned permitted-algorithm policy. |
score/crypto/src/daemon/key_management/BUILD |
Adds compatibility-validation dependencies. |
score/crypto/src/daemon/config/src/flatbuffer_config_parser.cpp |
Parses optional slot algorithm pins. |
score/crypto/src/daemon/config/inc/config.hpp |
Adds configured slot pins. |
score/crypto/src/daemon/config/crypto_config.fbs |
Extends slot schema with optional pins. |
score/crypto/src/daemon/common/key_compatibility.hpp |
Defines key-fit and exact-pin checks. |
score/crypto/src/daemon/common/BUILD |
Adds compatibility utilities and test targets. |
score/crypto/src/daemon/common/algorithm_info_test.cpp |
Tests descriptor-derived algorithm properties. |
score/crypto/src/api/types/BUILD |
Exposes algorithm catalog and tests. |
score/crypto/src/api/i_crypto_context.hpp |
Clarifies names and default-RNG query behavior. |
score/crypto/src/api/future/config/csr_generation_context_config.hpp |
Adds enumerator-based algorithm selection. |
score/crypto/src/api/future/config/aead_context_config.hpp |
Adds enumerator-based algorithm selection. |
score/crypto/src/api/contexts/src/key_management_context_impl.cpp |
Validates names and serializes generation pins. |
score/crypto/src/api/contexts/BUILD |
Adds client-side algorithm-check dependencies. |
score/crypto/src/api/config/verify_signature_context_config.hpp |
Adds typed selection and updates examples. |
score/crypto/src/api/config/sign_context_config.hpp |
Adds typed selection and updates examples. |
score/crypto/src/api/config/random_context_config.hpp |
Adds typed RNG selection. |
score/crypto/src/api/config/mac_context_config.hpp |
Adds typed MAC selection and corrects examples. |
score/crypto/src/api/config/key_operation_params.hpp |
Adds generation pins and typed key selection. |
score/crypto/src/api/config/hash_context_config.hpp |
Adds typed hash selection. |
score/crypto/src/api/config/cipher_context_config.hpp |
Adds typed cipher selection. |
score/crypto/src/api/config/BUILD |
Adds selection helpers and test targets. |
score/crypto/src/api/config/base_context_config.hpp |
Implements shared enumerator selection. |
score/crypto/src/api/config/algorithm_selection.hpp |
Converts enumerators to wire names. |
score/crypto/src/api/config/algorithm_selection_test.cpp |
Tests overloads, names, and unknown values. |
score/crypto/src/api/common/src/algorithm_check.hpp |
Adds pre-IPC catalog validation. |
score/crypto/src/api/common/BUILD |
Exposes internal algorithm-check helpers. |
score/crypto/src/api/BUILD |
Wires validation and implementation dependencies. |
score/crypto/docs/architecture/provider_architecture.puml |
Updates factory interface diagrams. |
score/crypto/docs/architecture/key_management_sequence_diagrams.puml |
Shows descriptor-based handler creation. |
score/crypto/docs/architecture/key_management_class_diagram.puml |
Updates MAC algorithm types. |
score/crypto/docs/architecture/key_management_architecture.rst |
Documents descriptor handling and slot pins. |
score/crypto/docs/architecture/interfaces.rst |
Documents compile-time output-size helpers. |
score/crypto/docs/architecture/design_decisions.rst |
Records structured algorithm-catalog design. |
score/crypto/docs/architecture/api_description.rst |
Documents discovery, algorithm selection, and pin policy. |
Review effort: Balanced
|
Documentation preview for this pull request is available at: |
80cda41 to
5f93b51
Compare
5f93b51 to
69c5389
Compare
69c5389 to
ccd817b
Compare
ccd817b to
3653daa
Compare
3653daa to
68d1e29
Compare
68d1e29 to
d1b5aee
Compare
GetProviderInfo() and both QueryCapabilities() overloads of
ICryptoContext returned kUnsupportedOperation ("not yet implemented"),
and ResolveResource(name, kProvider) failed with kUnsupportedOperation
because the daemon registered a resolver only for kKeySlot. Implement
all of them.
The mediator gains PROVIDER_INFO, QUERY_CAPABILITIES and
SYSTEM_CAPABILITIES. Capabilities come from new IsAlgorithmSupported()
and IsKeyGenerationSupported() hooks on the handler and key factories.
Both take the resolved AlgorithmDescriptor and reuse the decisions
context creation and key generation already apply: the handler
factories forward to the handlers' static IsAlgorithmSupported(), and
the OpenSSL key factory runs the same key-type switch as GenerateKey().
The PKCS#11 factories also ask the selected token for the mechanism
(CKF_DIGEST for hash, CKF_SIGN|CKF_VERIFY for HMAC, CKF_GENERATE for
key generation), so a row is not reported when the token lacks it.
QUERY_CAPABILITIES resolves the name to its catalog row first; a name
the catalog does not know is reported with no operations. An empty
name reports CTR-DRBG, the generator a RANDOM context gets when it is
created without an algorithm.
SYSTEM_CAPABILITIES walks kAlgorithmCatalog and passes each row, so
every ECDSA curve/hash pairing is listed as its own algorithm. Each
algorithm goes on the wire by its catalog name, so the client needs no
copy of the catalog to read the answer.
The answer is the union over the initialized providers; each supported
operation is reported as a mode string (HASH, MAC, CIPHER, SIGN,
VERIFY, RANDOM, GENERATE_KEY).
A new score_api_capabilities_test covers both backends, including the
ECDSA cross pairings. Rows only the software provider serves are
checked under SCORE_CRYPTO_SOFTWARE_BACKEND_ENABLED; a PKCS#11-only
build expects them to be reported unsupported.
Signed-off-by: Abdullah Elmarghany <abdullah.elmarghany@bmw.de>
A key labelled with a key row fits every operation of its family: an
"AES-256" key serves AES-256-CBC, AES-256-GCM and AES-256-CMAC, and an
"ECDSA-P256" key serves every ECDSA-P256 digest. Using one key in two
modes can leak what one mode relies on: key material also used for
AES-256-GCM outside the daemon (no provider serves AES-GCM today) could
be bound to an AES-256-CBC context, where one zero block under a zero
IV returns the GCM hash subkey.
Add an optional permitted algorithm to a key:
- GenerateKeyParams::permitted_algorithm / SetPermittedAlgorithm(),
by name, sent as an optional trailing string on KEY_GENERATE.
- "permitted_algorithm" on a key slot in the daemon configuration
(FlatBuffers schema, parser, KeyConfig, KeySlotConfig).
On the wire and in the configuration the pin stays a name. The daemon
resolves it to its catalog row once: the KEY_GENERATE parser refuses a
name without a row with kUnsupportedAlgorithm, and a slot's pin is
resolved when its key is used. KeyGenerationRequest, KeyEntry,
KeyRegistrationParams and ProviderKeyHandle carry it as
std::optional<AlgorithmDescriptor>; std::nullopt means no pin.
The pin is daemon policy. It is stored on the KeyEntry (generated or
slot-loaded keys) or the slot configuration, and PeekKeyHandle()
returns it in ProviderKeyHandle::permitted_algorithm, so providers need
no change. MediatorImpl::BindAndAuthorizeKey refuses any context whose
resolved row is not the pinned row with kIncompatibleKeyType. No pin
keeps today's behaviour.
A pin the key could never serve, or one that names a key, digest or
random generator, is refused at generation with kIncompatibleKeyType;
IsValidPermittedAlgorithm() is IsKeyCompatible() on the two rows. A key
labelled with an operation row, such as "HMAC-SHA256" or "AES-256-CBC",
already serves only that row, so the only pin it accepts is that row.
ConfigDrivenSlotCatalog::Load() skips, with an error log, a slot whose
pin is unknown or does not fit its key. The earlier rule that accepted
an unknown pin and left it to an exact name match is gone: every
context algorithm is a catalog row now, so such a pin could never
match.
Signed-off-by: Abdullah Elmarghany <abdullah.elmarghany@bmw.de>
d1b5aee to
0316b71
Compare


depends on: #346. Only the last commit belongs to this PR.
A key labelled with a key row fits every operation of its family: an
"AES-256" key serves AES-256-CBC, AES-256-GCM and AES-256-CMAC, and an
"ECDSA-P256" key serves every ECDSA-P256 digest. Using one key in two
modes can leak what one mode relies on: key material also used for
AES-256-GCM outside the daemon (no provider serves AES-GCM today) could
be bound to an AES-256-CBC context, where one zero block under a zero
IV returns the GCM hash subkey.
Add an optional permitted algorithm to a key:
by name, sent as an optional trailing string on KEY_GENERATE.
(FlatBuffers schema, parser, KeyConfig, KeySlotConfig).
The pin stays a name on the wire and in the configuration; the daemon
resolves it to its catalog row once and refuses an unknown name with
kUnsupportedAlgorithm.
The pin is daemon policy. It is stored on the KeyEntry (generated or
slot-loaded keys) or the slot configuration, and PeekKeyHandle()
returns it in ProviderKeyHandle::permitted_algorithm, so providers need
no change. MediatorImpl::BindAndAuthorizeKey refuses any context whose
resolved row is not the pinned row with kIncompatibleKeyType. No pin
keeps today's behaviour.
A pin the key could never serve, or one that names a key, digest or
random generator, is refused at generation with kIncompatibleKeyType,
and such a slot is skipped at load. A key labelled with an operation
row, such as "HMAC-SHA256" or "AES-256-CBC", already serves only that
row (#345), so the only pin it accepts is that row.