Git Product home page Git Product logo

cordova-plugin-ios-keychain's Introduction

Keychain Plugin for Apache Cordova

created by Shazron Abdullah

Updated by Max Lynch [email protected]

Maintenance Status:

Looking for maintainer. PRs and community contributions welcome.

Alternative: Enterprise Keychain and Keystore

For enterprise use cases requiring secret storage with biometric authentication for iOS (keychain) and Android (Keystore), see Identity Vault.

Installation

cordova plugin add https://github.com/ionic-team/cordova-plugin-ios-keychain

iCloud keychain enabled

iCloud keychain synchonizing is enabled, so the keychain will be mirrored across all devices if the user is signed in to iCloud (Settings > iCloud) and has iCloud keychain turned on (Settings > iCloud > Keychain)

Usage

See the example folder for example usage.

/*
 Retrieves a value for a key
 
 @param successCallback returns the value as the argument to the callback when successful
 @param failureCallback returns the error string as the argument to the callback, for a failure
 @param key the key to retrieve
 @param TouchIDMessage the message to show underneath the TouchID prompt (if any)
 */
Keychain.get(successCallback, failureCallback, 'key', 'TouchID Message');

/*
 Sets a value for a key
 
 @param successCallback returns when successful
 @param failureCallback returns the error string as the argument to the callback, for a failure
 @param key the key to set
 @param value the value to set
 @param useTouchID whether to store the value with security such that TouchID will be needed to grab it
 */
Keychain.set(successCallback, failureCallback, 'key', 'value', useTouchID);

/*
 Removes a value for a key
 
 @param successCallback returns when successful
 @param failureCallback returns the error string as the argument to the callback
 @param key the key to remove
 */
Keychain.remove(successCallback, failureCallback, 'key');

/*
 Sets a JSON value for a key 
 
 @param successCallback returns when successful
 @param failureCallback returns the error string as the argument to the callback, for a failure
 @param key the key to set
 @param value the value to set
 @param useTouchID whether to store the value with security such that TouchID will be needed to grab it
 */
Keychain.setJson(successCallback, failureCallback, 'key', 'value', useTouchID);

/*
 Gets a JSON value for a key 
 
 @param successCallback returns when successful
 @param failureCallback returns the error string as the argument to the callback, for a failure
 @param key the key to set
 @param value the value to set
 @param useTouchID whether to store the value with security such that TouchID will be needed to grab it
 */
Keychain.getJson(successCallback, failureCallback, 'key', useTouchID);

License

Apache 2.0 License except for the Auth0 SimpelKeychain code that is under MIT

cordova-plugin-ios-keychain's People

Contributors

ajcrites avatar danielsogl avatar inorganik avatar jacquesdev avatar jagregory avatar mlynch avatar r3ggi avatar shazron avatar tmct avatar ucci 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-ios-keychain's Issues

Pressing cancel returns null, same if the key doesn't exist

On the passcode screen, if the user presses the cancel button the promise of the keychain.get resolves to null, but it will also resolve to null if the key you're trying to get doesn't exist.
This is major because then you are not able to tell if the key doesn't exist or if the user just pressed the cancel button.

Not iCloud Keychain enabled

Even though the documentation states it is iCloud enabled it is not. It is missing the kSecAttrSynchronizable attribute to allow synchronization. I was having issues with getting it to work properly and by adding the kSecAttrSynchronizable to the basequery attributes in A0SimpleKeychain.m I was able to resolve the issue, as provided by the wip-icloud branch.

I see that Pull 17 seems to address an issue with that branch.

Andy

Set and Get value that return null

Hi,
i'm new to iOS and keychain and first i need to understand the usage better,
but i need to change a few things because a guy who did some security checks on my app noticed that the app needs to improve the security using the "kSecAttrAccessibleWhenUnlockedThisDeviceOnly" attribute instead of "kSecAttrAccessibleWhenUnlocked" for some keychain items ...
he wrote to me: "It was possible to identify an issue with the data stored in the iOS keychain through dumping of keychain data or reading backup data (iTunes)"

So i tried using cordova-plugin-ios-keychain to make a change to the keychain items,
but i think i don't understand what is the item/key i should change and if i'm doing it right.

I read Apple documentation and the key that have this possible attribute is "kSecAttrAccessible" ,
so i try to use the plugin like:
this.keychain.get('kSecAttrAccessible') .then(value => console.log('Keychain got value: ', value)) .catch(err => console.log('Keychain Error getting: ',err));

but it return always null value,
if i try to set the key like:
this.keychain.set('kSecAttrAccessible', 'kSecAttrAccessibleWhenUnlockedThisDeviceOnly').then(() => { this.keychain.get('kSecAttrAccessible') .then(value => console.log('Keychain got value: ', value)) .catch(err => console.log('Keychain Error getting: ',err)); }) .catch(err => console.log('Keychain Error setting: ', err));

the app crash ..

Can you help me? suggest where am I wrong?

I used Ionic Framework v3 with Angular v5.*

Can not set data for ios12

Hello,

I am not able to set keychain. the app crashes with the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull boolValue]: unrecognized selector sent to instance 0x111f02f08'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000111c9029b __exceptionPreprocess + 331
	1   libobjc.A.dylib                     0x0000000110a70735 objc_exception_throw + 48
	2   CoreFoundation                      0x0000000111caefa4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
	3   CoreFoundation                      0x0000000111c94fb6 ___forwarding___ + 1446
	4   CoreFoundation                      0x0000000111c96e88 _CF_forwarding_prep_0 + 120
	5   تحدي العرب                 0x000000010c15c765 __19-[CDVKeychain set:]_block_invoke + 437
	6   libdispatch.dylib                   0x000000011642b5d1 _dispatch_call_block_and_release + 12
	7   libdispatch.dylib                   0x000000011642c63e _dispatch_client_callout + 8
	8   libdispatch.dylib                   0x000000011642f0a0 _dispatch_queue_override_invoke + 1028
	9   libdispatch.dylib                   0x000000011643d028 _dispatch_root_queue_drain + 351
	10  libdispatch.dylib                   0x000000011643d9cd _dispatch_worker_thread2 + 130
	11  libsystem_pthread.dylib             0x0000000116818169 _pthread_wqthread + 1387
	12  libsystem_pthread.dylib             0x0000000116817be9 start_wqthread + 13

I test it on ios12.0.1.

Plugin attempts to use TouchID when it shouldn't

When setting a key/value and passing false for the useTouchId parameter, the plugin attempts to use TouchID anyway.

i.e.

var useTouchId = false;

Keychain.set(onSuccess, onFail, 'key', 'value', useTouchId);

I would expect this not to try to use TouchId to store the key/value. However if I inspect CDVKeychain.m#set then I can see that on converting the relevant command argument to a boolean it's incorrectly interpreting it as true.

See:
screen shot 2016-08-11 at 09 44 58

