Skip to content

CBL-7156 : Fix iOS cert chain deletion to handle self-signed roots ad ensure safe removal#2303

Merged
pasin merged 1 commit into
masterfrom
CBL-7156
Jul 9, 2025
Merged

CBL-7156 : Fix iOS cert chain deletion to handle self-signed roots ad ensure safe removal#2303
pasin merged 1 commit into
masterfrom
CBL-7156

Conversation

@pasin

@pasin pasin commented Jul 8, 2025

Copy link
Copy Markdown
Collaborator

Problem

In version 3.3.0, we enhanced the TLSIdentity API to support creating identities signed by an issuer. These identities include a certificate chain (leaf + root), all saved into the Keychain. However, when deleting the identity using the persistent label, only the leaf certificate was removed — the root or intermediate certs remained.

The root cause is that the deletion logic in Cert::deleteCert(const std::string &persistentID) relies on checking whether a certificate is an issuer for other certs. Basically, this check skips deleting certificates with multiple children. However, it doesn’t account for self-signed root certs, which are their own issuers, resulting in the root cert not being deleted.

Fixes

  • Updated the deletion logic to correctly handle and delete self-signed root certificates.

  • To prevent accidental deletion of unrelated certs, we now assign a shared label (kSharedCertLabel) to all non-leaf certificates saved via LiteCore. During deletion, we verify this label to ensure only certs saved by LiteCore are removed.

  • In addition, remove the obsolete codes in PublicKey+Apple.mm that supports macOS < 12.0 and iOS < 15.0 (in 3.3.0, we support macOS 12.0+ and iOS 15.0+).

Note to Reviewers

  • The main change is in void Cert::deleteCert(const std::string &persistentID) and Cert::save(const std::string &persistentID, bool entireChain) function.

  • I have tested the fix with TLSIdentityTests in CBL-iOS project.

…d ensure safe removal

Problem:

In version 3.3.0, we enhanced the TLSIdentity API to support creating identities signed by an issuer. These identities include a certificate chain (leaf + root), all saved into the Keychain. However, when deleting the identity using the persistent label, only the leaf certificate was removed — the root or intermediate certs remained.

The root cause is that the deletion logic in Cert::deleteCert(const std::string &persistentID) relies on checking whether a certificate is an issuer for other certs. Basically, this check skips deleting certificates with multiple children. However, it doesn’t account for self-signed root certs, which are their own issuers, resulting in the root cert not being deleted.

Fixes

* Updated the deletion logic to correctly handle and delete self-signed root certificates.

* To prevent accidental deletion of unrelated certs, we now assign a shared label (kSharedCertLabel) to all non-leaf certificates saved via LiteCore. During deletion, we verify this label to ensure only certs saved by LiteCore are removed.

* In addition, remove the obsolete codes in PublicKey+Apple.mm that supports macOS < 12.0 and iOS < 15.0 (in 3.3.0, we support macOS 12.0+ and iOS 15.0+).
@cbl-bot

cbl-bot commented Jul 8, 2025

Copy link
Copy Markdown

Code Coverage Results:

Type Percentage
branches 65.74
functions 77.56
instantiations 70.21
lines 77.03
regions 72.83

@pasin pasin requested a review from jianminzhao July 8, 2025 15:34
@pasin pasin merged commit b0161b9 into master Jul 9, 2025
8 checks passed
@pasin pasin deleted the CBL-7156 branch July 9, 2025 00:59
jianminzhao added a commit that referenced this pull request Jul 9, 2025
CBL-7156 : Fix iOS cert chain deletion to handle self-signed roots and ensure safe removal (#2303)
CBL-7125: c4Log sometimes does not log anything (#2302)
9bf748f c4PeerDiscovery.hh no longer uses nonpublic headers (#2301)

Included in EE:

CBL-7147: MultipeerReplicator forces its own auth dictionary (#63)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants