passw3rd 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/EXAMPLES ADDED
@@ -0,0 +1,67 @@
1
+ ------------------------------------------------------------------------------
2
+ Command line use
3
+ ------------------------------------------------------------------------------
4
+
5
+ Generate key/iv in ~/ by default
6
+
7
+ passw3rd -k
8
+
9
+ Create a password file
10
+
11
+ passw3rd -e 'foobar_app'
12
+ Enter password:
13
+
14
+ Read a password file
15
+
16
+ passw3rd -d 'foobar_app'
17
+
18
+ > "Your password"
19
+
20
+
21
+ ------------------------------------------------------------------------------
22
+ Manual JDBC Connection
23
+ ------------------------------------------------------------------------------
24
+
25
+ Before:
26
+
27
+ Datasource ds = new Datasource();
28
+ ds.setPassword("suparSekret");
29
+
30
+ After:
31
+
32
+ Datasource ds = new Datasource();
33
+ ds.setPassword(PasswordService.getPassword(USER);
34
+
35
+ ------------------------------------------------------------------------------
36
+ Java properties file
37
+ ------------------------------------------------------------------------------
38
+
39
+ Before:
40
+
41
+ password=suparSekret
42
+
43
+ After:
44
+
45
+ password=${password}
46
+
47
+ ------------------------------------------------------------------------------
48
+ Ruby on Rails config/database.yml
49
+ ------------------------------------------------------------------------------
50
+
51
+ Before:
52
+
53
+ development:
54
+ adapter: mysql
55
+ database: rails_development
56
+ username: root
57
+ password: my super secret password
58
+
59
+
60
+ After:
61
+
62
+ development:
63
+ adapter: mysql
64
+ database: rails_development
65
+ username: root
66
+ password: <%= PasswordService.get_password('foobar_app') -%>
67
+
data/History.txt ADDED
@@ -0,0 +1,10 @@
1
+ === 0.6.0 / 2011-10-02
2
+
3
+ Added custom password directories, more tests. Some code cleanup. Java version maven site generation.
4
+
5
+ === 0.1.0 / 2010-06-07
6
+
7
+ * 1 major enhancement
8
+
9
+ * Adding ruby gem packaging
10
+
data/LICENSE CHANGED
@@ -1,10 +1,22 @@
1
- Open Source Initiative OSI - The MIT License (MIT):Licensing
1
+ The MIT License
2
2
 
3
- The MIT License (MIT)
4
- Copyright (c) 2011 YELLOWPAGES.COM LLC
3
+ Copyright (c) 2010 YELLOWPAGES.COM LLC
5
4
 
6
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
7
11
 
8
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
9
22
 
10
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ ![Build status](/https://secure.travis-ci.org/oreoshake/passw3rd.png)
2
+
3
+ ------------------------------------------------------------------------------
4
+ Introduction
5
+ ------------------------------------------------------------------------------
6
+
7
+ This is a collection of encryption libraries intended to encrypt and store
8
+ passwords outside of source code.
9
+
10
+ Some advantages of keeping credentials out of source code are:
11
+
12
+ 1. Credentials are not passed around when source code is shared.
13
+ 2. Unintentional exposure of source code does not reveal credentials.
14
+ 3. Read-access to source code can be much more permissive.
15
+ 4. Source code can be checked into version control systems without concern
16
+ for exposure of credentials.
17
+ 5. It is easier to change credentials without having to worry about changing
18
+ all instances.
19
+ 6. Leaving credentials in source code leads to poor password management in
20
+ general. If changing a credential requires you to change code, you are less
21
+ likely to want to do it.
22
+
23
+ ------------------------------------------------------------------------------
24
+ Status
25
+ ------------------------------------------------------------------------------
26
+
27
+ This project is IN PROGRESS. All features and functionality are not working yet.
28
+
29
+ ------------------------------------------------------------------------------
30
+ License
31
+ ------------------------------------------------------------------------------
32
+
33
+ License: MIT (see LICENSE file)
34
+
35
+ ------------------------------------------------------------------------------
36
+ Credits
37
+ ------------------------------------------------------------------------------
38
+
39
+ Copyright 2010, YELLOWPAGES.COM LLC
40
+ Development by Neil Matatall <neil.matatall@gmail.com>
41
+
data/bin/passw3rd CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby -w
2
2
 
3
3
  require File.expand_path('../../lib/passw3rd', __FILE__)
4
- # require File.expand_path('../../lib/passw3rd/password_client.rb', __FILE__)
4
+ require File.expand_path('../../lib/passw3rd/password_client.rb', __FILE__)
5
5
 
@@ -4,27 +4,40 @@ require 'optparse'
4
4
 
5
5
  module Passw3rd
6
6
  class PasswordClient
7
- # def self.run argv = ARGV
8
7
  password_file = nil
9
- output_path = nil
10
8
  gen_key_path = nil
11
9
  key_path = nil
10
+ password_dir = nil
11
+ mode = nil
12
12
 
13
13
  opts = OptionParser.new
14
14
  opts.banner = 'Usage: password_client [options]'
15
+
15
16
  opts.on('-d', '--decrypt PATH_TO_PASSWORD', 'Path to password file') do |opt|
16
17
  password_file = opt
18
+ mode = "decrypt"
17
19
  end
18
- opts.on('-e', '--encrypt OUTPUT_PATH', 'Write the password to this location') do |opt|
19
- output_path = opt
20
+
21
+ opts.on('-e', '--encrypt PASSWORD_FILE', 'Write the password to this location') do |opt|
22
+ password_file = opt
23
+ mode = "encrypt"
20
24
  end
21
- opts.on('-p', '--key-path KEY_PATH', 'Use the keys specificed in this directory for encryption or decryption') do |opt|
25
+
26
+ opts.on('-k', '--key-dir KEY_PATH', 'Use the keys specificed in this directory for encryption or decryption (default is ~/)') do |opt|
22
27
  key_path = opt
23
28
  if !File.directory?(File.expand_path(key_path))
24
29
  raise "#{opt} must be a directory"
25
30
  end
26
31
  end
27
- opts.on('-k', '--generate-key [PATH]', 'generate key/iv and store in PATH, defaults to the home directory') do |opt|
32
+
33
+ opts.on('-p', '--password-dir PATH', 'Read and write password files to this directory (default is ~/)') do |opt|
34
+ password_dir = opt
35
+ if !File.directory?(File.expand_path(password_dir))
36
+ raise "#{password_dir} must be a directory"
37
+ end
38
+ end
39
+
40
+ opts.on('-g', '--generate-key [PATH]', 'generate key/iv and store in PATH, defaults to the home directory') do |opt|
28
41
  gen_key_path = opt
29
42
  if gen_key_path.nil?
30
43
  gen_key_path = ENV["HOME"]
@@ -47,20 +60,14 @@ module Passw3rd
47
60
  puts "generated keys in #{gen_key_path}"
48
61
  end
49
62
 
50
- # default the key directory to the users home, can also be specified by -p [path]
51
- if key_path.nil?
52
- key_path = ENV["HOME"]
53
- end
54
-
55
63
  # decrypt password_file using the key/IV in key_path
56
- if password_file
57
- decrypted = Passw3rd::PasswordService.getPassword(password_file, key_path)
58
-
59
- puts("The password is: #{decrypted}")
64
+ if mode == "decrypt"
65
+ decrypted = Passw3rd::PasswordService.get_password(password_file, key_path)
66
+ puts "The password is: #{decrypted}"
60
67
  end
61
68
 
62
69
  # encrypt password, store it in output path
63
- if output_path
70
+ if mode == "encrypt"
64
71
  begin
65
72
  system 'stty -echo'
66
73
  print "Enter the password: "
@@ -69,8 +76,8 @@ module Passw3rd
69
76
  system 'stty echo; echo ""'
70
77
  end
71
78
 
72
- Passw3rd::PasswordService.write_password_file(password, output_path, key_path)
73
- puts "Wrote password to #{output_path}"
79
+ file = Passw3rd::PasswordService.write_password_file(password, password_file, key_path)
80
+ puts "Wrote password to #{file}"
74
81
  end
75
82
  end
76
83
  end
@@ -1,20 +1,27 @@
1
1
  module Passw3rd
2
2
  class PasswordService
3
- VERSION = '0.1.0'
3
+ @@password_file_dir = ENV["HOME"]
4
4
 
5
- def self.getPassword (password_file, key_path=nil)
6
- encoded_password = IO.readlines(password_file).join
7
- encrypted_password = Base64.decode64(encoded_password)
8
- PasswordService.decrypt(encrypted_password, key_path)
5
+ def self.password_file_dir= dir
6
+ @@password_file_dir = dir
9
7
  end
10
8
 
11
- def self.write_password_file password, output_path, key_path
9
+ def self.get_password (password_file, key_path=nil)
10
+ encoded_password = Base64.decode64(IO.readlines(File.join(@@password_file_dir, password_file)).join)
11
+ PasswordService.decrypt(encoded_password, key_path)
12
+ end
13
+
14
+ def self.write_password_file(password, output_path, key_path = nil)
12
15
  enc_password = PasswordService.encrypt(password, key_path)
13
16
  base64pw = Base64.encode64(enc_password)
14
- File.open(output_path, 'w') { |f| f.write base64pw }
17
+ path = File.join(@@password_file_dir, output_path)
18
+ File.open(path, 'w') { |f| f.write base64pw }
19
+ path
15
20
  end
16
21
 
17
22
  def self.encrypt(password, key_path = nil)
23
+ raise "password cannot be blank" if password.empty?
24
+
18
25
  pair = KeyLoader.load(key_path)
19
26
  cipher = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
20
27
  cipher.encrypt
@@ -23,27 +30,25 @@ module Passw3rd
23
30
  begin
24
31
  e = cipher.update(password)
25
32
  e << cipher.final
26
- rescue OpenSSL::Cipher::CipherError=>err
33
+ rescue OpenSSL::Cipher::CipherError => err
27
34
  puts "Couldn't encrypt password."
28
35
  raise err
29
36
  end
30
-
31
37
  end
32
38
 
33
- def self.decrypt(password, key_path = nil)
39
+ def self.decrypt(cipher_text, key_path = nil)
34
40
  pair = KeyLoader.load(key_path)
35
41
  cipher = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
36
42
  cipher.decrypt
37
43
  cipher.key = pair.key
38
44
  cipher.iv = pair.iv
39
45
  begin
40
- d = cipher.update(password)
46
+ d = cipher.update(cipher_text)
41
47
  d << cipher.final
42
48
  rescue OpenSSL::Cipher::CipherError => err
43
49
  puts "Coudln't decrypt password. Are you using the right keys?"
44
50
  raise err
45
51
  end
46
-
47
52
  end
48
53
  end
49
- end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module Passw3rd
2
- Version = VERSION = '0.0.5'
2
+ Version = VERSION = '0.0.6'
3
3
  end
data/lib/passw3rd.rb CHANGED
@@ -3,5 +3,4 @@ require 'openssl'
3
3
  require 'optparse'
4
4
  require File.expand_path('../passw3rd/key_loader', __FILE__)
5
5
  require File.expand_path('../passw3rd/password_service', __FILE__)
6
- require File.expand_path('../passw3rd/password_client', __FILE__)
7
6
 
@@ -16,6 +16,21 @@ class PasswordServiceTest < Test::Unit::TestCase
16
16
 
17
17
  assert_equal(@random_string, dec)
18
18
  end
19
+
20
+ def test_set_and_get_password
21
+ ::Passw3rd::KeyLoader.create_key_iv_file(Dir.tmpdir)
22
+ password_file = ::Passw3rd::PasswordService.write_password_file(@random_string, "test", Dir.tmpdir)
23
+ decrypted = Passw3rd::PasswordService.get_password("test", Dir.tmpdir)
24
+ assert_equal(@random_string, decrypted)
25
+ end
26
+
27
+ def test_set_and_get_password_custom_dir
28
+ ::Passw3rd::PasswordService.password_file_dir = Dir.tmpdir
29
+ ::Passw3rd::KeyLoader.create_key_iv_file(Dir.tmpdir)
30
+ password_file = ::Passw3rd::PasswordService.write_password_file(@random_string, "test2")
31
+ decrypted = Passw3rd::PasswordService.get_password("test2")
32
+ assert_equal(@random_string, decrypted)
33
+ end
19
34
 
20
35
  def test_gen_key
21
36
  ::Passw3rd::KeyLoader.create_key_iv_file(Dir.tmpdir)
metadata CHANGED
@@ -1,74 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: passw3rd
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Neil Matatall
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-24 00:00:00 Z
12
+ date: 2011-10-02 00:00:00.000000000Z
19
13
  dependencies: []
20
-
21
- description: Generate a key/iv file, generate passwords, and store encrypted files in source control, keep the key/iv safe!
22
- email:
14
+ description: Generate a key/iv file, generate passwords, and store encrypted files
15
+ in source control, keep the key/iv safe!
16
+ email:
23
17
  - neil.matatall@gmail.com
24
- executables:
18
+ executables:
25
19
  - passw3rd
26
20
  extensions: []
27
-
28
21
  extra_rdoc_files: []
29
-
30
- files:
31
- - README
22
+ files:
23
+ - README.md
32
24
  - LICENSE
25
+ - EXAMPLES
26
+ - History.txt
33
27
  - lib/passw3rd/key_loader.rb
34
28
  - lib/passw3rd/password_client.rb
35
29
  - lib/passw3rd/password_service.rb
36
30
  - lib/passw3rd/version.rb
37
31
  - lib/passw3rd.rb
38
32
  - bin/passw3rd
39
- - test/test_password_service.rb
33
+ - test/password_service_test.rb
40
34
  homepage: https://github.com/oreoshake/passw3rd
41
35
  licenses: []
42
-
43
36
  post_install_message:
44
37
  rdoc_options: []
45
-
46
- require_paths:
38
+ require_paths:
47
39
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
40
+ required_ruby_version: !ruby/object:Gem::Requirement
49
41
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- hash: 3
54
- segments:
55
- - 0
56
- version: "0"
57
- required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
47
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
66
52
  requirements: []
67
-
68
53
  rubyforge_project:
69
54
  rubygems_version: 1.8.10
70
55
  signing_key:
71
56
  specification_version: 3
72
57
  summary: A simple "keep the passwords out of source code and config files".
73
58
  test_files: []
74
-
data/README DELETED
@@ -1,27 +0,0 @@
1
- == DESCRIPTION:
2
-
3
- * Programmatic Password Crytpo
4
-
5
- == FEATURES/PROBLEMS:
6
-
7
- * Simple mechanism to store encrypted values using keys on the system
8
-
9
- == SYNOPSIS:
10
-
11
- require 'password_service'
12
-
13
- == REQUIREMENTS:
14
-
15
- openssl
16
- base64
17
- optparse
18
-
19
- == INSTALL:
20
-
21
- * gem install programmatic_crypto
22
-
23
- == DEVELOPERS:
24
-
25
- == LICENSE:
26
-
27
- MIT