keylime 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a81357c7a678f11061991964b11c12e7bdfdd144
4
+ data.tar.gz: 72d703f5749bba76f214e23b1670a7d4dc960043
5
+ SHA512:
6
+ metadata.gz: d2142d8176bd0e05218118caa4e3ecf2b4101ecacfb50250f23c93ce69df9264fb1ae138fc76b64df9f3c64bbd914b6e51fb54cb602aafe8c6cff5a9d0062df2
7
+ data.tar.gz: f3645e6405ec6c4854db623d5bdc26eb685da4275f769e917a4ac5ea79e406d5be1d4281a4dd0f30a654a5ac526e0494138f9727f334f9d18e575678a2f848b4
@@ -0,0 +1,5 @@
1
+ pkg/*.gem
2
+ coverage/
3
+ .coveralls.yml
4
+ .bundle
5
+ Gemfile.lock
@@ -0,0 +1,11 @@
1
+ item do
2
+ expected do
3
+ static
4
+ set 'green'
5
+ end
6
+
7
+ actual do
8
+ gemnasium
9
+ slug 'akerl/keylime'
10
+ end
11
+ end
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
@@ -0,0 +1,2 @@
1
+ Encoding:
2
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Les Aker
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
13
+ all 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
21
+ THE SOFTWARE.
22
+
@@ -0,0 +1,69 @@
1
+ keylime
2
+ =========
3
+
4
+ [![Gem Version](https://img.shields.io/gem/v/keylime.svg)](https://rubygems.org/gems/keylime)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/akerl/keylime.svg)](https://gemnasium.com/akerl/keylime)
6
+ [![Build Status](https://img.shields.io/circleci/project/akerl/keylime.svg)](https://circleci.com/gh/akerl/keylime)
7
+ [![Coverage Status](https://img.shields.io/codecov/c/github/akerl/keylime.svg)](https://codecov.io/github/akerl/keylime)
8
+ [![Code Quality](https://img.shields.io/codacy/b84e51f348094a33b2982bfb73adc645.svg)](https://www.codacy.com/app/akerl/keylime)
9
+ [![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license)
10
+
11
+ Simple wrapper for using Mac Keychain
12
+
13
+ ## Usage
14
+
15
+ Create a Keylime object, which represents a single credential (which may or may not be stored in Keychain yet):
16
+
17
+ ```
18
+ require 'keylime'
19
+ my_credential = Keylime.new(server: 'https://example.org', account: 'akerl')
20
+ ```
21
+
22
+ You can specify any of the following attributes by providing them:
23
+
24
+ * account: the username field
25
+ * server: the site the credential is for (if it's an "internet password", which just means a credential that was created with a server set)
26
+ * label: the name of the credential, generally describing what it's used for
27
+ * service: the "Where" field in keychain access, used to describe what the credential is used for
28
+ * There are other attributes, which you can look up with `security find-generic-password -h` and `security find-internet-password -h`, but these are the most commonly useful
29
+
30
+ Once you've created the credential object, you can get its value in one of two ways:
31
+
32
+ ```
33
+ require 'keylime'
34
+ my_credential = Keylime.new(server: 'https://example.org', account: 'akerl')
35
+
36
+ # This will get the value, and return nil if it doesn't exist:
37
+ value = my_credential.get
38
+
39
+ # This will get the value, and prompt the user to input the value if it doesn't exist:
40
+ value = my_credential.get!('Please enter example.org password')
41
+ ```
42
+
43
+ If you know the password via some other means, you can directly set it with .set():
44
+
45
+ ```
46
+ require 'keylime'
47
+ my_credential = Keylime.new(server: 'https://example.org', account: 'akerl')
48
+
49
+ secret = 'foobar'
50
+ my_credential.set(secret)
51
+ ```
52
+
53
+ You can also delete a secret using .delete():
54
+
55
+ ```
56
+ require 'keylime'
57
+ my_credential = Keylime.new(server: 'https://example.org', account: 'akerl')
58
+
59
+ my_credential.delete!
60
+ ```
61
+
62
+ ## Installation
63
+
64
+ gem install keylime
65
+
66
+ ## License
67
+
68
+ keylime is released under the MIT License. See the bundled LICENSE file for details.
69
+
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ desc 'Run tests'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ desc 'Run Rubocop on the gem'
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
10
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
11
+ task.fail_on_error = true
12
+ end
13
+
14
+ task default: [:spec, :rubocop, :build, :install]
@@ -0,0 +1,12 @@
1
+ dependencies:
2
+ override:
3
+ - 'rvm-exec 1.9.3-p551 bundle install'
4
+ - 'rvm-exec 2.0.0-p645 bundle install'
5
+ - 'rvm-exec 2.1.6 bundle install'
6
+ - 'rvm-exec 2.2.2 bundle install'
7
+ test:
8
+ override:
9
+ - 'rvm-exec 1.9.3-p551 bundle exec rake'
10
+ - 'rvm-exec 2.0.0-p645 bundle exec rake'
11
+ - 'rvm-exec 2.1.6 bundle exec rake'
12
+ - 'rvm-exec 2.2.2 bundle exec rake'
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'keylime'
3
+ s.version = '0.0.3'
4
+ s.date = Time.now.strftime('%Y-%m-%d')
5
+
6
+ s.summary = 'Simple wrapper for using Mac Keychain'
7
+ s.description = "Simple wrapper for using Mac Keychain"
8
+ s.authors = ['Les Aker']
9
+ s.email = 'me@lesaker.org'
10
+ s.homepage = 'https://github.com/akerl/keylime'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files`.split
14
+ s.test_files = `git ls-files spec/*`.split
15
+
16
+ s.add_dependency 'ruby-keychain', '~> 0.3.0'
17
+ s.add_dependency 'userinput', '~> 1.0.0'
18
+
19
+ s.add_development_dependency 'rubocop', '~> 0.39.0'
20
+ s.add_development_dependency 'rake', '~> 11.1.0'
21
+ s.add_development_dependency 'codecov', '~> 0.1.1'
22
+ s.add_development_dependency 'rspec', '~> 3.4.0'
23
+ s.add_development_dependency 'fuubar', '~> 2.0.0'
24
+ end
@@ -0,0 +1,11 @@
1
+ ##
2
+ # Keylime, a simple tool for interacting with OSX's keychain
3
+ module Keylime
4
+ class << self
5
+ def new(*args)
6
+ self::Credential.new(*args)
7
+ end
8
+ end
9
+ end
10
+
11
+ require 'keylime/credential'
@@ -0,0 +1,59 @@
1
+ require 'keychain'
2
+ require 'userinput'
3
+
4
+ module Keylime
5
+ ##
6
+ # Easy wrapper around getting and setting secrets
7
+ class Credential
8
+ def initialize(params = {})
9
+ @options = params
10
+ @enabled = RUBY_PLATFORM =~ /darwin/ || ENV['CI']
11
+ end
12
+
13
+ def get
14
+ return unless @enabled
15
+ keychain_segment.where(@options).first
16
+ end
17
+
18
+ def get!(message)
19
+ get || prompt(message)
20
+ end
21
+
22
+ def set(value)
23
+ delete!
24
+ keychain_segment.create(@options.merge(password: value))
25
+ end
26
+
27
+ def delete!
28
+ get && keychain_segment.where(@options).first.delete
29
+ nil
30
+ end
31
+
32
+ private
33
+
34
+ def prompt(message)
35
+ set UserInput.new(
36
+ message: message,
37
+ secret: true,
38
+ attempts: 3,
39
+ validation: /.+/
40
+ ).ask
41
+ end
42
+
43
+ def keychain
44
+ @keychain ||= if @options[:keychain]
45
+ Keychain.open(@options[:keychain])
46
+ else
47
+ Keychain
48
+ end
49
+ end
50
+
51
+ def key_type
52
+ @options[:server] ? :internet_passwords : :generic_passwords
53
+ end
54
+
55
+ def keychain_segment
56
+ @keychain_segment ||= keychain.send(key_type)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+
4
+ describe Keylime::Credential do
5
+ let(:subject) { Keylime.new(service: 'testing') }
6
+ let(:secret) { SecureRandom.hex }
7
+
8
+ it 'accepts a keychain path' do
9
+ credential = Keylime.new(keychain: 'other/file', service: 'testing')
10
+ credential.set secret
11
+ expect(credential.get.keychain).to eql 'other/file'
12
+ end
13
+ it 'can get internet passwords' do
14
+ credential = Keylime.new(server: 'https://example.org', account: 'testing')
15
+ credential.set secret
16
+ expect(credential.get.password).to eql secret
17
+ end
18
+ it 'can get generic passwords' do
19
+ subject.set secret
20
+ expect(subject.get.password).to eql secret
21
+ end
22
+
23
+ describe '#get' do
24
+ it 'returns a credential if it exists' do
25
+ subject.set secret
26
+ expect(subject.get.password).to eql secret
27
+ end
28
+ it 'returns nil if the credential does not exist' do
29
+ expect(subject.get).to be_nil
30
+ end
31
+ end
32
+
33
+ describe '#get!' do
34
+ it 'returns a credential if it exists' do
35
+ subject.set secret
36
+ expect(subject.get.password).to eql secret
37
+ end
38
+ it 'prompts the user if the credential does not exist' do
39
+ allow(STDIN).to receive(:gets) { "#{secret}\n" }
40
+ expect(STDOUT).to receive(:print).with('Question? ')
41
+ expect(subject.get!('Question').password).to eql secret
42
+ end
43
+ end
44
+
45
+ describe '#set' do
46
+ it 'sets the value of the credential' do
47
+ subject.set secret
48
+ expect(subject.get.password).to eql secret
49
+ end
50
+ it 'overwrites any existing credential' do
51
+ subject.set 'oldvalue'
52
+ expect(subject.get.password).to eql 'oldvalue'
53
+ subject.set secret
54
+ expect(subject.get.password).to eql secret
55
+ end
56
+ end
57
+
58
+ describe '#delete!' do
59
+ it 'removes the credential' do
60
+ subject.set secret
61
+ expect(subject.get.password).to eql secret
62
+ subject.delete!
63
+ expect(subject.get).to be_nil
64
+ end
65
+ it 'succeeds if credential does not exist' do
66
+ subject.delete!
67
+ expect(subject.get).to be_nil
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keylime do
4
+ describe '#new' do
5
+ it 'creates Credential objects' do
6
+ expect(Keylime.new).to be_an_instance_of Keylime::Credential
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ if ENV['CI'] == 'true'
2
+ require 'simplecov'
3
+ require 'codecov'
4
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
8
+ end
9
+
10
+ require 'rspec'
11
+ $LOAD_PATH.unshift File.expand_path('../stub', __FILE__)
12
+ require 'keylime'
@@ -0,0 +1,78 @@
1
+ require 'ostruct'
2
+
3
+ module Keychain
4
+ class << self
5
+ def generic_passwords
6
+ KeychainFile.new.generic_passwords
7
+ end
8
+
9
+ def internet_passwords
10
+ KeychainFile.new.internet_passwords
11
+ end
12
+
13
+ def open(path)
14
+ KeychainFile.new(path)
15
+ end
16
+
17
+ def nuke_list
18
+ @nuke_list ||= []
19
+ end
20
+
21
+ def empty_nuke_list!
22
+ @nuke_list = []
23
+ end
24
+ end
25
+
26
+ class KeychainFile
27
+ def initialize(path = nil)
28
+ @keychain = path
29
+ end
30
+
31
+ def generic_passwords
32
+ Passwords.new(@keychain)
33
+ end
34
+
35
+ def internet_passwords
36
+ InternetPasswords.new(@keychain)
37
+ end
38
+ end
39
+
40
+ class Passwords
41
+ def initialize(keychain = nil)
42
+ @keychain = keychain
43
+ end
44
+
45
+ def where(params)
46
+ cache.find_all do |x|
47
+ hash = x.marshal_dump
48
+ params.all? { |k, v| hash[k] == v }
49
+ end
50
+ end
51
+
52
+ def create(params)
53
+ struct = OpenStruct.new(params)
54
+ struct.keychain = @keychain
55
+ cache << struct
56
+ struct
57
+ end
58
+
59
+ private
60
+
61
+ def cache
62
+ @cache ||= []
63
+ @cache.reject! { |x| Keychain.nuke_list.include? x.hash }
64
+ Keychain.empty_nuke_list!
65
+ @cache
66
+ end
67
+ end
68
+
69
+ class InternetPasswords < Passwords
70
+ end
71
+ end
72
+
73
+ class OpenStruct
74
+ def delete
75
+ Keychain.nuke_list << hash
76
+ super
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keylime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Les Aker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-keychain
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: userinput
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.39.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.39.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 11.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 11.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: codecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: fuubar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.0
111
+ description: Simple wrapper for using Mac Keychain
112
+ email: me@lesaker.org
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ".gitignore"
118
+ - ".prospectus"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - Gemfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - circle.yml
126
+ - keylime.gemspec
127
+ - lib/keylime.rb
128
+ - lib/keylime/credential.rb
129
+ - spec/keylime/credential_spec.rb
130
+ - spec/keylime_spec.rb
131
+ - spec/spec_helper.rb
132
+ - spec/stub/keychain.rb
133
+ homepage: https://github.com/akerl/keylime
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.5.1
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Simple wrapper for using Mac Keychain
157
+ test_files:
158
+ - spec/keylime/credential_spec.rb
159
+ - spec/keylime_spec.rb
160
+ - spec/spec_helper.rb
161
+ - spec/stub/keychain.rb