Skip to content

Fix PlayChain key data return semantics - #239

Merged
Depal1 merged 2 commits into
PlayCover:masterfrom
Kaua463:fix-youtube-playchain-v3
Sep 30, 2026
Merged

Depal1 merged 2 commits into
PlayCover:masterfrom
Kaua463:fix-youtube-playchain-v3

Conversation

@Kaua463

@Kaua463 Kaua463 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes PlayChain handling of keychain return semantics, particularly for kSecClassKey items requested with kSecReturnData.

Problem

PlayChain previously treated matched kSecClassKey items as SecKeyRef objects even when the caller explicitly requested kSecReturnData.

Google apps, including YouTube, perform queries such as:

kSecClass = kSecClassKey
kSecReturnData = true
kSecReturnRef = false

In this case PlayChain attempted to reconstruct a SecKey using key metadata such as kSecAttrKeyType and kSecAttrKeyClass.

Some persisted key entries do not contain those attributes, which could lead to a crash in PlayKeychain.copyMatching.

PlayChain also attempted to construct return values during SecItemAdd calls where the caller did not request a result.

Changes

  • Respect kSecReturnData for key-class items and return the stored data instead of constructing a SecKey.
  • Avoid constructing return values for SecItemAdd when no return value was requested.
  • Handle data-only kSecMatchLimitAll queries.
  • Treat queries without any kSecReturn* flags as existence checks.
  • Preserve the existing kSecReturnRef behavior.

Testing

Tested with YouTube iOS 21.38.3 under PlayCover on Apple Silicon.

Runtime instrumentation confirmed calls including:

SecItemCopyMatching class=keys data=1 ref=0 attrs=0 pref=0
SecItemAdd class=keys data=0 ref=0 attrs=0 pref=0 resultPtr=0

With the final uninstrumented build:

  • YouTube login persisted across 5 consecutive force-stop/relaunch cycles.
  • Login persisted after fully quitting and restarting PlayCover.
  • No PlayChain crash occurred.
  • The project builds successfully with Xcode 27.0.

Related:

@TheMoonThatRises TheMoonThatRises added the enhancement New feature or request label Sep 29, 2026
@Kaua463
Kaua463 force-pushed the fix-youtube-playchain-v3 branch from 851754b to 13c4fd6 Compare September 29, 2026 17:02
@TheMoonThatRises

Copy link
Copy Markdown
Member

@ohaiibuzzle you are the inventor of PlayChain, could you review this PR please?

@ohaiibuzzle

ohaiibuzzle commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Looks good. To be completely honest PlayChain makes a lot of assumptions when it was made, so these changes are to be expected.

@Depal1
Depal1 merged commit e222ce0 into PlayCover:master Sep 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants