auth_keys_chain 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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +674 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/auth_keys_chain.gemspec +23 -0
- data/bin/auth_keys +33 -0
- data/lib/auth_keys/version.rb +3 -0
- data/lib/auth_keys.rb +90 -0
- data/vendor/bundle/cache/auth_keys-0.0.1.gem +0 -0
- data/vendor/bundle/doc/auth_keys-0.0.1/ri/AuthKey/cdesc-AuthKey.ri +0 -0
- data/vendor/bundle/doc/auth_keys-0.0.1/ri/AuthKeys/%5b%5d-c.ri +0 -0
- data/vendor/bundle/doc/auth_keys-0.0.1/ri/AuthKeys/cdesc-AuthKeys.ri +0 -0
- data/vendor/bundle/doc/auth_keys-0.0.1/ri/AuthKeys/get-c.ri +0 -0
- data/vendor/bundle/doc/auth_keys-0.0.1/ri/AuthKeys/keys-c.ri +0 -0
- data/vendor/bundle/doc/auth_keys-0.0.1/ri/AuthKeys/load-c.ri +0 -0
- data/vendor/bundle/doc/auth_keys-0.0.1/ri/cache.ri +0 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/.gitignore +14 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/Gemfile +4 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/LICENSE.txt +674 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/README.md +33 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/Rakefile +2 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/auth_keys.gemspec +23 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/lib/auth_keys/version.rb +3 -0
- data/vendor/bundle/gems/auth_keys-0.0.1/lib/auth_keys.rb +49 -0
- data/vendor/bundle/specifications/auth_keys-0.0.1.gemspec +32 -0
- metadata +99 -0
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# AuthKeys
|
2
|
+
|
3
|
+
Saving and Editing passwords more easily.
|
4
|
+
Using ~/.auth_keys file , this is space seperated file.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
AuthKeys uses CSV/TSV passwod list.
|
9
|
+
File format is TSV(space sperated) for easy to edit.
|
10
|
+
|
11
|
+
## example of ~/.auth_keys
|
12
|
+
softbank 080xxxxxxxxx 12345678
|
13
|
+
mobilepoint example@i.softbank.jp passs
|
14
|
+
starbucks example@gmail.com passssss
|
15
|
+
au example@au passssss
|
16
|
+
wi2 example@au passssss
|
17
|
+
7spot example@gmail.com passssss
|
18
|
+
|
19
|
+
## Example
|
20
|
+
#/usr/bin/env ruby
|
21
|
+
require 'auth_keys'
|
22
|
+
AuthKeys["site_name"]
|
23
|
+
|
24
|
+
~/.auth_keys to store id/pass pair.
|
25
|
+
|
26
|
+
| key(site_name) | login_id | password |
|
27
|
+
|----------------|----------|----------|
|
28
|
+
|mixi| username@example.com | my_pass |
|
29
|
+
|
30
|
+
# execute from CLI (bin/auth_keys)
|
31
|
+
|
32
|
+
Space sperateted is very easy for editing and reading, but not enough secure.
|
33
|
+
So auth_keys comannd is available, for easy to encrypt and to decrypt ~/.auth_keys from CLI.
|
34
|
+
|
35
|
+
$ auth_keys -e #encrypt ~/.auth_keys after edit
|
36
|
+
$ auth_keys -d #decrypt ~/.auth_keys before edit
|
37
|
+
$ auth_keys -l #list key names ~/.auth_keys
|
38
|
+
$ auth_keys -k key #retrieve id/pass pair from ~/.auth_keys
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
Add this line to your application's Gemfile:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'auth_keys_chain'
|
46
|
+
```
|
47
|
+
|
48
|
+
And then execute:
|
49
|
+
|
50
|
+
$ bundle
|
51
|
+
|
52
|
+
Or install it yourself as:
|
53
|
+
|
54
|
+
$ gem install auth_keys_chain
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/takuya/auth_keys/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
63
|
+
|
64
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'auth_keys/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "auth_keys_chain"
|
8
|
+
spec.version = AuthKey::VERSION
|
9
|
+
spec.authors = ["takuya"]
|
10
|
+
spec.email = ["takuy.a.1st+nospam@gmail.com"]
|
11
|
+
spec.summary = %q{Passwords saves/load in ~/.auth_keys }
|
12
|
+
spec.description = %q{Passwords save/load in ~/.auth_keys(plain text table) }
|
13
|
+
spec.homepage = "https://github.com/takuya/auth_key"
|
14
|
+
spec.license = "GPLv3"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/bin/auth_keys
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
def load_path
|
4
|
+
path = File.expand_path( "../lib", File.dirname(File.realpath(__FILE__)) )
|
5
|
+
$:.unshift path
|
6
|
+
end
|
7
|
+
load_path;
|
8
|
+
|
9
|
+
require 'pp'
|
10
|
+
require 'auth_keys'
|
11
|
+
require 'optparse'
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
opt = []
|
15
|
+
keys = []
|
16
|
+
ARGV << "-h" unless ARGV.size > 0
|
17
|
+
op = OptionParser.new
|
18
|
+
op.on("-e","--encrypt", "#{AuthKeys::KEY_PATH}を暗号化"){ opt << "encrypt"}
|
19
|
+
op.on("-d","--decrypt", "#{AuthKeys::KEY_PATH}を平文化"){ opt << "decrypt" }
|
20
|
+
op.on("-k [key]","--key", "#{AuthKeys::KEY_PATH}に含まれる識別子から検索"){|key| if key then opt << "key" ;keys << key else opt<<"list" end }
|
21
|
+
op.on("-l", "--list", "#{AuthKeys::KEY_PATH}に含まれる識別子を一覧"){ opt << "list" }
|
22
|
+
|
23
|
+
op.parse!(ARGV)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
case opt
|
29
|
+
when ["encrypt"] then AuthKeys.encrypt
|
30
|
+
when ["decrypt"] then AuthKeys.decrypt
|
31
|
+
when ["list"] then puts AuthKeys.keys
|
32
|
+
when ["key"] then keys.each{|e| o={};o[e]=AuthKeys[e]; puts JSON.dump(o) }
|
33
|
+
end
|
data/lib/auth_keys.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
require 'openssl'
|
3
|
+
class AuthKeys
|
4
|
+
KEY_PATH = "~/.auth_keys"
|
5
|
+
MASTER_KEY = "~/.ssh/id_rsa"
|
6
|
+
class << self
|
7
|
+
def encrypt_data(data,pass)
|
8
|
+
cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
|
9
|
+
salt = OpenSSL::Random.random_bytes(8)
|
10
|
+
cipher.encrypt
|
11
|
+
cipher.pkcs5_keyivgen(pass, salt)
|
12
|
+
data = cipher.update(data) + cipher.final
|
13
|
+
## salted
|
14
|
+
data = "Salted__" + salt + data
|
15
|
+
end
|
16
|
+
def encrypt()
|
17
|
+
data = self.read
|
18
|
+
return if is_encrypted?(data)
|
19
|
+
data = encrypt_data(data, self.master_key)
|
20
|
+
save(data)
|
21
|
+
end
|
22
|
+
def master_key
|
23
|
+
path = File.expand_path(MASTER_KEY)
|
24
|
+
raise unless File.exists?(path)
|
25
|
+
open(path).read
|
26
|
+
end
|
27
|
+
def decrypt_data(data,pass)
|
28
|
+
data = data.force_encoding("ASCII-8BIT")
|
29
|
+
salt = data[8,8]
|
30
|
+
data = data[16, data.size]
|
31
|
+
cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
|
32
|
+
cipher.decrypt
|
33
|
+
cipher.pkcs5_keyivgen(pass, salt)
|
34
|
+
cipher.update(data) + cipher.final
|
35
|
+
end
|
36
|
+
|
37
|
+
def decrypt()
|
38
|
+
data = self.read
|
39
|
+
data = data.force_encoding("ASCII-8BIT")
|
40
|
+
return unless is_encrypted?(data)
|
41
|
+
data = self.decrypt_data(data,self.master_key)
|
42
|
+
self.save(data)
|
43
|
+
end
|
44
|
+
def is_encrypted?(str)
|
45
|
+
/Salted__/ === str[0,8]
|
46
|
+
end
|
47
|
+
def save(content)
|
48
|
+
path = File.expand_path(KEY_PATH)
|
49
|
+
raise "#{path} not found." unless File.exists?(path)
|
50
|
+
open(path, "w"){|f|
|
51
|
+
f.write content
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def load()
|
56
|
+
content = self.read
|
57
|
+
content = self.decrypt_data(content,self.master_key) if is_encrypted?(content)
|
58
|
+
array = content
|
59
|
+
.split("\n")
|
60
|
+
.reject{|e| e.strip =~/^#/}
|
61
|
+
.map(&:split).map{|e| [e[0],[ e[1],e[2] ] ] }
|
62
|
+
password_table = Hash[array]
|
63
|
+
end
|
64
|
+
def read()
|
65
|
+
path = File.expand_path(KEY_PATH)
|
66
|
+
raise unless File.exists?(path)
|
67
|
+
content = open(path).read
|
68
|
+
end
|
69
|
+
def get(key)
|
70
|
+
hash = self.load
|
71
|
+
hash.key?(key) ? hash[key] : nil ;
|
72
|
+
end
|
73
|
+
def [](key)
|
74
|
+
self.get(key)
|
75
|
+
end
|
76
|
+
def keys
|
77
|
+
self.load.keys
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
if $0 == __FILE__ then
|
84
|
+
require 'pp'
|
85
|
+
pp AuthKeys.load
|
86
|
+
pp AuthKeys.keys
|
87
|
+
pp AuthKeys["softbank"]
|
88
|
+
pp AuthKeys.encrypt
|
89
|
+
end
|
90
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|