Skip to content
This repository was archived by the owner on Sep 4, 2026. It is now read-only.
This repository was archived by the owner on Sep 4, 2026. It is now read-only.

APCKeychainStore.stringForKey randomly returning empty values  #119

Description

@brendenwest

I'm seeing unpredictable behavior with APCKeychain, where APCKeychainStore.stringForKey incorrectly returns an empty value about 1/3 of the time. Where APCKeychainStore incorrectly returns empty values, I can force-close the app and see the correct values returned on subsequent queries.

I'm getting and setting keychain values via Swift, like this:

var email : String {
    get {
        if let value = APCKeychainStore.stringForKey(kEmailPropertyName) {
            return value
        }
        return ""
    }
    set {
        APCKeychainStore.setString(newValue, forKey: kEmailPropertyName)
    }
}

var password : String {
    get {
        if let value = APCKeychainStore.stringForKey(kPasswordPropertyName) {
            return value
        }
        return ""
    }
    set {
        APCKeychainStore.setString(newValue, forKey: kPasswordPropertyName)
    }
}

Activity

  1. rsanchezsaez commented on Jul 29, 2015

    @rsanchezsaez

    Could this be related to the infamous -34018 (errSecMissingEntitlement) keychain bug?

  2. brendenwest commented on Jul 29, 2015

    @brendenwest
    Author

    I get no errors on compile or at run time.

    Also, I haven't enabled the Keychain sharing entitlement, since I don't expect to share the keychain data with other apps.

  3. rsanchezsaez commented on Jul 29, 2015

    @rsanchezsaez

    Are you sure you don't see any keychain-related message logged onto the console at runtime when you get nil from the stringForKey() method? (AppCore should be compiled in Debug for you to see them)

    The bug I was mentioning would manifest by APCKeychainStore running this code path, which would print a debug log message on the console and return nil.

    There's more info about this issue here. It has been a longstanding keychain issue on iOS, and unfortunately it's quite random.

  4. brendenwest commented on Jul 29, 2015

    @brendenwest
    Author

    I see this error when I haven't yet set a passcode:

    APC_DEBUG in +[APCKeychainStore dataForKey:service:accessGroup:] at APCKeychainStore.m:105 => SecItemCopyMatching query failed with error code: 4294941996i

    But an error is expected there. I haven't recently repro'd the issue of unexpected missing values.

  5. added a commit that references this issue on Jun 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions