Coder Social home page Coder Social logo

kishikawakatsumi / keychainaccess Goto Github PK

View Code? Open in Web Editor NEW
7.8K 126.0 766.0 1.54 MB

Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.

License: MIT License

Swift 99.10% Ruby 0.49% Objective-C 0.40%
keychain touch-id security

keychainaccess's Introduction

KeychainAccess

Build Status Carthage compatible SPM supported Version Platform

KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and macOS. Makes using Keychain APIs extremely easy and much more palatable to use in Swift.

πŸ’‘ Features

πŸ“– Usage

πŸ‘€ See also:

πŸ”‘ Basics

Saving Application Password

let keychain = Keychain(service: "com.example.github-token")
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"

Saving Internet Password

let keychain = Keychain(server: "https://github.com", protocolType: .https)
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"

πŸ”‘ Instantiation

Create Keychain for Application Password

let keychain = Keychain(service: "com.example.github-token")
let keychain = Keychain(service: "com.example.github-token", accessGroup: "12ABCD3E4F.shared")

Create Keychain for Internet Password

let keychain = Keychain(server: "https://github.com", protocolType: .https)
let keychain = Keychain(server: "https://github.com", protocolType: .https, authenticationType: .htmlForm)

πŸ”‘ Adding an item

subscripting

for String
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
keychain[string: "kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
for NSData
keychain[data: "secret"] = NSData(contentsOfFile: "secret.bin")

set method

keychain.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")

error handling

do {
    try keychain.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
}
catch let error {
    print(error)
}

πŸ”‘ Obtaining an item

subscripting

for String (If the value is NSData, attempt to convert to String)
let token = keychain["kishikawakatsumi"]
let token = keychain[string: "kishikawakatsumi"]
for NSData
let secretData = keychain[data: "secret"]

get methods

as String
let token = try? keychain.get("kishikawakatsumi")
let token = try? keychain.getString("kishikawakatsumi")
as NSData
let data = try? keychain.getData("kishikawakatsumi")

πŸ”‘ Removing an item

subscripting

keychain["kishikawakatsumi"] = nil

remove method

do {
    try keychain.remove("kishikawakatsumi")
} catch let error {
    print("error: \(error)")
}

πŸ”‘ Set Label and Comment

let keychain = Keychain(server: "https://github.com", protocolType: .https)
do {
    try keychain
        .label("github.com (kishikawakatsumi)")
        .comment("github access token")
        .set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
} catch let error {
    print("error: \(error)")
}

πŸ”‘ Obtaining Other Attributes

PersistentRef

let keychain = Keychain()
let persistentRef = keychain[attributes: "kishikawakatsumi"]?.persistentRef
...

Creation Date

let keychain = Keychain()
let creationDate = keychain[attributes: "kishikawakatsumi"]?.creationDate
...

All Attributes

let keychain = Keychain()
do {
    let attributes = try keychain.get("kishikawakatsumi") { $0 }
    print(attributes?.comment)
    print(attributes?.label)
    print(attributes?.creator)
    ...
} catch let error {
    print("error: \(error)")
}
subscripting
let keychain = Keychain()
if let attributes = keychain[attributes: "kishikawakatsumi"] {
    print(attributes.comment)
    print(attributes.label)
    print(attributes.creator)
}

πŸ”‘ Configuration (Accessibility, Sharing, iCloud Sync)

Provides fluent interfaces

let keychain = Keychain(service: "com.example.github-token")
    .label("github.com (kishikawakatsumi)")
    .synchronizable(true)
    .accessibility(.afterFirstUnlock)
Default accessibility matches background application (=kSecAttrAccessibleAfterFirstUnlock)
let keychain = Keychain(service: "com.example.github-token")
For background application
Creating instance
let keychain = Keychain(service: "com.example.github-token")
    .accessibility(.afterFirstUnlock)

keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
One-shot
let keychain = Keychain(service: "com.example.github-token")

do {
    try keychain
        .accessibility(.afterFirstUnlock)
        .set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
} catch let error {
    print("error: \(error)")
}
For foreground application
Creating instance
let keychain = Keychain(service: "com.example.github-token")
    .accessibility(.whenUnlocked)

keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
One-shot
let keychain = Keychain(service: "com.example.github-token")

do {
    try keychain
        .accessibility(.whenUnlocked)
        .set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
} catch let error {
    print("error: \(error)")
}

πŸ‘« Sharing Keychain items

let keychain = Keychain(service: "com.example.github-token", accessGroup: "12ABCD3E4F.shared")
Creating instance
let keychain = Keychain(service: "com.example.github-token")
    .synchronizable(true)

keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
One-shot
let keychain = Keychain(service: "com.example.github-token")

do {
    try keychain
        .synchronizable(true)
        .set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
} catch let error {
    print("error: \(error)")
}

Any Operation that require authentication must be run in the background thread.
If you run in the main thread, UI thread will lock for the system to try to display the authentication dialog.

To use Face ID, add NSFaceIDUsageDescription key to your Info.plist

πŸ” Adding a Touch ID (Face ID) protected item

If you want to store the Touch ID protected Keychain item, specify accessibility and authenticationPolicy attributes.

let keychain = Keychain(service: "com.example.github-token")

DispatchQueue.global().async {
    do {
        // Should be the secret invalidated when passcode is removed? If not then use `.WhenUnlocked`
        try keychain
            .accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: [.biometryAny])
            .set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
    } catch let error {
        // Error handling if needed...
    }
}

πŸ” Updating a Touch ID (Face ID) protected item

The same way as when adding.

Do not run in the main thread if there is a possibility that the item you are trying to add already exists, and protected. Because updating protected items requires authentication.

Additionally, you want to show custom authentication prompt message when updating, specify an authenticationPrompt attribute. If the item not protected, the authenticationPrompt parameter just be ignored.

let keychain = Keychain(service: "com.example.github-token")

DispatchQueue.global().async {
    do {
        // Should be the secret invalidated when passcode is removed? If not then use `.WhenUnlocked`
        try keychain
            .accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: [.biometryAny])
            .authenticationPrompt("Authenticate to update your access token")
            .set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
    } catch let error {
        // Error handling if needed...
    }
}

πŸ” Obtaining a Touch ID (Face ID) protected item

The same way as when you get a normal item. It will be displayed automatically Touch ID or passcode authentication If the item you try to get is protected.
If you want to show custom authentication prompt message, specify an authenticationPrompt attribute. If the item not protected, the authenticationPrompt parameter just be ignored.

let keychain = Keychain(service: "com.example.github-token")

DispatchQueue.global().async {
    do {
        let password = try keychain
            .authenticationPrompt("Authenticate to login to server")
            .get("kishikawakatsumi")

        print("password: \(password)")
    } catch let error {
        // Error handling if needed...
    }
}

πŸ” Removing a Touch ID (Face ID) protected item

The same way as when you remove a normal item. There is no way to show Touch ID or passcode authentication when removing Keychain items.

let keychain = Keychain(service: "com.example.github-token")

do {
    try keychain.remove("kishikawakatsumi")
} catch let error {
    // Error handling if needed...
}

Shared web credentials is a programming interface that enables native iOS apps to share credentials with their website counterparts. For example, a user may log in to a website in Safari, entering a user name and password, and save those credentials using the iCloud Keychain. Later, the user may run a native app from the same developer, and instead of the app requiring the user to reenter a user name and password, shared web credentials gives it access to the credentials that were entered earlier in Safari. The user can also create new accounts, update passwords, or delete her account from within the app. These changes are then saved and used by Safari.
https://developer.apple.com/library/ios/documentation/Security/Reference/SharedWebCredentialsRef/

let keychain = Keychain(server: "https://www.kishikawakatsumi.com", protocolType: .HTTPS)

let username = "[email protected]"

// First, check the credential in the app's Keychain
if let password = try? keychain.get(username) {
    // If found password in the Keychain,
    // then log into the server
} else {
    // If not found password in the Keychain,
    // try to read from Shared Web Credentials
    keychain.getSharedPassword(username) { (password, error) -> () in
        if password != nil {
            // If found password in the Shared Web Credentials,
            // then log into the server
            // and save the password to the Keychain

            keychain[username] = password
        } else {
            // If not found password either in the Keychain also Shared Web Credentials,
            // prompt for username and password

            // Log into server

            // If the login is successful,
            // save the credentials to both the Keychain and the Shared Web Credentials.

            keychain[username] = inputPassword
            keychain.setSharedPassword(inputPassword, account: username)
        }
    }
}

Request all associated domain's credentials

Keychain.requestSharedWebCredential { (credentials, error) -> () in

}

Generate strong random password

Generate strong random password that is in the same format used by Safari autofill (xxx-xxx-xxx-xxx).

let password = Keychain.generatePassword() // => Nhu-GKm-s3n-pMx

How to set up Shared Web Credentials

  1. Add a com.apple.developer.associated-domains entitlement to your app. This entitlement must include all the domains with which you want to share credentials.

  2. Add an apple-app-site-association file to your website. This file must include application identifiers for all the apps with which the site wants to share credentials, and it must be properly signed.

  3. When the app is installed, the system downloads and verifies the site association file for each of its associated domains. If the verification is successful, the app is associated with the domain.

More details:
https://developer.apple.com/library/ios/documentation/Security/Reference/SharedWebCredentialsRef/

πŸ” Debugging

Display all stored items if print keychain object

let keychain = Keychain(server: "https://github.com", protocolType: .https)
print("\(keychain)")
=>
[
  [authenticationType: default, key: kishikawakatsumi, server: github.com, class: internetPassword, protocol: https]
  [authenticationType: default, key: hirohamada, server: github.com, class: internetPassword, protocol: https]
  [authenticationType: default, key: honeylemon, server: github.com, class: internetPassword, protocol: https]
]

Obtaining all stored keys

let keychain = Keychain(server: "https://github.com", protocolType: .https)

let keys = keychain.allKeys()
for key in keys {
  print("key: \(key)")
}
=>
key: kishikawakatsumi
key: hirohamada
key: honeylemon

Obtaining all stored items

let keychain = Keychain(server: "https://github.com", protocolType: .https)

let items = keychain.allItems()
for item in items {
  print("item: \(item)")
}
=>
item: [authenticationType: Default, key: kishikawakatsumi, server: github.com, class: InternetPassword, protocol: https]
item: [authenticationType: Default, key: hirohamada, server: github.com, class: InternetPassword, protocol: https]
item: [authenticationType: Default, key: honeylemon, server: github.com, class: InternetPassword, protocol: https]

Keychain sharing capability

If you encounter the error below, you need to add an Keychain.entitlements.

OSStatus error:[-34018] Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements.

Screen Shot 2019-10-27 at 8 08 50

Requirements

OS Swift
v1.1.x iOS 7+, macOS 10.9+ 1.1
v1.2.x iOS 7+, macOS 10.9+ 1.2
v2.0.x iOS 7+, macOS 10.9+, watchOS 2+ 2.0
v2.1.x iOS 7+, macOS 10.9+, watchOS 2+ 2.0
v2.2.x iOS 8+, macOS 10.9+, watchOS 2+, tvOS 9+ 2.0, 2.1
v2.3.x iOS 8+, macOS 10.9+, watchOS 2+, tvOS 9+ 2.0, 2.1, 2.2
v2.4.x iOS 8+, macOS 10.9+, watchOS 2+, tvOS 9+ 2.2, 2.3
v3.0.x iOS 8+, macOS 10.9+, watchOS 2+, tvOS 9+ 3.x
v3.1.x iOS 8+, macOS 10.9+, watchOS 2+, tvOS 9+ 4.0, 4.1, 4.2
v3.2.x iOS 8+, macOS 10.9+, watchOS 2+, tvOS 9+ 4.0, 4.1, 4.2, 5.0
v4.0.x iOS 8+, macOS 10.9+, watchOS 2+, tvOS 9+ 4.0, 4.1, 4.2, 5.1
v4.1.x iOS 8+, macOS 10.9+, watchOS 3+, tvOS 9+, Mac Catalyst 13+ 4.0, 4.1, 4.2, 5.1

Installation

CocoaPods

KeychainAccess is available through CocoaPods. To install it, simply add the following lines to your Podfile:

use_frameworks!
pod 'KeychainAccess'

Carthage

KeychainAccess is available through Carthage. To install it, simply add the following line to your Cartfile:

github "kishikawakatsumi/KeychainAccess"

Swift Package Manager

KeychainAccess is also available through Swift Package Manager.

Xcode

Select File > Add Packages... > Add Package Dependency...,

CLI

First, create Package.swift that its package declaration includes:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
        .library(name: "MyLibrary", targets: ["MyLibrary"]),
    ],
    dependencies: [
        .package(url: "https://github.com/kishikawakatsumi/KeychainAccess.git", from: "3.0.0"),
    ],
    targets: [
        .target(name: "MyLibrary", dependencies: ["KeychainAccess"]),
    ]
)

Then, type

$ swift build

To manually add to your project

  1. Add Lib/KeychainAccess.xcodeproj to your project
  2. Link KeychainAccess.framework with your target
  3. Add Copy Files Build Phase to include the framework to your application bundle

See iOS Example Project as reference.

Author

kishikawa katsumi, [email protected]

License

KeychainAccess is available under the MIT license. See the LICENSE file for more info.

keychainaccess's People

Contributors

aaadonai avatar abunur avatar alexmx avatar aloco avatar amarcadet avatar anthonymdev avatar dchohfi avatar franciscoamado avatar ikesyo avatar ilendemli avatar ishkawa avatar jessearmand avatar jeswinsimon avatar jinjorge avatar josephduffy avatar kevnm67 avatar kishikawakatsumi avatar ky1ejs avatar lpuentes19 avatar marcocanc avatar mxcl avatar raven avatar sgoodwin avatar usami-k avatar vladimirhorky avatar vladislavjevremovic avatar yangyubo avatar yaslab avatar zunda-pixel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

keychainaccess's Issues

Keychain and OnlyThisDevice

Hi,

I'm new to Swift and I am trying to store the Keychains locally only and not across device. I tried setting .synchronizable(false), but I still get a "AfterFirstUnlock" which says that the Keychain migrates to new device. Also, keychain.accessibility(.AlwaysThisDeviceOnly) doesn't seem to work, still get "AfterFirstUnlock" when print(keychain.accessibility). Is there a way to set the Keychain to be only this device and not sync with icloud.

Sorry if this is a dumb question.
Thanks

OSX Dev ID

I am needing to store user/pass info in OS X keychain, but not with an AppStore App. I am able to use DeveloperID for this library ? I am not able to use keychain sharing as that is disallowed for non MAS apps.

Use with Carthage

Hello,

I can't manage to use KeychainAccess with Carthage.

I get the following error:
*** Building scheme "KeychainAccess" in KeychainAccess.xcworkspace fatal error: SDK count 7 in scheme KeychainAccess is not supported: file /Users/mdiep/Repositories/Carthage/Carthage/Source/CarthageKit/Xcode.swift, line 959

Caught signal triggered by the Swift runtime! Illegal instruction: 4

I just add github "kishikawakatsumi/KeychainAccess" in my Cartfile

If I remove KeychainAccess from the Cartfile, everything runs fine with the command line carthage update --platform iOS --no-use-binaries

Thanks for your help!

Returning just key-value pairs as dictionary.

When I'm returning all values, I noticed there are only two methods: allItems and allKeys.
Is there a way to return just key value pairs in one dictionary??

For example, [ "last_name" : "value1", "first_name" : "value2" ].

Thank you!

Merge swift 2.0 to master

I think it would good to cut an official release for swift 2.0 as it's now officially released.

Thanks!

Archiving issue

I ended up copying the project manually to get rid of the module issues. That all worked until I tried archiving the project and got the following error:

screen shot 2015-10-20 at 11 41 28 am

please advice

Question: Which Xcode version was used to compile the release binaries

Hi

I was wondering, which Xcode version was used to compile the pre-built binaries from https://github.com/kishikawakatsumi/KeychainAccess/releases? (2.2.0 specifically).

I'm asking because a specific (and weird) issue I experienced using Carthage to embed KeychainAccess in my project. More details here: Carthage/Carthage#832

Could it be that they were created using an older version dan Xcode 7.0.1 (maybe one of the beta builds?)

Keep getting errors while saving data to Keychain

 keychain["\(PartConfigurationViewController.formName)_all_fields"] = "\(self.dataSource.requiredFields.count)"

        keychain["\(PartConfigurationViewController.formName)_invalid_fields"] = String(self.dataSource.invalidFields.count)

Whenever I run these methods, I get two errors saying same thing:

error:[-67594] failed to convert data to string

Can you guess why this is causing a problem?? self.dataSource.invalidFields.count is just Int type, btw.

values not stored?

Hi,

I have a wrapper class for KeychainAccess:

class KeychainHelper: NSObject {

    let keychain: Keychain

    class var sharedInstance: KeychainHelper {
        struct Singleton {
            static let instance = KeychainHelper()
        }
        return Singleton.instance
    }

    override init() {
        self.keychain = Keychain(service: "com.myDomain.myAppName")

        super.init()
    }

    var username:String? {

        get{
            return keychain["username"]
        }
        set{
            keychain["username"] = username
        }
    }
}

And wrote a test for it:

func testUserName() {

        if let existingUserName = KeychainHelper.sharedInstance.username{

            let testUserName = "[email protected]"

            KeychainHelper.sharedInstance.username = testUserName

            XCTAssertEqual(testUserName, KeychainHelper.sharedInstance.username)

             KeychainHelper.sharedInstance.username = existingUserName
             XCTAssertEqual(existingUserName, KeychainHelper.sharedInstance.username)
        }
        else{
            let testUserName = "[email protected]"

            KeychainHelper.sharedInstance.username = testUserName

            if let receivedUserName = KeychainHelper.sharedInstance.username{
                XCTAssertEqual(testUserName, receivedUserName)
            }
            else{
                XCTFail("username was not written to keychain!")
            }

            KeychainHelper.sharedInstance.username = nil
            if let receivedUserName = KeychainHelper.sharedInstance.username{
                XCTAssertEqual(receivedUserName, KeychainHelper.sharedInstance.username)
            }

        }
    }

The test fails, because no value can be fetched from Keychain. If I "po kechain" I get the result []. Any ideas?

License not mentioned in Keychain.swift

Hey

This is a tedious t crossing issue, but I noticed that the MIT licence the project is licensed under isn't reflected in the source file and it appears that the source as a whole is all rights reserved.

Build error on carthage update for swift-2.0 branch

I'm getting the following error when I try to run carthage update pointed at your swift-2.0 branch:

*** Building scheme "KeychainAccess-iOS" in KeychainAccess.xcworkspace
A shell task failed with exit code 65:
** BUILD FAILED **


The following build commands failed:
CompileSwift normal x86_64 /Users/n/Documents/Digest/digest_app_ios/DigestApp/Carthage/Checkouts/KeychainAccess/Lib/KeychainAccess/Keychain.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)

Segmentation fault: 11

Thoughts?

Repeating OSX Keychain Access Prompts

Good morning,

I am wondering if there is a way to get OSX to stop prompting each time the keychain is accessed. I click "Always allow" and it still prompts every time I access a particular value stored in the keychain.

let keychain = Keychain(service: "com.mycompany.myapp");
// Causes prompt #1
let someValue = keychain[Constants.SomeKey];

// Causes prompt #2
let someValue2 = keychain[Constants.SomeKey2];

It was my understanding that by initializing the Keychain with a service, all key/value pairs in this context would be authorized as a group.

Cheers,

Adam

Add CocoaPods support

CocoaPods recently added support for Swift. Could we add an KeyChain.podspec file to make this great lib available through CocoaPods?

KeychainAccess not compatible with iOS7 ?

In the docs it says this wrapper can be used in iOS7, however, when I try to install it in CocoaPods it says:

[!] The platform of the target XXX (iOS 7.0) is not compatible with KeychainAccess (1.1.1) which has a minimum requirement of iOS 8.0 - OS X 10.9.

Is it true that it is only available on iOS8 and above ?

Cocoapods unknown option character `X' in: -Xlinker

Im getting an error after I install via Cocoapods:

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker

Libtool /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Products/Debug-iphonesimulator/libPods-Orb-KeychainAccess.a normal x86_64
cd /Users/Mathias/Desktop/Orb/Pods
export IPHONEOS_DEPLOYMENT_TARGET=8.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -L/Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Products/Debug-iphonesimulator -filelist /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-Orb-KeychainAccess.build/Objects-normal/x86_64/Pods-Orb-KeychainAccess.LinkFileList -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-Orb-KeychainAccess.build/Objects-normal/x86_64/Pods_Orb_KeychainAccess.swiftmodule -framework Foundation -o /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Products/Debug-iphonesimulator/libPods-Orb-KeychainAccess.a

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table ] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]

I have other pods in my podfile that works. Not sure what happened here

Cheers!

Keychain synchronizable and TouchID

I try to enable the keychain synchronization together with a Touch ID enabled login.
Unfortunately I receive the following error whenever I set .synchronizable(true):

OSStatus error:[-50] One or more parameters passed to a function were not valid.

error: Optional(Error Domain=com.kishikawakatsumi.KeychainAccess.error Code=-50 "One or more parameters passed to a function were not valid." UserInfo=0x7fb271d3e6b0 {NSLocalizedDescription=One or more parameters passed to a function were not valid.})

And thats the example code:

let keychain = Keychain(service: "my.service").synchronizable(true)
    keychain.remove("default.tenantid")

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
        let failable = keychain
            .authenticationPrompt("Please auth!")
            .getStringOrError("default.tenantid")

        if failable.succeeded {
            var tenantId: String? = failable.value

            if tenantId == nil{
                tenantId = NSUUID().UUIDString

                let error = keychain
                    .accessibility(.WhenPasscodeSetThisDeviceOnly, authenticationPolicy: .UserPresence)
                    .set(tenantId!, key: "default.tenantid")

                if error != nil {
                    println("error: \(error)")
                    // Error handling if needed...
                }
            }

            //logged in
            println(tenantId)

        } else {
            println("error: \(failable.error?.localizedDescription)")
            // Error handling if needed...
        }
    }

What's wrong?

2 warnings for iOS 9, XCode7.1.1

Keychain.swift:556:12: Unnecessary check for 'iOS'; minimum deployment target ensures guard will always be true

Keychain.swift:1100:48: 'kSecUseNoAuthenticationUI' was deprecated in iOS 9.0: Use a kSecAuthenticationUI instead.

Check if item exists in keychain without Touch ID auth

Is this possible? Is it possible to see if a value exists at a given key in a keychain secured with Touch ID without prompting the user for their finger print?

If not, is there a way to check if the keychain, as a whole, exists without prompting for authentication?

I was torn as to whether I should ask this on here or on StackOverflow. I hope you don't mind me asking here? πŸ˜‡ πŸ˜…. I figured since I'm using your framework and couldn't find anything about my question in the README, I'd be coming back to you with any answer I got on SO to see how I do it via KeychainAccess.

Many thanks!

Error -34018 required entitlement

Hello,

I'm frequently getting this error:

Error Domain=com.kishikawakatsumi.KeychainAccess.error Code=-34018 "Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements."

I noticed it tends to happen when the application comes back from Background. Any idea where this could come from?

Subclassing

Hi All,

Im not sure if im doing this correctly, but im trying to subclass KeychainAccess..

The problem is that I cannot override any constructor cause the only designated is private and I cant call convenience constructors from the subclass..
My final goal is to create a singleton with Keychain:

static let sharedInstance = KeychainManager()

where.. class KeychainManager : Keychain

Can anyone give me hand to understand?

Thanks

Documentation is incorrect

Documentation mentions things such as:

try keychain.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")

Two issues here:
There is no such function. There is however a function called set forKey.

Secondly, this method does not actually throw any errors, so writing the above will result in a Swift warning.

So I am not sure how to even handle errors.

Documentation needs updating.

merge Swift 2.0 branch

Swift 2.0 is now official / released with Xcode 7. This should be merged to Master and Swift 2.0 branch deleted. Additionally you might want to start a Swift 2.1 branch...

Getting current warning on swift 2.0

/Users/allaire/Dropbox/Projects/agendrix/ios/Pods/KeychainAccess/Lib/KeychainAccess/Keychain.swift:289:19: Unnecessary check for 'iOS'; minimum deployment target ensures guard will always be true

var query = options.query()

query[kSecAttrAccount as String] = key
#if os(iOS)
if #available(iOS 9.0, *) {
    query[kSecUseAuthenticationUI as String] = kCFBooleanFalse
} else if #available(iOS 8.0, *) {
    query[kSecUseNoAuthenticationUI as String] = kCFBooleanTrue
}
#endif

Swift 2.1 build and archive

Please could you make a new release with an archive attached build from Xcode 7.1 + Swift 2.1? The current release and archive don't work with Xcode 7.1 and Swift 2.1.

screen shot 2015-10-22 at 15 04 24

Thanks! πŸ˜„

Unable to build with Carthage: Scheme KeychainAccess-tvOS is not currently configured for the build action

I won't pretend to know enough about build schemes etc for this, but on trying to update my builds, I get this error:

Scheme KeychainAccess-tvOS is not currently configured for the build action

I am guessing that this is to do with taking the schemes out of the project file. I can build with version == 2.3.1, but not with ~>2.2.0 (which resolves to 2.3.2) which I was using previously, and, interestingly enough, not with == 2.2.0 (which says it resolves to 2.2.0).

My Carthage build command is carthage update --no-use-binaries --no-skip-current --platform ios.

Is this perhaps because of not sharing build schemes or some such thing?

Target for iOS?

It would be nice to have a target inside the KeychainAccess project specifically for iOS.

As I can't use Cocoapods due to embedded frameworks are not supported I've included your KeychainAccess as git submodule into my iOS project and checked out the tag 2.3.5

Unfortunately I receive a an unexpected Mach- O header code after archiving when trying to upload to iTunes Connect.

This is due to the fact the KeychainAccess library is built for OS X by default (Base SDK is set to OS X).
Please add a second framework target, so this can be embedded in iOS projects without modifying your code / settings.

keychain value not saved after I kill the app

Everytime I killed the app, my keychain's value are empty/nil.
I'm storing the value like this :
var keychain = Keychain(service: "myapp.app.service")
keychain["login"] = login
keychain["auth_token"] = auth_token

Then in my appDelegate didFinishLaunchingWithOptions, I do this var

var keychain = Keychain(service: "myapp.app.service")
let login = keychain["login"]
let auth_token = keychain["auth_token"]

println(login)
println(keychain)

And after I kill the app and open it again, both my login and keychain are NIL. Anyone has any idea why my Keychains value are nil even though I never delete them? (I've tried both solution KeychainWrapper and KeychainAccess, both same behavior).

git tag for swift-2.0 branch

Thank you for your great library.

I'd like you to tag like '2.0.0-beta.4'
Because I want to add dependency in *.podspec, but podspec doesn't allow symbols like :git, :branch.

can do this in Podfile.

pod 'KeychainAccess', :git => 'https://github.com/kishikawakatsumi/KeychainAccess.git', :branch => 'swift-2.0'

cannot do this in *.podspec

s.dependency 'KeychainAccess', :git => 'https://github.com/kishikawakatsumi/KeychainAccess.git', :branch => 'swift-2.0'

want

s.dependency 'KeychainAccess', '~> 2.0.0-beta.4'

Best πŸ˜„

`APPLICATION_EXTENSION_API_ONLY = YES`

APPLICATION_EXTENSION_API_ONLY = YES can prevent following warning when using KeychainAccess from App Extension project.

ld: warning: linking against dylib not safe for use in application extensions: …Carthage/Build/iOS/KeychainAccess.framework/KeychainAccess

is this library compatible with ObjC

i was not able to import this library to an Objc project successfully.
i was reading through the minimum requirement for such compatibility and i noticed that the Swift classes do not carry @objc keyword with them so is this intentional or is it okay to contribute a patch for making the library Objc portable ?

Cannot compile by Xcode7 beta4.

It cannot be compiled with a error "Cannot invoke 'takeUnretainedValue' with no arguments".
takeUnretainedValue 's arguments changed at beta4?

Using KeychainAccess for saving UUID and store after reinstall app

Hi,

I am looking solution for have same ID for device even when user delete app and then install it again. I found that others are using keychain for this. But I've read about some problems that sometimes Keychain returns nil and the second problem could be that ID from keychain would be shared across devices and I really don't want that. I guess that when I set synchronizable to false that there shoudn't be second issue. But what about first one? Is it possible that sometimes Keychain returns nil even if there are saved data? For example link here: soffes/SAMKeychain#75 Should I combine this with NSUserDefaults? When app is launched for first time get ID from keychain and save it to NSUserDefaults for other needs. Thanks for help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.