auth_keys_chain 0.0.1 → 0.0.2
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/lib/auth_keys.rb +42 -17
- data/lib/auth_keys/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f89f5e6801c242316f8b792c37c170c7ff251a7b
|
4
|
+
data.tar.gz: bed86d758454aaf46c092b951e34741ee4053e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdce5d6d0b5b12dbccfc3388b0bc07c66db37713f173791307cb7561164150c749603b042de50cab3a6febd04965e446f21a5841684a5c629e92c77ab2745c30
|
7
|
+
data.tar.gz: 34d0097f8cedb219eee91e99f1687531f3112e40ebf0627c2cd94b41488499e2882310e630519c21e92c13b77767858b3f4e6d363e7f7f584a44d79b33d26d50
|
data/lib/auth_keys.rb
CHANGED
@@ -16,13 +16,17 @@ class AuthKeys
|
|
16
16
|
def encrypt()
|
17
17
|
data = self.read
|
18
18
|
return if is_encrypted?(data)
|
19
|
-
data =
|
19
|
+
#data = self.encrypt_data_by_pubkey(data)
|
20
|
+
data = self.encrypt_data(data,self.master_key_data)
|
20
21
|
save(data)
|
21
22
|
end
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def decrypt()
|
24
|
+
data = self.read
|
25
|
+
return unless is_encrypted?(data)
|
26
|
+
data = data.force_encoding("ASCII-8BIT")
|
27
|
+
#data = self.decrypt_data_by_privkey(data)
|
28
|
+
data = self.decrypt_data(data,self.master_key_data)
|
29
|
+
self.save(data)
|
26
30
|
end
|
27
31
|
def decrypt_data(data,pass)
|
28
32
|
data = data.force_encoding("ASCII-8BIT")
|
@@ -33,16 +37,33 @@ class AuthKeys
|
|
33
37
|
cipher.pkcs5_keyivgen(pass, salt)
|
34
38
|
cipher.update(data) + cipher.final
|
35
39
|
end
|
40
|
+
def rsautil
|
41
|
+
OpenSSL::PKey::RSA.new(self.master_key_data)
|
42
|
+
end
|
43
|
+
def encrypt_data_by_pubkey(data)
|
44
|
+
self.rsautil.public_encrypt(data)
|
45
|
+
end
|
46
|
+
def decrypt_data_by_privkey(data)
|
47
|
+
self.rsautil.private_decrypt(data)
|
48
|
+
end
|
36
49
|
|
37
|
-
def
|
38
|
-
|
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)
|
50
|
+
def is_salted?(str)
|
51
|
+
/Salted__/ === str[0,8]
|
43
52
|
end
|
44
53
|
def is_encrypted?(str)
|
45
|
-
|
54
|
+
return true if self.is_salted?(str)
|
55
|
+
# check encrypt by trying to treat as UTF-8 String
|
56
|
+
begin
|
57
|
+
str.split("")
|
58
|
+
return false
|
59
|
+
rescue => e
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
def master_key_data
|
64
|
+
path = File.expand_path(MASTER_KEY)
|
65
|
+
raise unless File.exists?(path)
|
66
|
+
open(path).read
|
46
67
|
end
|
47
68
|
def save(content)
|
48
69
|
path = File.expand_path(KEY_PATH)
|
@@ -54,7 +75,7 @@ class AuthKeys
|
|
54
75
|
|
55
76
|
def load()
|
56
77
|
content = self.read
|
57
|
-
content = self.decrypt_data(content,self.
|
78
|
+
content = self.decrypt_data(content,self.master_key_data) if is_encrypted?(content)
|
58
79
|
array = content
|
59
80
|
.split("\n")
|
60
81
|
.reject{|e| e.strip =~/^#/}
|
@@ -68,6 +89,10 @@ class AuthKeys
|
|
68
89
|
end
|
69
90
|
def get(key)
|
70
91
|
hash = self.load
|
92
|
+
if key.class == Regexp then
|
93
|
+
key = self.keys.find{|e| e=~key}
|
94
|
+
return nil unless key
|
95
|
+
end
|
71
96
|
hash.key?(key) ? hash[key] : nil ;
|
72
97
|
end
|
73
98
|
def [](key)
|
@@ -82,9 +107,9 @@ end
|
|
82
107
|
|
83
108
|
if $0 == __FILE__ then
|
84
109
|
require 'pp'
|
85
|
-
pp AuthKeys.load
|
86
|
-
pp AuthKeys.keys
|
87
|
-
pp AuthKeys["softbank"]
|
88
|
-
pp AuthKeys.encrypt
|
110
|
+
#pp AuthKeys.load
|
111
|
+
#pp AuthKeys.keys
|
112
|
+
#pp AuthKeys["softbank"]
|
113
|
+
#pp AuthKeys.encrypt
|
89
114
|
end
|
90
115
|
|
data/lib/auth_keys/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takuya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|