password_vault 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in password_vault.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jon Druse
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # PasswordVault
2
+
3
+ Really simple CLI for storing passwords securely.
4
+
5
+ ## Installation
6
+
7
+ $ gem install password_vault
8
+
9
+ ## Usage
10
+
11
+ Run pvault to interact with your Vault
12
+
13
+ Here's an example:
14
+
15
+ ![Example](https://www.evernote.com/shard/s9/sh/2ae7fdfc-1dba-40da-a265-c002acbcb299/82e34f321ea2740330831af5344fc8df/res/10639cfa-b442-4125-a521-246eb8a1baf9/skitch.png)
16
+
17
+
18
+ ## Contributing
19
+
20
+ 1. Fork it
21
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
23
+ 4. Push to the branch (`git push origin my-new-feature`)
24
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/pvault ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+ require 'terminal-table'
6
+ require 'clipboard'
7
+ require 'password_vault'
8
+
9
+ program :version, '0.0.1'
10
+ program :description, 'store your passwords safely'
11
+
12
+ default_command :main
13
+
14
+ command :main do |c|
15
+ c.syntax = 'Password Vault'
16
+ c.summary = 'Interact with your password vault'
17
+ c.action do |args, options|
18
+ if !File.exists?(PasswordVault::VaultFile)
19
+ p = ask("Please enter a password for your vault: ") {|q| q.echo = false }
20
+ vault = PasswordVault::Vault.new(p)
21
+ vault.write
22
+ vault.read
23
+ else
24
+ p = ask("Password: ") { |q| q.echo = false }
25
+ vault = PasswordVault::Vault.new(p)
26
+ end
27
+
28
+ begin
29
+ vault.read
30
+ rescue
31
+ puts "you shall not pass!"
32
+ exit
33
+ end
34
+
35
+ puts "type 'help' to see a list of commands"
36
+ loop do
37
+ input = ask_for_array("> ")
38
+ c = input.first
39
+
40
+ if %w(quit q).include?(c)
41
+ break
42
+ end
43
+
44
+ case c
45
+ when "list"
46
+ rows = []
47
+ vault.passwords.each do |p|
48
+ rows << [
49
+ p.name,
50
+ p.username,
51
+ p.url
52
+ ]
53
+ end
54
+
55
+ table = Terminal::Table.new headings: ["Name","Username","URL"], rows: rows
56
+ puts table
57
+ when "add"
58
+ p = PasswordVault::Password.new
59
+ p.name = ask("Name: ")
60
+
61
+ if vault.get_password(p.name)
62
+ puts "entry for #{p.name} already exists, use 'update'"
63
+ else
64
+ p.password = ask("Password: ") { |q| q.echo = false }
65
+ p.username = ask("Username: ")
66
+ p.url = ask("URL: ")
67
+
68
+ vault.passwords << p
69
+
70
+ vault.write
71
+
72
+ puts "added #{p.name} to vault"
73
+ end
74
+ when "copy"
75
+ if input.size == 2
76
+ p = vault.get_password(input.last)
77
+ if p.nil?
78
+ puts "couldn't find password with name #{input.last}"
79
+ redo
80
+ end
81
+ Clipboard.copy(p.password)
82
+ puts "password for #{p.name} copied to your clipboard"
83
+ else
84
+ puts "you must supply exaclty one name to copy"
85
+ end
86
+ when "delete"
87
+ if input.size == 2
88
+ vault.delete_password(input.last)
89
+ vault.write
90
+ puts "deleted #{input.last}"
91
+ else
92
+ puts "you must supply exaclty one name to delete"
93
+ end
94
+ when "update"
95
+ if input.size == 2
96
+ p = vault.get_password(input.last)
97
+
98
+ if p.nil?
99
+ puts "couldn't find password with name #{input.last}"
100
+ redo
101
+ end
102
+
103
+ p.name = ask("Name: ")
104
+ p.password = ask("Password: ") { |q| q.echo = false }
105
+ p.username = ask("Username: ")
106
+ p.url = ask("URL: ")
107
+ vault.write
108
+ else
109
+ puts "you must supply exaclty one name to update"
110
+ end
111
+ when "help"
112
+ puts "commands are: list, add, copy NAME, update NAME, delete NAME, quit"
113
+ else
114
+ puts "#{c}: does not compute"
115
+ end
116
+ end
117
+
118
+
119
+ end
120
+ end
@@ -0,0 +1,5 @@
1
+ class PasswordVault::Password
2
+
3
+ attr_accessor :name, :password, :username, :url
4
+
5
+ end
@@ -0,0 +1,53 @@
1
+ require 'openssl'
2
+ require 'fileutils'
3
+
4
+ class PasswordVault::Vault
5
+
6
+ def initialize(key)
7
+ @key = Digest::SHA512.digest(key)
8
+ end
9
+
10
+ def passwords
11
+ @passwords ||= []
12
+ end
13
+
14
+ def get_password(name)
15
+ found = @passwords.select {|p| p.name == name }
16
+ found.first
17
+ end
18
+
19
+ def delete_password(name)
20
+ if p = get_password(name)
21
+ @passwords -= [p]
22
+ end
23
+ end
24
+
25
+ def write
26
+ File.open(PasswordVault::VaultFile, 'w') {|f| f.write(lock) }
27
+ end
28
+
29
+ def read
30
+ unlock File.read(PasswordVault::VaultFile)
31
+ end
32
+
33
+ def lock
34
+ crypt(:encrypt, dump)
35
+ end
36
+
37
+ def unlock(data)
38
+ dump = crypt(:decrypt, data)
39
+ @passwords = Marshal.load(dump)
40
+ end
41
+
42
+ def dump
43
+ Marshal.dump(passwords)
44
+ end
45
+
46
+ private
47
+ def crypt(mode, data)
48
+ cipher = OpenSSL::Cipher.new 'AES256'
49
+ cipher.send mode
50
+ cipher.key = @key
51
+ cipher.update(data) << cipher.final
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module PasswordVault
2
+ VaultFile = "#{ENV["HOME"]}/.password_vault"
3
+ end
@@ -0,0 +1,3 @@
1
+ module PasswordVault
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "password_vault/version"
2
+ require "password_vault/vault_file"
3
+ require "password_vault/vault"
4
+ require "password_vault/password"
5
+
6
+ require 'terminal-table'
7
+
8
+ module PasswordVault
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'password_vault/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "password_vault"
8
+ spec.version = PasswordVault::VERSION
9
+ spec.authors = ["Jon Druse"]
10
+ spec.email = ["jon@jondruse.com"]
11
+ spec.description = %q{CLI Password Vault}
12
+ spec.summary = %q{CLI Password Vault}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.add_dependency "commander"
21
+ spec.add_dependency "terminal-table"
22
+ spec.add_dependency "clipboard"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "fakefs"
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PasswordVault::Password do
4
+
5
+ let(:p) {PasswordVault::Password.new}
6
+
7
+ it "should store some attribs" do
8
+ p.name = "twitter"
9
+ p.username = "joeshmoe"
10
+ p.password = "youllneverguess"
11
+ p.url = "http://twitter.com"
12
+
13
+ p.name.should == "twitter"
14
+ p.username.should == "joeshmoe"
15
+ p.password.should == "youllneverguess"
16
+ p.url.should == "http://twitter.com"
17
+ end
18
+
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe PasswordVault do
4
+ it 'should have a version number' do
5
+ PasswordVault::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'password_vault'
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require 'fakefs'
3
+
4
+ describe PasswordVault::Vault do
5
+ let(:vault) {PasswordVault::Vault.new('mykey')}
6
+ let(:twitter) {
7
+ p = PasswordVault::Password.new
8
+ p.name = "twitter"
9
+ p.username = "joe.moe"
10
+ p.password = "youllneverguess"
11
+ p
12
+ }
13
+ let(:vp) {
14
+ vault.passwords << twitter
15
+ vault
16
+ }
17
+
18
+ it "new files should have 0 passwords" do
19
+ vault.passwords.size.should == 0
20
+ end
21
+
22
+ it "should add new passwords" do
23
+ twitter
24
+
25
+ vault.passwords << twitter
26
+
27
+ vault.passwords.size.should == 1
28
+ end
29
+
30
+ it "should retrieve passwords by name" do
31
+ vp.get_password("nothere").should be_nil
32
+ vp.get_password("twitter").class.should == PasswordVault::Password
33
+ end
34
+
35
+ it "should delete a password" do
36
+ vp.delete_password("nothere").should be_nil
37
+
38
+ size = vp.passwords.size
39
+ vp.delete_password("twitter")
40
+
41
+ vp.passwords.size.should == (size-1)
42
+ end
43
+
44
+ it "should marshal dump/load" do
45
+ dump = vp.dump
46
+ dump.class.should == String
47
+ loaded = Marshal.load(dump)
48
+ loaded.first.name.should == "twitter"
49
+ end
50
+
51
+ it "should encrypt the stuff" do
52
+ vp.lock.class.should == String
53
+ end
54
+
55
+ it "should decrypt the stuff also" do
56
+ data = vp.lock
57
+ unlocked = vp.unlock(data)
58
+
59
+ unlocked.class.should == Array
60
+ unlocked.first.name.should == "twitter"
61
+ end
62
+
63
+ it "should write/read to/from a file" do
64
+ pending "fakefs not working?"
65
+ File.exists?(PasswordVault::VaultFile).should be_false
66
+ vp.write
67
+ File.exists?(PasswordVault::VaultFile).should be_true
68
+
69
+ vault = PasswordVault::Vault.new("mykey")
70
+ vault.passwords.size.should == 0
71
+
72
+ vault.read
73
+
74
+ vault.passwords.size.should == 1
75
+ end
76
+
77
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: password_vault
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Druse
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: commander
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: terminal-table
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: clipboard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: fakefs
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: CLI Password Vault
127
+ email:
128
+ - jon@jondruse.com
129
+ executables:
130
+ - pvault
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .rspec
136
+ - .travis.yml
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/pvault
142
+ - lib/password_vault.rb
143
+ - lib/password_vault/password.rb
144
+ - lib/password_vault/vault.rb
145
+ - lib/password_vault/vault_file.rb
146
+ - lib/password_vault/version.rb
147
+ - password_vault.gemspec
148
+ - spec/password_spec.rb
149
+ - spec/password_vault_spec.rb
150
+ - spec/spec_helper.rb
151
+ - spec/vault_spec.rb
152
+ homepage: ''
153
+ licenses:
154
+ - MIT
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ segments:
166
+ - 0
167
+ hash: -2860634679747420969
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ segments:
175
+ - 0
176
+ hash: -2860634679747420969
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 1.8.25
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: CLI Password Vault
183
+ test_files:
184
+ - spec/password_spec.rb
185
+ - spec/password_vault_spec.rb
186
+ - spec/spec_helper.rb
187
+ - spec/vault_spec.rb