Skip to content

feat(crypto): export public keys as SPKI DER/PEM - #394

Open
abdullahelmarghany wants to merge 2 commits into
eclipse-score:mainfrom
abdullahelmarghany:feat/wp3-export
Open

abdullahelmarghany wants to merge 2 commits into
eclipse-score:mainfrom
abdullahelmarghany:feat/wp3-export

Conversation

@abdullahelmarghany

@abdullahelmarghany abdullahelmarghany commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #393; only the last commit is new.

The OpenSSL key factory only exported EC public keys as a raw point.

  • EC, RSA and Ed25519 keys export their public half as SubjectPublicKeyInfo in DER or PEM, and EC also as the raw point.
  • The export format is optional: unset (kFormatNative) asks for the provider's native format, DER SPKI for public keys.
  • Private and secret key material is never exported in plaintext; it can only leave wrapped. Every refusal the client sees is kKeyNotExportable: a public key without kExport, any symmetric key, and secret keys on PKCS#11. GetExportKeySize refuses the same way.
  • ExportKey and GetExportKeySize share one encoder, so the size query always matches the exported length.

Tests: OpenSSL key handler tests (SPKI DER/PEM for every asymmetric key type matching the size query, P-256 SPKI matching OpenSSL and re-importing, raw export refused for non-EC keys, refusals without kExport and for secret keys), a PKCS#11 secret-key export refusal, and integration tests (DER round trip, PEM size-then-data, unset format gives DER SPKI, secret key export refused).

@github-actions

github-actions Bot commented Nov 10, 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: b0f7cb6c-650c-4e0d-ab13-11209efe72c5
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.863s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

@github-actions

Copy link
Copy Markdown
Contributor

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

@abdullahelmarghany
abdullahelmarghany marked this pull request as ready for review November 17, 2026 10:05
Symmetric key import accepted any byte count and ignored the requested
format. Asymmetric import accepted DER only, and every caller had to
name a format even when the key type fixes it.

ImportKeyParams::format is now std::optional<FormatType>, unset by
default. Unset means the native format of the key type: raw bytes for
AES/HMAC, and for asymmetric keys PEM (data starting with "-----BEGIN"),
an uncompressed EC point (leading 0x04, EC algorithms only) or DER.
Detection only picks the parser; curve, modulus and type checks still
apply. An explicit format stays strict. On the IPC the unset format is
sent as operations::kFormatNative (0xFFFFFFFF), with EncodeFormat /
DecodeFormat in key_management_operations.hpp; any other value outside
FormatType is rejected instead of being cast.

Symmetric imports go through a shared
IKeyFactory::ValidateSymmetricImport, which both the OpenSSL and the
PKCS#11 factory use. The format must be unset or kRaw, otherwise the
import fails with kInvalidFormat. An AES key must be exactly 16/24/32
bytes and an HMAC key at least as long as its digest, otherwise the
import fails with kIncompatibleKeyType.

The file-backed slot handler maps the deployment "key_format" property
raw/der/pem to that format, maps an absent property to the native
format, and fails the load for any other value.

The OpenSSL factory decodes one unencrypted PEM block labelled
PRIVATE KEY, EC PRIVATE KEY, RSA PRIVATE KEY or PUBLIC KEY. Encrypted
PEM, unknown labels, data around the block and a label that disagrees
with the key are rejected. PEM_FLAG_SECURE keeps the decoded body on
the secure heap, and no passphrase callback is ever invoked. PKCS#11
asymmetric import stays unsupported.

Tests:
- OpenSSL key factory unit tests for the symmetric rules, PEM import,
  native-format import for each key family, and file-backed slot
  loading with absent, raw, der, pem and unknown key_format.
- A request parser test for the format wire encoding.
- Integration tests for native and explicit AES-256 import and for PEM,
  DER and raw-point public key import with raw export.
- PEM test vectors derived from the existing NIST DER vectors.

Signed-off-by: Abdullah Elmarghany <abdullah.elmarghany@bmw.de>
The OpenSSL key factory only exported EC public keys as a raw point.

Asymmetric keys (EC, RSA, Ed25519) now export their public half as
SubjectPublicKeyInfo in DER or PEM, or for EC as the raw point. The
export format is now optional: std::nullopt (wire kFormatNative) asks
for the provider's native format, which is DER SPKI for public keys.
The export handlers parse it with ExtractOptionalFormat, so the
ExtractFormatOrDefault helper is removed.

Private and secret key material is never exported in plaintext; it can
only leave wrapped. Every client-visible refusal is
kKeyNotExportable: a public key without kExport, any symmetric
key, and secret keys on the PKCS#11 provider. GetExportKeySize refuses
the same way.

ExportKey and GetExportKeySize share one encoding function, so the
size query always matches the exported length.

Signed-off-by: Abdullah Elmarghany <abdullah.elmarghany@bmw.de>

This branch is waiting to be deployed

1 waiting deployment
workflow-approval — 176ad548 Waiting Nov 27, 2026 by abdullahelmarghany via Build and Test aarch64-qnx / approval #1263
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.

1 participant