Skip to content

[feature/mtls-client-certificates] TLS client certificate (mTLS) support - #180

Open
bunducdragos wants to merge 1 commit into
owncloud:masterfrom
bunducdragos:feature/mtls-client-certificates
Open

bunducdragos wants to merge 1 commit into
owncloud:masterfrom
bunducdragos:feature/mtls-client-certificates

Conversation

@bunducdragos

@bunducdragos bunducdragos commented Nov 25, 2026 •

Copy link
Copy Markdown

Description

Adds support for TLS client certificates (mutual TLS), for servers, or reverse proxies in front of them, that require clients to present a certificate.

  • OCClientIdentityStore (new, Security/): stores client identities imported from PKCS#12 (.p12/.pfx) files, one per server host.
    • The PKCS#12 data and its password are kept together in a single generic-password keychain item per host. The item lives in the app's shared keychain access group (same group as OCKeychain), so app extensions such as the File Provider can use it. It is kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly and not synchronizable.
    • An identity is only ever presented to the exact host it was imported for.
    • Lookups re-read the keychain item, which happens once per TLS handshake rather than per request. Imports and removals made in the app therefore take effect in already-running extensions. The decoded NSURLCredential is cached for as long as the stored data is unchanged.
    • Provides the subject summary and expiry date (iOS 18+) for display, plus import (with wrong-password / invalid-file / no-identity errors) and removal. A failed import leaves a previously stored identity untouched.
  • OCHTTPPipeline: NSURLAuthenticationMethodClientCertificate challenges are answered with the identity stored for the challenge's host. Before this change, every challenge other than server trust got PerformDefaultHandling, so the TLS handshake with such servers failed.
  • OCAuthenticationMethodOAuth2: new class property mutualTLSBrowserSessionClass. ASWebAuthenticationSession can't present client certificates provided by the app. If this property is set and an identity is stored for the authorization URL's host (and no browser session class is configured via class settings), this OCAuthenticationBrowserSession subclass is used instead. The app provides a WKWebView-based implementation, see the ios-app PR.

Related Issue

Fixes #11

App side (UI, in-app login session, web views): owncloud/ios-app#1607

Motivation and Context

Self-hosted instances are often put behind a reverse proxy with ssl_verify_client on (nginx) / SSLVerifyClient require (Apache). This is what #11 asked for, and the desktop client has supported it since 2.3.

How Has This Been Tested?

  • New ClientIdentityStoreTests: import, lookup, host scoping, challenge-method filtering, removal, a wrong password keeping the previous identity, and invalid input. They use a self-signed test identity (client-identity.p12). All pass on an iOS 26.3 simulator (Xcode 27.2).
  • ownCloudSDKTests suites that don't need a live server (ClientIdentityStore, Bookmark, DataSource, Extension, Lock, KeyValueStore, PasswordPolicy, Database, Settings, SQL, Certificate, Misc) on an iOS 26.3 simulator: 84/86 pass. The 2 failures (CertificateTests testCertificateMetaDataParsingFromWeb, SettingsTests testMetadataAvailability) fail the same way on a clean master.
  • The server-based suites couldn't be run: demo.owncloud.org no longer resolves, and ocis.ocis-wopi.latest.owncloud.works serves a certificate for a different hostname.
  • Manually on an iPhone 15 Pro, with the ios-app PR: an ownCloud server behind a reverse proxy that requires a client certificate. Import, login (app password), browsing and Files app (File Provider) access work.

Note: the Ocean test host doesn't launch on an iOS 27 simulator when built with Xcode 27.2 ("UIScene life cycle is required for apps built with this SDK"). That is unrelated to this change, so the tests were run on iOS 26.3.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

🤖 Generated with Claude Code

- OCClientIdentityStore: new store for client identities imported from
  PKCS#12 files, one per server host. Kept in the shared keychain access
  group (after first unlock, this device only, not synchronizable) so app
  extensions can use them. Identities are only presented to the exact
  host they were imported for. Lookups re-read the keychain so changes
  made in the app take effect in running extensions; decoded credentials
  are cached while the stored data is unchanged.
- OCHTTPPipeline: answer NSURLAuthenticationMethodClientCertificate
  challenges with the identity stored for the challenge's host (previously
  default handling, which failed the TLS handshake).
- OCAuthenticationMethodOAuth2: add mutualTLSBrowserSessionClass, used
  instead of ASWebAuthenticationSession when a client identity is stored
  for the authorization URL's host, since ASWebAuthenticationSession can't
  present app-provided client certificates.
- ClientIdentityStoreTests + client-identity.p12 test fixture.

Fixes owncloud#11

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CLAassistant

CLAassistant commented Nov 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

TLS client certificate support

2 participants