Cached online keys can suppress offline persistable-key requests in AVContentKeySession

GitHub source

Apple confirmed. This page is generated from GitHub Issue #33; GitHub remains the canonical authoring and discussion source.

Source#

Problem#

A FairPlay HLS asset plays online through AVContentKeySession with a non-persistable key. Later, the application downloads the same asset and needs a persistable key. With the same session and key identifier, contentKeySession(_:didProvide:) is not called again; explicitly calling processContentKeyRequest(withIdentifier:initializationData:options:) does not force the callback.

Environment: iOS 18+, AVFoundation, FairPlay Streaming, online → offline transition.

Evidence level#

Apple confirmed for the missing-callback explanation and persistable-request API. Inferred / needs device verification for a fresh-session isolation workaround.

Cause / explanation#

An Apple Media Engineer explicitly confirms that AVContentKeySession caches valid keys by key ID. If a key remains resolved, requesting that same key does not necessarily reinvoke the delegate. The first documented divergence is the key-session cache hit, before the application's persistable-key branch, SPC generation, KSM authorization, or CKC processing.

The engineer confirms that distinct key IDs are not required for online and offline usage. A persistable key is obtained by invoking respondByRequestingPersistableContentKeyRequestAndReturnError() on an appropriate AVContentKeyRequest; this yields an AVPersistableContentKeyRequest callback when supported.

Critical distinction: This API must be called when the application has a suitable unresolved request. The forum response does not prove that a cached, already-resolved online key can be upgraded to a persistable key afterward. The absence of a callback is precisely why a post-hoc upgrade may be impossible through the same request path.

Lifecycle#

Online-first, same key session:
  EXT-X-KEY / SKD URI
    → AVContentKeyRequest
    → SPC → KSM → CKC
    → processContentKeyResponse
    → valid online key cached

Later download, same KID:
  processContentKeyRequest / asset download
    → cached valid key reused
    → no new normal delegate callback
    → no AVPersistableContentKeyRequest
    → no persistent key file

Correct offline-first acquisition sequence:

Download intent before key resolution
  → AVContentKeyRequest
  → respondByRequestingPersistableContentKeyRequestAndReturnError()
  → AVPersistableContentKeyRequest
  → SPC → authorized KSM → CKC
  → persistableContentKey(fromKeyVendorResponse:options:)
  → securely store persistent key
  → process appropriate key response
  → verify .movpkg + key, then test airplane-mode playback

The KSM must authorize offline persistence; a streaming-only CKC cannot be assumed to grant offline rights.

Engineering guideline#

  1. Establish download intent before resolving the key, and select the persistable path in the first eligible delegate callback.
  2. For online → offline after a key is already resolved, test a separate, freshly configured AVContentKeySession for the download with its own delegate and recipient lifecycle. This is a candidate mitigation, not an Apple-documented universal fix. Do not expire a session while active recipients still depend on it.
  3. Do not change KIDs merely to force callbacks. If separate KIDs are chosen as a content design, coordinate playlist signaling, actual key material and KSM mapping.
  4. Instrument session identity, full SKD URI/KID, acquisition intent, callback type/order, key request status, KSM authorization metadata, persistence success and offline playback. Never log SPC/CKC or persistent key bytes.

Swift delegate skeleton (license transport omitted)#

func contentKeySession(_ session: AVContentKeySession,
                       didProvide request: AVContentKeyRequest) {
    if acquisitionIntent == .offlineDownload {
        do {
            try request.respondByRequestingPersistableContentKeyRequestAndReturnError()
        } catch {
            request.processContentKeyResponseError(error)
        }
        return
    }
    // Online: authorized SPC/CKC exchange.
}

func contentKeySession(_ session: AVContentKeySession,
                       didProvide request: AVPersistableContentKeyRequest) {
    // Offline: SPC/CKC with persistence rights,
    // persistableContentKey(fromKeyVendorResponse:options:),
    // secure storage, then process the appropriate response.
}

Verification#

Controlled experiment Key observation
Offline-first, fresh session Normal callback → persistable callback → persistent key
Online-first → offline, same session/KID Cached key may suppress new callback (Apple confirmed)
Explicit repeat request, same resolved KID Does not necessarily force callback (Apple confirmed for report)
Online-first → offline, separate fresh session Test whether persistable callback occurs; not guaranteed
KSM persistence disabled Check conversion/authorization error independently
Multiple rotating KIDs Check per-KID state and offline coverage

Evidence still needed: physical-device iOS 18+ A/B traces, request lifecycle timestamps, KSM authorization and offline airplane-mode playback.

Experiment#

A deterministic conceptual Python state-machine model was executed on 2026-10-25: six scenarios, seven assertions passed. This illustrates the confirmed cache semantics but does not run AVFoundation or FairPlay, and does not establish that a new session fixes actual devices.

Reusable insight#

A content key identifier is not a command to change persistence class. Key resolution and offline-license intent are separate state dimensions. Do not use repeated key requests as an implicit online-to-offline upgrade mechanism.

References#