├── .gitignore ├── Gemfile ├── README.md ├── Rakefile ├── app └── app_delegate.rb ├── lib ├── motion-keychain.rb └── project │ └── motion-keychain.rb ├── license ├── motion-keychain.gemspec ├── resources └── Default-568h@2x.png └── spec └── main_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .repl_history 2 | build 3 | tags 4 | app/pixate_code.rb 5 | resources/*.nib 6 | resources/*.momd 7 | resources/*.storyboardc 8 | .DS_Store 9 | nbproject 10 | .redcar 11 | #*# 12 | *~ 13 | *.sw[po] 14 | *.gem 15 | .eprj 16 | .sass-cache 17 | .idea 18 | .dat*.* 19 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Define all dependencies in your .gemspec file 4 | gemspec 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # motion-keychain 2 | [![Gem Version](https://badge.fury.io/rb/motion-keychain.svg)](http://badge.fury.io/rb/motion-keychain) 3 | 4 | #### Securely store data in RubyMotion. 5 | 6 | The motion-keychain gem is a simple wrapper for Keychain on iOS and OS X. Makes using Keychain APIs as easy as NSUserDefaults. 7 | 8 | ## Installation 9 | 10 | Add this line to your application's Gemfile: 11 | 12 | gem 'motion-keychain' 13 | 14 | And then execute: 15 | 16 | $ bundle 17 | 18 | Or install it yourself as: 19 | 20 | $ gem install motion-keychain 21 | 22 | ## Usage 23 | 24 | Store secure data: 25 | ```ruby 26 | # Storing securely under key 'password' 27 | MotionKeychain.set('password', @password.text) 28 | ``` 29 | 30 | Retrieve secure data: 31 | ```ruby 32 | # Retrieving 'password' content from keychain 33 | @password.text = MotionKeychain.get('password') 34 | ``` 35 | 36 | Wipe secure data: 37 | ```ruby 38 | # User is logging out 39 | MotionKeychain.remove('password') 40 | ``` 41 | 42 | #### Keychain access groups 43 | 44 | If you want the new keychain item to be shared among multiple applications, (i.e. include the kSecAttrAccessGroup key in the attributes dictionary), the value of your key must be the name of a keychain access group to which all of the programs that will share this item belong. 45 | 46 | This area needs more field-testing but for RubyMotion this means setting the entitlements in your Rakefile. E.G. 47 | ```ruby 48 | app.identifier = 'com.apple.myapp' 49 | app.seed_id = '659823F3DC53' 50 | app.entitlements['keychain-access-groups'] = [app.seed_id + '.' + app.identifier] 51 | ``` 52 | 53 | 54 | ## TODO 55 | 56 | * Remove cocoapod dependency and move to pure RubyMotion implementation. (v0.1.0) 57 | 58 | ## Contributing 59 | 60 | 1. Fork it 61 | 2. Create your feature branch (`git checkout -b my-new-feature`) 62 | 3. Commit your changes (`git commit -am 'Add some feature'`) 63 | 4. Push to the branch (`git push origin my-new-feature`) 64 | 5. Create new Pull Request 65 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | $:.unshift("/Library/RubyMotion/lib") 3 | require 'motion/project/template/ios' 4 | require './lib/motion-keychain' 5 | 6 | begin 7 | require 'bundler' 8 | require 'motion/project/template/gem/gem_tasks' 9 | Bundler.require 10 | rescue LoadError 11 | end 12 | 13 | Motion::Project::App.setup do |app| 14 | # Use `rake config' to see complete project settings. 15 | app.name = 'motion-keychain' 16 | end 17 | -------------------------------------------------------------------------------- /app/app_delegate.rb: -------------------------------------------------------------------------------- 1 | class AppDelegate 2 | def application(application, didFinishLaunchingWithOptions:launchOptions) 3 | true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/motion-keychain.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | unless defined?(Motion::Project::Config) 4 | raise "This file must be required within a RubyMotion project Rakefile." 5 | end 6 | 7 | lib_dir_path = File.dirname(File.expand_path(__FILE__)) 8 | Motion::Project::App.setup do |app| 9 | app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb"))) 10 | 11 | # Add needed security Framework 12 | app.frameworks += ['Security'] 13 | 14 | # For now depending on pod 15 | app.pods do 16 | pod 'UICKeyChainStore' 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/project/motion-keychain.rb: -------------------------------------------------------------------------------- 1 | class MotionKeychain 2 | class << self 3 | SERVICE = NSBundle.mainBundle.bundleIdentifier 4 | STORE = UICKeyChainStore.keyChainStoreWithService(SERVICE) 5 | 6 | def store 7 | STORE 8 | end 9 | 10 | def get(key) 11 | STORE.stringForKey(key.to_s) 12 | end 13 | 14 | def set(key, value) 15 | STORE.setString(value, forKey: key.to_s) 16 | STORE.synchronize 17 | {key: value} 18 | end 19 | 20 | def remove(key) 21 | STORE.removeItemForKey(key.to_s) 22 | STORE.synchronize 23 | true 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Iconoclast Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /motion-keychain.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | VERSION = "0.0.1" 3 | 4 | Gem::Specification.new do |spec| 5 | spec.name = "motion-keychain" 6 | spec.version = VERSION 7 | spec.authors = ["Gant"] 8 | spec.email = ["Gant@iconoclastlabs.com"] 9 | spec.description = "Simple wrapper for Keychain on iOS and OS X." 10 | spec.summary = "The motion-keychain gem is a simple wrapper for Keychain on iOS and OS X. Makes using Keychain APIs as easy as NSUserDefaults." 11 | spec.homepage = "https://github.com/IconoclastLabs/motion-keychain" 12 | spec.license = "MIT" 13 | 14 | files = [] 15 | files << 'README.md' 16 | files.concat(Dir.glob('lib/**/*.rb')) 17 | spec.files = files 18 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 19 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 20 | spec.require_paths = ["lib"] 21 | 22 | spec.add_dependency "motion-cocoapods", ">= 1.4.1" 23 | 24 | spec.add_development_dependency "rake" 25 | end 26 | -------------------------------------------------------------------------------- /resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IconoclastLabs/motion-keychain/73e613663c122b07e788d6acada7b1a54d9777b4/resources/Default-568h@2x.png -------------------------------------------------------------------------------- /spec/main_spec.rb: -------------------------------------------------------------------------------- 1 | describe "Application 'motion-keychain'" do 2 | before do 3 | @app = UIApplication.sharedApplication 4 | end 5 | 6 | it "has one window" do 7 | @app.windows.size.should == 1 8 | end 9 | end 10 | --------------------------------------------------------------------------------