auth_keys_chain 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +1 -1
- data/bin/auth_keys +5 -5
- data/lib/auth_keys.rb +17 -19
- data/lib/auth_keys/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a27cccc5a2300568c4684d076eb8453087aa7c4
|
4
|
+
data.tar.gz: 1beafe681264d64232fe00ef46f317acaa39de81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c3c76f0dc78f582fbbd28d8431999c54fddc369b424e6c38e34e5a30aab943c3a25b9278d3148b4e58042b77e852972f5aceefc60d817a88fb630724e455cf
|
7
|
+
data.tar.gz: 897d16cba40f3b2b98a2411a5c0ec97c95dd32be90298bc365f75910d79799152a86f303e276f51e6229223e3a7223a8370b596dca1cdc3f4902f204c4d82bff
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ File format is TSV(space sperated) for easy to edit.
|
|
21
21
|
require 'auth_keys'
|
22
22
|
AuthKeys["site_name"]
|
23
23
|
|
24
|
-
~/.auth_keys to store id/pass pair.
|
24
|
+
~/.auth_keys is to store id/pass pair.
|
25
25
|
|
26
26
|
| key(site_name) | login_id | password |
|
27
27
|
|----------------|----------|----------|
|
data/bin/auth_keys
CHANGED
@@ -4,21 +4,21 @@ def load_path
|
|
4
4
|
path = File.expand_path( "../lib", File.dirname(File.realpath(__FILE__)) )
|
5
5
|
$:.unshift path
|
6
6
|
end
|
7
|
-
load_path;
|
8
7
|
|
9
8
|
require 'pp'
|
10
9
|
require 'auth_keys'
|
11
10
|
require 'optparse'
|
12
11
|
require 'json'
|
13
12
|
|
13
|
+
|
14
14
|
opt = []
|
15
15
|
keys = []
|
16
16
|
ARGV << "-h" unless ARGV.size > 0
|
17
17
|
op = OptionParser.new
|
18
|
-
op.on("-e","--encrypt", "#{AuthKeys
|
19
|
-
op.on("-d","--decrypt", "#{AuthKeys
|
20
|
-
op.on("-k [key]","--key", "#{AuthKeys
|
21
|
-
op.on("-l", "--list", "#{AuthKeys
|
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
22
|
|
23
23
|
op.parse!(ARGV)
|
24
24
|
|
data/lib/auth_keys.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
|
2
2
|
require 'openssl'
|
3
3
|
class AuthKeys
|
4
|
-
KEY_PATH = "~/.auth_keys"
|
5
|
-
MASTER_KEY = "~/.ssh/id_rsa"
|
6
4
|
class << self
|
5
|
+
def KEY_PATH ; ENV["KEY_PATH"] || "~/.auth_keys" end
|
6
|
+
def MASTER_KEY ; ENV["MASTER_KEY"] || "~/.ssh/id_rsa" end
|
7
7
|
def encrypt_data(data,pass)
|
8
8
|
cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
|
9
9
|
salt = OpenSSL::Random.random_bytes(8)
|
10
10
|
cipher.encrypt
|
11
|
-
cipher.pkcs5_keyivgen(pass, salt)
|
11
|
+
cipher.pkcs5_keyivgen(pass, salt, 1)
|
12
12
|
data = cipher.update(data) + cipher.final
|
13
13
|
## salted
|
14
14
|
data = "Salted__" + salt + data
|
@@ -16,7 +16,7 @@ class AuthKeys
|
|
16
16
|
def encrypt()
|
17
17
|
data = self.read
|
18
18
|
return if is_encrypted?(data)
|
19
|
-
|
19
|
+
|
20
20
|
data = self.encrypt_data(data,self.master_key_data)
|
21
21
|
save(data)
|
22
22
|
end
|
@@ -24,7 +24,6 @@ class AuthKeys
|
|
24
24
|
data = self.read
|
25
25
|
return unless is_encrypted?(data)
|
26
26
|
data = data.force_encoding("ASCII-8BIT")
|
27
|
-
#data = self.decrypt_data_by_privkey(data)
|
28
27
|
data = self.decrypt_data(data,self.master_key_data)
|
29
28
|
self.save(data)
|
30
29
|
end
|
@@ -34,7 +33,7 @@ class AuthKeys
|
|
34
33
|
data = data[16, data.size]
|
35
34
|
cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
|
36
35
|
cipher.decrypt
|
37
|
-
cipher.pkcs5_keyivgen(pass, salt)
|
36
|
+
cipher.pkcs5_keyivgen(pass, salt, 1 )
|
38
37
|
cipher.update(data) + cipher.final
|
39
38
|
end
|
40
39
|
def rsautil
|
@@ -48,12 +47,12 @@ class AuthKeys
|
|
48
47
|
end
|
49
48
|
|
50
49
|
def is_salted?(str)
|
51
|
-
/Salted__/ === str[0,8]
|
50
|
+
/Salted__/ === str[0,8]
|
52
51
|
end
|
53
52
|
def is_encrypted?(str)
|
54
53
|
return true if self.is_salted?(str)
|
55
54
|
# check encrypt by trying to treat as UTF-8 String
|
56
|
-
begin
|
55
|
+
begin
|
57
56
|
str.split("")
|
58
57
|
return false
|
59
58
|
rescue => e
|
@@ -61,14 +60,14 @@ class AuthKeys
|
|
61
60
|
end
|
62
61
|
end
|
63
62
|
def master_key_data
|
64
|
-
path = File.expand_path(MASTER_KEY)
|
63
|
+
path = File.expand_path(self.MASTER_KEY)
|
65
64
|
raise unless File.exists?(path)
|
66
65
|
open(path).read
|
67
66
|
end
|
68
67
|
def save(content)
|
69
|
-
path = File.expand_path(KEY_PATH)
|
68
|
+
path = File.expand_path(self.KEY_PATH)
|
70
69
|
raise "#{path} not found." unless File.exists?(path)
|
71
|
-
open(path, "w"){|f|
|
70
|
+
open(path, "w"){|f|
|
72
71
|
f.write content
|
73
72
|
}
|
74
73
|
end
|
@@ -76,14 +75,14 @@ class AuthKeys
|
|
76
75
|
def load()
|
77
76
|
content = self.read
|
78
77
|
content = self.decrypt_data(content,self.master_key_data) if is_encrypted?(content)
|
79
|
-
array = content
|
78
|
+
array = content
|
80
79
|
.split("\n")
|
81
80
|
.reject{|e| e.strip =~/^#/}
|
82
81
|
.map(&:split).map{|e| [e[0],[ e[1],e[2] ] ] }
|
83
82
|
password_table = Hash[array]
|
84
83
|
end
|
85
84
|
def read()
|
86
|
-
path = File.expand_path(KEY_PATH)
|
85
|
+
path = File.expand_path(self.KEY_PATH)
|
87
86
|
raise unless File.exists?(path)
|
88
87
|
content = open(path).read
|
89
88
|
end
|
@@ -93,7 +92,7 @@ class AuthKeys
|
|
93
92
|
key = self.keys.find{|e| e=~key}
|
94
93
|
return nil unless key
|
95
94
|
end
|
96
|
-
hash.key?(key) ? hash[key] : nil ;
|
95
|
+
hash.key?(key) ? hash[key] : nil ;
|
97
96
|
end
|
98
97
|
def [](key)
|
99
98
|
self.get(key)
|
@@ -107,9 +106,8 @@ end
|
|
107
106
|
|
108
107
|
if $0 == __FILE__ then
|
109
108
|
require 'pp'
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
pp AuthKeys.load
|
110
|
+
pp AuthKeys.keys
|
111
|
+
pp AuthKeys["softbank"]
|
112
|
+
pp AuthKeys.encrypt
|
114
113
|
end
|
115
|
-
|
data/lib/auth_keys/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth_keys_chain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takuya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: 'Passwords save/load in ~/.auth_keys(plain text table) '
|
@@ -46,7 +46,7 @@ executables:
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- .gitignore
|
49
|
+
- ".gitignore"
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE.txt
|
52
52
|
- README.md
|
@@ -82,12 +82,12 @@ require_paths:
|
|
82
82
|
- lib
|
83
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|