Repository navigation
[C] Managed provider: validate stored chains; atomic owner-only writes - #410
Merged
Ewerton Scaboro da Silva (ewertons) merged 7 commits intoOct 11, 2026
Merged
Ewerton Scaboro da Silva (ewertons) merged 7 commits into
Ewerton Scaboro da Silva (ewertons) merged 7 commits into
Conversation
- store_issued_certificate() refuses a chain unless every entry is a non-empty, parseable PEM certificate, the count matches, the leaf certifies the operational key, and the PEM chain is at most 64 KiB. Each entry is sized before it is decoded. A refused store keeps the previous chain. - init() uses a persisted chain only if it passes the same checks; the read is bounded to 64 KiB. - The key and chain are written to a uniquely named, exclusively created file next to the destination (0600 on POSIX, owner-only DACL on Windows), flushed, then renamed over it. A failed write leaves the destination untouched; a symlink there is replaced, not followed. The mode of an existing key file is not changed.
Ewerton Scaboro da Silva (ewertons)
requested review from
Avishek (avishekpant) and
Maxim Semenov (maximsemenov80)
as code owners
October 11, 2026 07:10
Copilot started reviewing on behalf of
Ewerton Scaboro da Silva (ewertons)
October 11, 2026 07:10
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Windows consumers lack the provider’s required system-library linkage, and malformed base64 returns the wrong result code.
3 open findings
What changed in this PR
Hardens managed certificate persistence through chain validation, bounded reads, and atomic owner-only file replacement.
Changes:
- Validates certificate chains against the operational key and 64 KiB limit.
- Adds secure atomic writes for POSIX and Windows.
- Expands platform-specific tests and coverage documentation.
| File | Description |
|---|---|
c/adapters/cert_openssl/az_iot_certificate_provider_managed.c |
Implements validation and secure atomic persistence. |
c/adapters/cert_openssl/az_iot_certificate_provider_managed.h |
Documents validation and file protections. |
c/tests/unit/certificate_provider_managed_test.c |
Adds validation, permissions, DACL, and symlink tests. |
c/tests/CMakeLists.txt |
Adds Windows security-library linkage for tests. |
c/docs/eng/test-coverage.md |
Records expanded managed-provider coverage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…e and rename failures - The provider target links advapi32 on Windows, so every consumer gets it. - An issued entry that is not base64 is AZ_IOT_ERR_INVALID_ARG, not AZ_IOT_ERR_INTERNAL; allocation and write failures keep their codes. - Windows: GetTickCount64 for the temp-name seed; a NULL handle is a failure. - POSIX tests: a failed write or rename keeps the destination and leaves no temporary file.
Copilot started reviewing on behalf of
Ewerton Scaboro da Silva (ewertons)
October 11, 2026 07:27
View session
This was referenced Oct 11, 2026
Copilot started reviewing on behalf of
Ewerton Scaboro da Silva (ewertons)
October 11, 2026 07:36
View session
…ate; key-file doc - A certificate followed by more bytes in the same block is refused at store and not used at init. - The operational key option documents that only a key that loads is left as is; a missing, unreadable or malformed file is replaced.
Copilot started reviewing on behalf of
Ewerton Scaboro da Silva (ewertons)
October 11, 2026 07:49
View session
Copilot started reviewing on behalf of
Ewerton Scaboro da Silva (ewertons)
October 11, 2026 08:00
View session
Ewerton Scaboro da Silva (ewertons)
left a comment
Contributor
Author
There was a problem hiding this comment.
Approved
Ewerton Scaboro da Silva (ewertons)
deleted the
feature/c-managed-provider-storage
branch
October 11, 2026 15:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The managed certificate provider stores only chains for its own key and writes its files atomically, readable only by the current user.
Store (
store_issued_certificate)AZ_IOT_ERR_INVALID_ARG) unless every entry is a non-empty, parseable PEM certificate, the parsed count matches the issued count, the leaf certifies the operational key, and the PEM chain is at most 64 KiB. Each entry is sized before it is decoded.Init
Writes (key and chain)
mkstemp+fchmod(0600)on POSIX, owner-only protected DACL (owner, SYSTEM) on Windows. Flushed, then renamed over the destination.Tests: unit tests for each behavior. Permission, mode and symlink tests are POSIX only; a Windows test checks the DACL.
Validation (Linux, gcc): all unit suites pass, the provider suite also under ASan/UBSan; clang-tidy 18.1.8 clean on the provider; clang-format 18 and repo lint scripts pass. The Windows code was syntax-checked with MinGW only.