Is it just expecting a non-boolean argument for `useTouchId, or is it just generally broken?

Also, even if it has been told to use TouchID, shouldn't it ignore that if the device doesn't support it? I believe the plugin may be broken for me due to it trying to save everything with touch ID on a device that doesn't support it (iPad 2 with iOS9).

Keychain.get always returns null on iOS8

Everything seems to work on iOS 9.3, but on iOS 8 I always get back null. Is there anything I can do to help debug this? I've stepped through some Obj-c code and all I can determine is that OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &data); results in a status of -50 which I believe means "client has neither application-identifier nor keychain-access-groups entitlements".

Edit: [email protected], xcode 7.3.1

Installation broken with Cordova 7.0.0

I get this error when I try to run the install step from README.md:

$ cordova plugin add https://github.com/driftyco/cordova-plugin-ios-keychain -d
No scripts found for hook "before_plugin_add".
Calling plugman.fetch on plugin "https://github.com/driftyco/cordova-plugin-ios-keychain"
saving
Running command: npm install https://github.com/driftyco/cordova-plugin-ios-keychain --save
Command finished with error code 235: npm install,https://github.com/driftyco/cordova-plugin-ios-keychain,--save
Error: Failed to fetch plugin https://github.com/driftyco/cordova-plugin-ios-keychain via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: npm: Command failed with exit code 235 Error output:
npm ERR! addLocal Could not install /var/folders/j7/gkwgxcp90gx2nqk08bht52xm0000gn/T/npm-9762-b7e4fc06/git-cache-23e5dc94/d9bbf389e7dad950452e73d72131573472f0a25f
npm ERR! code EISDIR
npm ERR! errno -21
npm ERR! syscall read
npm ERR! eisdir EISDIR: illegal operation on a directory, read
npm ERR! eisdir This is most likely not a problem with npm itself
npm ERR! eisdir and is related to npm not being able to find a package.json in
npm ERR! eisdir a package you are trying to install.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yeldarb/.npm/_logs/2017-05-11T20_10_01_038Z-debug.log

iOS Keychain Sharing

Hello developers!

Thank you very much for implementing this plugin. It is very easy to use and has a clean, simple implementation. However, my team is hoping to use this plugin in order to access a shared Keychain across multiple apps for our company, and are struggling to come up with a solution.

We have been unable to find a way to specify an accessGroup within your plugin, even after modification of the .m files within src/ios. On two separate apps, we have enabled Keychain Sharing through XCode, given them both the same Keychain Group name within their .entitlements files, and also enabled iCloud for good measure through our Apple Developer site. They both use the same Bundle Seed as well.

Would you be able to shed any light on how we might implement Keychain Sharing using your plugin? Any help or suggestions would be greatly appreciated.

Is it possible to read values with this plugin saved in Safari?

I tried to look for answer on the web with no luck.
So just asking here.
Is it possible to log in to the app form with data saved with Safari in keychain? Or is there some restriction from access to keychain data from other apps?

I see that this is possible to read any saved data with Keychain Access but you need to enter master password. Maybe on mobile it may be somehow shared via TouchID?

Thanks in advance.

Crashing

I upgraded from shazron version 3.0.0 to driftyco 3.0.1 and it just froze up when calling.

I diffed the changes and can't see anything obvious, just looks like an extra param added for sync yes/no.

So i forked shazron:old and am using that version which works perfectly.

I didn't spend too much time investigating exact fault as it already took me hours to track it down to this plugin upgrade. I recently upgraded to ios 10, not sure if related.

Transitioning from shazron to diftyco?

I am using shazron's KeyChain to store a pin. How can I read that pin and store it afresh using diftyco's updated plugin? I need to do this under an iOS 10 build.

Thanks,
Scott

.get return null on iOS 10.1

Hi,

The .get resource always return null on iOS 10. But, on any other version its fine.

Any error is throwed. The .get executes successfully, but without data.

Cannot install as suggested `Error: Failed to fetch plugin`

When running commands as specified in the Readme or on Ionic Native Documentation, I receive the following output:

$ ionic cordova plugin add cordova-plugin-ios-keychain --verbose
  ionic:cli-utils Terminal info: { tty: true, ci: false } +0ms
  ionic:cli-utils CLI global options: { _: [ 'cordova', 'plugin', 'add', 'cordova-plugin-ios-keychain' ], help: null, h: null, verbose: true, quiet: null, interactive: true, color: true, confirm: null, json: null, project: null, '--': [] } +117ms
  ionic:cli-utils:lib:environment Environment open. +0ms
  ionic:cli-utils:lib:project Project type from config: Ionic Angular 3 (ionic-angular) +0ms
  ionic:cli-utils Project name: undefined +5ms
  ionic:cli Context: { binPath: '/Users/matt/.npm-global/lib/node_modules/ionic/bin/ionic', libPath: '/Users/matt/.npm-global/lib/node_modules/ionic', execPath: '/Users/matt/project/patient-portal', version: '4.0.1' } +0ms
  ionic:cli-utils:lib:integrations:cordova:config Using config.xml: /Users/matt/project/patient-portal/config.xml +0ms
> cordova plugin add cordova-plugin-ios-keychain --verbose --save
No scripts found for hook "before_plugin_add".
No version specified for cordova-plugin-ios-keychain, retrieving version from package.json
Calling plugman.fetch on plugin "git+https://github.com/ionic-team/cordova-plugin-ios-keychain.git"
saving
Running command: npm install git+https://github.com/ionic-team/cordova-plugin-ios-keychain.git --production --save
Command finished with error code 0: npm install,git+https://github.com/ionic-team/cordova-plugin-ios-keychain.git,--production,--save
Error: Failed to fetch plugin git+https://github.com/ionic-team/cordova-plugin-ios-keychain.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Failed to get absolute path to installed module
[ERROR] An error occurred while running subprocess cordova.

        cordova plugin add cordova-plugin-ios-keychain --verbose --save exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.
  ionic:cli-framework:utils:process onBeforeExit handler: process.exit received +0ms
  ionic:cli-framework:utils:process onBeforeExit handler: running 1 queued functions +1ms
  ionic:cli-framework:utils:process onBeforeExit handler: exiting (exit code 1) +0ms

Any suggestions? Thanks!

plugin doesn't work with iOS 10

I can not get the plugin to work with iOS 10 targets. I am testing with both SDK 9.3 and SDK 10.0.
Builds with both SDKs work fine on iOS 9.3 targets, but, not on iOS 10 targets.

Something, has apparently changed with how iOS 10 handles keychains.

this plugin always returns null in success handler and it does not store anything in keychain

old plugin (verion 1.0) did work till now. but when i try to use updated plugin with following change
remove var kc = new Keychain()... instead use global Keychain and instead of getforKey.. i am using get(..) as per readme file. (providing the 'key' and removing servicename)

but its not working in ios11. and yes i do have keychain sharing enabled in xcode ? any idea how to fix this .. please..

more details.. when key is not found. it returns null.. in the previous version it was going in the fail function. if key is not found. then it should not go to success..

Callbacks always return `null`

I've tried using this plugin as described in README.md but I can't seem to get it to work. There are no errors, but on setting and getting a key/value the success callback is always called with null as the only argument.

Am I doing something wrong?

See below output which was run on an iPad running iOS9:

screen shot 2016-08-11 at 09 33 32

I'd expect the final call, Keychain.get(onSuccess, onFail, 'someKey', 'message') to call the success callback with value (the string set in the previous call). This doesn't happen.

Example code isn't valid

It looks like the example in example/index.js is out of date (possibly just not updated after the implementation was changed from the original shazron/KeychainPlugin repository.

e.g. the example shows using the plugin as new Keychain() which won't work (example in README.md shows just using the global Keychain as Keychain.get, etc.)

Add Keychain reference on window object

I am using the following plugin: ng-persist , which uses shazron's original KeychainPlugin as a dependency.

I am trying to swap out this fork instead for shazron's original KeychainPlugin, and it looks like the original plugin adds a reference to the Keychain object on the window object here. This reference is used in ng-persist, and so using the current fork doesn't work because it can't find the Keychain object (on the window object).

If you could add this reference - or suggest an alternative fix that would be great!

Store Passwords to reuse with password Autofill

Hi,

Sorry but this off. Is this possible to store with this plugins credentials to use it with iOS password Autofill?

I have tried to store a key-value data but then when I click into a ion-input and then into 'Password bar' the value not appears.

Is this possible?

How to manually clear the key outside of the app? (ios)

Is there a way on iOS to clear out a specific key/value outside of the app? I know this is more of a general iOS question and not something specific to the plugin but it would be nice if documentation helped to explain more about how the keychain works, or at least point to apple documentation for it.

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.