passw3rd 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/passw3rd/password_service.rb +9 -4
- data/lib/passw3rd/version.rb +1 -1
- data/test/password_service_test.rb +8 -8
- metadata +39 -21
data/History.txt
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
module Passw3rd
|
2
2
|
class PasswordService
|
3
3
|
@@password_file_dir = ENV["HOME"]
|
4
|
+
@@key_file_dir = ENV["HOME"]
|
4
5
|
|
5
6
|
def self.password_file_dir= dir
|
6
7
|
@@password_file_dir = dir
|
7
8
|
end
|
8
9
|
|
10
|
+
def self.key_file_dir= dir
|
11
|
+
@@key_file_dir = dir
|
12
|
+
end
|
13
|
+
|
9
14
|
def self.get_password (password_file, key_path=nil)
|
10
15
|
encoded_password = Base64.decode64(IO.readlines(File.join(@@password_file_dir, password_file)).join)
|
11
|
-
PasswordService.decrypt(encoded_password, key_path)
|
16
|
+
PasswordService.decrypt(encoded_password, key_path || @@key_file_dir)
|
12
17
|
end
|
13
18
|
|
14
19
|
def self.write_password_file(password, output_path, key_path = nil)
|
15
|
-
enc_password = PasswordService.encrypt(password, key_path)
|
20
|
+
enc_password = PasswordService.encrypt(password, key_path || @@key_file_dir)
|
16
21
|
base64pw = Base64.encode64(enc_password)
|
17
22
|
path = File.join(@@password_file_dir, output_path)
|
18
23
|
File.open(path, 'w') { |f| f.write base64pw }
|
@@ -22,7 +27,7 @@ module Passw3rd
|
|
22
27
|
def self.encrypt(password, key_path = nil)
|
23
28
|
raise "password cannot be blank" if password.empty?
|
24
29
|
|
25
|
-
pair = KeyLoader.load(key_path)
|
30
|
+
pair = KeyLoader.load(key_path || @@key_file_dir)
|
26
31
|
cipher = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
|
27
32
|
cipher.encrypt
|
28
33
|
cipher.key = pair.key
|
@@ -37,7 +42,7 @@ module Passw3rd
|
|
37
42
|
end
|
38
43
|
|
39
44
|
def self.decrypt(cipher_text, key_path = nil)
|
40
|
-
pair = KeyLoader.load(key_path)
|
45
|
+
pair = KeyLoader.load(key_path || @@key_file_dir)
|
41
46
|
cipher = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
|
42
47
|
cipher.decrypt
|
43
48
|
cipher.key = pair.key
|
data/lib/passw3rd/version.rb
CHANGED
@@ -8,6 +8,9 @@ class PasswordServiceTest < Test::Unit::TestCase
|
|
8
8
|
def setup
|
9
9
|
random_num = SecureRandom.random_number(5000)
|
10
10
|
@random_string = SecureRandom.random_bytes(5000 + random_num)
|
11
|
+
|
12
|
+
::Passw3rd::KeyLoader.create_key_iv_file(Dir.tmpdir)
|
13
|
+
::Passw3rd::PasswordService.key_file_dir = Dir.tmpdir
|
11
14
|
end
|
12
15
|
|
13
16
|
def test_enc_dec
|
@@ -18,25 +21,22 @@ class PasswordServiceTest < Test::Unit::TestCase
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def test_set_and_get_password
|
21
|
-
::Passw3rd::
|
22
|
-
|
23
|
-
decrypted = Passw3rd::PasswordService.get_password("test", Dir.tmpdir)
|
24
|
+
password_file = ::Passw3rd::PasswordService.write_password_file(@random_string, "test")
|
25
|
+
decrypted = Passw3rd::PasswordService.get_password("test")
|
24
26
|
assert_equal(@random_string, decrypted)
|
25
27
|
end
|
26
28
|
|
27
29
|
def test_set_and_get_password_custom_dir
|
28
30
|
::Passw3rd::PasswordService.password_file_dir = Dir.tmpdir
|
29
|
-
|
31
|
+
|
30
32
|
password_file = ::Passw3rd::PasswordService.write_password_file(@random_string, "test2")
|
31
33
|
decrypted = Passw3rd::PasswordService.get_password("test2")
|
32
34
|
assert_equal(@random_string, decrypted)
|
33
35
|
end
|
34
36
|
|
35
37
|
def test_gen_key
|
36
|
-
::Passw3rd::
|
37
|
-
|
38
|
-
enc = ::Passw3rd::PasswordService.encrypt(@random_string, Dir.tmpdir)
|
39
|
-
dec = ::Passw3rd::PasswordService.decrypt(enc, Dir.tmpdir)
|
38
|
+
enc = ::Passw3rd::PasswordService.encrypt(@random_string)
|
39
|
+
dec = ::Passw3rd::PasswordService.decrypt(enc)
|
40
40
|
|
41
41
|
assert_equal(@random_string, dec)
|
42
42
|
end
|
metadata
CHANGED
@@ -1,25 +1,33 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: passw3rd
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Neil Matatall
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
17
|
+
|
18
|
+
date: 2011-10-02 00:00:00 Z
|
13
19
|
dependencies: []
|
14
|
-
|
15
|
-
|
16
|
-
email:
|
20
|
+
|
21
|
+
description: Generate a key/iv file, generate passwords, and store encrypted files in source control, keep the key/iv safe!
|
22
|
+
email:
|
17
23
|
- neil.matatall@gmail.com
|
18
|
-
executables:
|
24
|
+
executables:
|
19
25
|
- passw3rd
|
20
26
|
extensions: []
|
27
|
+
|
21
28
|
extra_rdoc_files: []
|
22
|
-
|
29
|
+
|
30
|
+
files:
|
23
31
|
- README.md
|
24
32
|
- LICENSE
|
25
33
|
- EXAMPLES
|
@@ -33,26 +41,36 @@ files:
|
|
33
41
|
- test/password_service_test.rb
|
34
42
|
homepage: https://github.com/oreoshake/passw3rd
|
35
43
|
licenses: []
|
44
|
+
|
36
45
|
post_install_message:
|
37
46
|
rdoc_options: []
|
38
|
-
|
47
|
+
|
48
|
+
require_paths:
|
39
49
|
- lib
|
40
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
51
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
60
|
none: false
|
48
|
-
requirements:
|
49
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
52
68
|
requirements: []
|
69
|
+
|
53
70
|
rubyforge_project:
|
54
71
|
rubygems_version: 1.8.10
|
55
72
|
signing_key:
|
56
73
|
specification_version: 3
|
57
74
|
summary: A simple "keep the passwords out of source code and config files".
|
58
75
|
test_files: []
|
76
|
+
|