Search code examples
iosdrmfairplayavcontentkeysession

iOS 16: AVContentKeyRequest processContentKeyResponse Throws Exception


Issue:

I am supporting a streaming iOS application that uses Fairplay DRM to playback protected content.

On iOS 16 devices, I am seeing intermittent exceptions thrown when trying to process the CKC returned by the license server.

The thrown exception is as follows:

-[AVContentKeyRequest processContentKeyResponse:] AVContentKeySession's keySystem is not same as that of keyResponse"

This issue does not occur on older devices (we support iOS 13, 14, 15).

I am unable to find much documentation about this error so any insight is appreciated:

Code Overview

  • Use ContentKeyRequest to request an application certificate
  • Use returned Cert to call makeStreamingContentKeyRequestData
  • Use returned data to request FairPlay license
  • Use returned CKC to generate AVContentKeyResponse (i.e. AVContentKeyResponse(fairPlayStreamingKeyResponseData)
  • Call processContentKeyResponse(_)
  • App crash/exception thrown when callling processContentKeyResponse

I am seeing other issues related to DRM and iOS 16 but none seem to match my particular problem. i.e. I am not dealing with downloaded content and offline DRM


Solution

  • For me, this error is thrown when the content is dismissed before FairPlay has a chance to process the content key:

    let keyResponse = AVContentKeyResponse(fairPlayStreamingKeyResponseData: ckcData)
    // Error happens at this point if request is active
    keyRequest.processContentKeyResponse(keyResponse)
    

    Since I'm using Alamofire to make the certificate, SPC, and CKC calls, stopping all the requests immediately upon dismissing the content prevented the key processing:

    Alamofire.Session.default.getAllTasks { tasks in
       tasks.forEach{ $0.cancel() }
    }
    

    Of course this may not be an ideal approach, but let me know if anyone finds a better way.