keystorage 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +35 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/keystorage +2 -0
- data/bin/keystorage.rb +7 -0
- data/lib/keystorage/cli.rb +43 -0
- data/lib/keystorage/command/base.rb +26 -0
- data/lib/keystorage/command/get.rb +29 -0
- data/lib/keystorage/command/help.rb +14 -0
- data/lib/keystorage/command/list.rb +28 -0
- data/lib/keystorage/command/set.rb +25 -0
- data/lib/keystorage/commands.rb +26 -0
- data/lib/keystorage/manager.rb +63 -0
- data/test/helper.rb +18 -0
- data/test/test_keystorage.rb +7 -0
- metadata +145 -0
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Yoshihiro TAKAHARA
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= keystorage
|
2
|
+
|
3
|
+
Simple password storage command.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
sudo gem install keystrage
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
Usage: keystorage [options] command [command options] args...
|
12
|
+
--help show this message
|
13
|
+
-f, --file=FILE file to store password
|
14
|
+
|
15
|
+
=== Commands
|
16
|
+
|
17
|
+
* list [group]
|
18
|
+
* set group name value
|
19
|
+
* get group name
|
20
|
+
|
21
|
+
== Contributing to keystorage
|
22
|
+
|
23
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
24
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
25
|
+
* Fork the project
|
26
|
+
* Start a feature/bugfix branch
|
27
|
+
* Commit and push until you are happy with your contribution
|
28
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
29
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
30
|
+
|
31
|
+
== Copyright
|
32
|
+
|
33
|
+
Copyright (c) 2011 Yoshihiro TAKAHARA. See LICENSE.txt for
|
34
|
+
further details.
|
35
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "keystorage"
|
16
|
+
gem.homepage = "http://github.com/tumf/keystorage"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Simple password storage command}
|
19
|
+
gem.description = %Q{This is a command to store and manage your passwords.}
|
20
|
+
gem.email = "y.takahara@gmail.com"
|
21
|
+
gem.authors = ["Yoshihiro TAKAHARA"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "keystorage #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/keystorage
ADDED
data/bin/keystorage.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'keystorage/commands'
|
3
|
+
|
4
|
+
module Keystorage
|
5
|
+
class CLI
|
6
|
+
def initialize(argv)
|
7
|
+
@options = Hash.new
|
8
|
+
@options[:file] = ENV["HOME"]+"/.keystore"
|
9
|
+
@argv = argv.clone
|
10
|
+
@opt = OptionParser.new
|
11
|
+
@opt.banner="Usage: keystorage [options] command [command options] args..."
|
12
|
+
@opt.on('--help', 'show this message') { usage; exit }
|
13
|
+
@opt.on('-f FILE','--file=FILE', 'file to store password') { |v|
|
14
|
+
@options[:file] = v;
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def usage
|
19
|
+
puts @opt;
|
20
|
+
puts "Commands:"
|
21
|
+
@commands = ["list","set","get","help"]
|
22
|
+
@commands.each do |m|
|
23
|
+
puts " "+m
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute
|
28
|
+
argv = @opt.parse(@argv)
|
29
|
+
command = argv.shift
|
30
|
+
unless command
|
31
|
+
usage;exit
|
32
|
+
end
|
33
|
+
Commands.send(command,argv,@options)
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def run(argv)
|
38
|
+
self.new(argv).execute
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Keystorage
|
2
|
+
module Command
|
3
|
+
class Base
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@file = options[:file]
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def run(argv,options)
|
11
|
+
begin
|
12
|
+
self.new(options).execute(argv)
|
13
|
+
rescue =>e
|
14
|
+
puts "Error: \n %s\n\n" % e
|
15
|
+
puts help
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def help
|
20
|
+
"TODO: HELP IS NOT DESCRIBED YET."
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'keystorage/command/base'
|
2
|
+
|
3
|
+
module Keystorage
|
4
|
+
module Command
|
5
|
+
class Get < Base
|
6
|
+
def execute(argv)
|
7
|
+
group = argv.shift
|
8
|
+
raise "missing parameter" unless group
|
9
|
+
|
10
|
+
name = argv.shift
|
11
|
+
ks = Manager.new(@file)
|
12
|
+
data = ks.get(group,name)
|
13
|
+
raise "missing %s " % [group] unless data
|
14
|
+
puts data
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def help
|
19
|
+
"Description:
|
20
|
+
get key from file
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
keystrage [options] get groups [name]
|
24
|
+
"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'keystorage/command/base'
|
2
|
+
require 'keystorage/manager'
|
3
|
+
|
4
|
+
module Keystorage
|
5
|
+
module Command
|
6
|
+
class List < Base
|
7
|
+
def execute(argv)
|
8
|
+
site = argv.shift
|
9
|
+
ks = Manager.new(@file)
|
10
|
+
ks.list(site).each do |v|
|
11
|
+
puts v
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def help
|
17
|
+
"Description:
|
18
|
+
list in storage
|
19
|
+
|
20
|
+
Usage:
|
21
|
+
keystrage [options] list [group]
|
22
|
+
"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'keystorage/command/base'
|
2
|
+
|
3
|
+
module Keystorage
|
4
|
+
module Command
|
5
|
+
class Set < Base
|
6
|
+
def execute(argv)
|
7
|
+
group = argv.shift
|
8
|
+
var = argv.shift
|
9
|
+
val = argv.shift
|
10
|
+
ks = Manager.new(@file)
|
11
|
+
ks.set(group,var,val)
|
12
|
+
end
|
13
|
+
class << self
|
14
|
+
def help
|
15
|
+
"Description:
|
16
|
+
store key to file
|
17
|
+
|
18
|
+
Usage:
|
19
|
+
keystrage [options] set group name key
|
20
|
+
"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'keystorage/command/help'
|
2
|
+
require 'keystorage/command/list'
|
3
|
+
require 'keystorage/command/set'
|
4
|
+
require 'keystorage/command/get'
|
5
|
+
|
6
|
+
module Keystorage
|
7
|
+
class Commands
|
8
|
+
class << self
|
9
|
+
def help(argv,options)
|
10
|
+
Command::Help.run(argv,options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def list(argv,options)
|
14
|
+
Command::List.run(argv,options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def set(argv,options)
|
18
|
+
Command::Set.run(argv,options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(argv,options)
|
22
|
+
Command::Get.run(argv,options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
class Manager
|
5
|
+
|
6
|
+
def initialize(file)
|
7
|
+
@file = file
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(group=null)
|
11
|
+
data = Hash.new
|
12
|
+
if File::exist?(@file)
|
13
|
+
File.open(@file,'r') do |f|
|
14
|
+
data = YAML.load(f)
|
15
|
+
return data.keys unless group
|
16
|
+
return data[group].keys
|
17
|
+
end
|
18
|
+
end
|
19
|
+
Hash.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(group,name)
|
23
|
+
raise "missing group" unless group
|
24
|
+
raise "missing name" unless name
|
25
|
+
|
26
|
+
File.open(@file,'r') do |f|
|
27
|
+
data=YAML.load(f)
|
28
|
+
raise "missing key" unless data[group][name]
|
29
|
+
return decode(data[group][name])
|
30
|
+
end
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def all
|
35
|
+
return YAML.load_file(@file) if File.exist?(@file)
|
36
|
+
Hash.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def set(group,key,value)
|
40
|
+
data=all
|
41
|
+
data = Hash.new unless data
|
42
|
+
data[group] = Hash.new unless data.has_key?(group)
|
43
|
+
data[group][key] = encode(value)
|
44
|
+
|
45
|
+
File.open(@file,'w',0600) do |f|
|
46
|
+
YAML.dump(data,f)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def encode(str,salt="3Qw9EtWE")
|
51
|
+
enc = OpenSSL::Cipher::Cipher.new('aes256')
|
52
|
+
enc.encrypt.pkcs5_keyivgen(salt)
|
53
|
+
((enc.update(str) + enc.final).unpack("H*")).to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
def decode(str,salt="3Qw9EtWE")
|
57
|
+
dec = OpenSSL::Cipher::Cipher.new('aes256')
|
58
|
+
dec.decrypt.pkcs5_keyivgen(salt)
|
59
|
+
(dec.update(Array.new([str]).pack("H*")) + dec.final)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'keystorage'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keystorage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Yoshihiro TAKAHARA
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-15 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
requirement: *id001
|
32
|
+
prerelease: false
|
33
|
+
name: shoulda
|
34
|
+
type: :development
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 23
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
requirement: *id002
|
48
|
+
prerelease: false
|
49
|
+
name: bundler
|
50
|
+
type: :development
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 7
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 5
|
61
|
+
- 2
|
62
|
+
version: 1.5.2
|
63
|
+
requirement: *id003
|
64
|
+
prerelease: false
|
65
|
+
name: jeweler
|
66
|
+
type: :development
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirement: *id004
|
78
|
+
prerelease: false
|
79
|
+
name: rcov
|
80
|
+
type: :development
|
81
|
+
description: This is a command to store and manage your passwords.
|
82
|
+
email: y.takahara@gmail.com
|
83
|
+
executables:
|
84
|
+
- keystorage
|
85
|
+
- keystorage.rb
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.rdoc
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- bin/keystorage
|
98
|
+
- bin/keystorage.rb
|
99
|
+
- lib/keystorage/cli.rb
|
100
|
+
- lib/keystorage/command/base.rb
|
101
|
+
- lib/keystorage/command/get.rb
|
102
|
+
- lib/keystorage/command/help.rb
|
103
|
+
- lib/keystorage/command/list.rb
|
104
|
+
- lib/keystorage/command/set.rb
|
105
|
+
- lib/keystorage/commands.rb
|
106
|
+
- lib/keystorage/manager.rb
|
107
|
+
- test/helper.rb
|
108
|
+
- test/test_keystorage.rb
|
109
|
+
has_rdoc: true
|
110
|
+
homepage: http://github.com/tumf/keystorage
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
requirements: []
|
137
|
+
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.4.1
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: Simple password storage command
|
143
|
+
test_files:
|
144
|
+
- test/helper.rb
|
145
|
+
- test/test_keystorage.rb
|