Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osxkeychain: lock for exclusive execution #1729

Commits on May 15, 2024

  1. osxkeychain: exclusive lock to serialize execution of operations

    git passes a credential that has been used successfully to the helpers
    to record. If "git-credential-osxkeychain store" commands run in
    parallel (with fetch.parallel configuration and/or by running multiple
    git commands simultaneously), some of them may exit with the error
    "failed to store: -25299". This is because SecItemUpdate() in
    add_internet_password() may return errSecDuplicateItem (-25299) in this
    situation. Apple's documentation [1] also states as below:
    
      In macOS, some of the functions of this API block while waiting for
      input from the user (for example, when the user is asked to unlock a
      keychain or give permission to change trust settings). In general, it
      is safe to use this API in threads other than your main thread, but
      avoid calling the functions from multiple operations, work queues, or
      threads concurrently. Instead, serialize function calls or confine
      them to a single thread.
    
    The error has not been noticed before, because the former implementation
    ignored the error.
    
    Introduce an exclusive lock to serialize execution of operations.
    
    [1] https://developer.apple.com/documentation/security/certificate_key_and_trust_services/working_with_concurrency
    
    Signed-off-by: Koji Nakamaru <koji.nakamaru@gree.net>
    KojiNakamaru committed May 15, 2024
    Configuration menu
    Copy the full SHA
    3341346 View commit details
    Browse the repository at this point in the history
  2. osxkeychain: state to skip unnecessary store operations

    git passes a credential that has been used successfully to the helpers
    to record. If a credential is already stored,
    "git-credential-osxkeychain store" just records the credential returned
    by "git-credential-osxkeychain get", and unnecessary (sometimes
    problematic) SecItemAdd() and/or SecItemUpdate() are performed.
    
    We can skip such unnecessary operations by marking a credential returned
    by "git-credential-osxkeychain get". This marking can be done by
    utilizing the "state[]" feature:
    
    - The "get" command sets the field "state[]=osxkeychain:seen=1".
    
    - The "store" command skips its actual operation if the field
      "state[]=osxkeychain:seen=1" exists.
    
    Introduce a new state "state[]=osxkeychain:seen=1".
    
    Suggested-by: brian m. carlson <sandals@crustytoothpaste.net>
    Signed-off-by: Koji Nakamaru <koji.nakamaru@gree.net>
    KojiNakamaru committed May 15, 2024
    Configuration menu
    Copy the full SHA
    146b0ae View commit details
    Browse the repository at this point in the history