password_manager 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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/bin/pass_manage +35 -0
- data/lib/password_manager.rb +86 -0
- data/lib/password_manager/version.rb +3 -0
- data/password_manager.gemspec +24 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/bin/pass_manage
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'password_manager'
|
5
|
+
require 'clipboard'
|
6
|
+
|
7
|
+
PasswordManager.config_path = File.expand_path '.pass_manage', '~'
|
8
|
+
|
9
|
+
case ARGV[0]
|
10
|
+
when 'generate'
|
11
|
+
PasswordManager.generate(ARGV[1])
|
12
|
+
when 'get'
|
13
|
+
Clipboard.copy PasswordManager.get ARGV[1], ARGV[2], ARGV[3]
|
14
|
+
when 'set'
|
15
|
+
puts PasswordManager.get ARGV[1], ARGV[2], ARGV[3]
|
16
|
+
when 'remove'
|
17
|
+
if PasswordManager.remove ARGV[1]
|
18
|
+
puts 'Group succesfully removed'
|
19
|
+
else
|
20
|
+
puts "Group can't be removed"
|
21
|
+
end
|
22
|
+
when 'change_password'
|
23
|
+
PasswordManager.change_password ARGV[1]
|
24
|
+
when 'import'
|
25
|
+
PasswordManager.import ARGV[1]
|
26
|
+
when 'export'
|
27
|
+
PasswordManager.export ARGV[1]
|
28
|
+
when 'list'
|
29
|
+
puts "Groups:"
|
30
|
+
PasswordManager.list.each do |group|
|
31
|
+
puts " * #{group}"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
puts "Allowed commands: generate, get and set"
|
35
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'highline'
|
2
|
+
require 'highline/import'
|
3
|
+
|
4
|
+
require 'openssl'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module PasswordManager
|
8
|
+
def self.config_path=(config_path)
|
9
|
+
@config_path = config_path
|
10
|
+
Dir.mkdir(@config_path) unless Dir.exists?(@config_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.generate(group)
|
14
|
+
group ||= 'default'
|
15
|
+
key_pair = OpenSSL::PKey::RSA.generate 1024
|
16
|
+
|
17
|
+
password = ask_password false
|
18
|
+
store_keys group, key_pair, password
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.change_password(group)
|
22
|
+
password = ask("Password:"){ |q| q.echo = '*' }
|
23
|
+
new_password = ask_password false
|
24
|
+
|
25
|
+
rsa = OpenSSL::PKey::RSA.new File.read( group_path(group) ), password
|
26
|
+
store_keys group, rsa, new_password
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.export(group)
|
30
|
+
password = ask("Password:"){ |q| q.echo = '*' }
|
31
|
+
new_password = ask_password false
|
32
|
+
|
33
|
+
rsa = OpenSSL::PKey::RSA.new File.read( group_path(group) ), password
|
34
|
+
store_keys group, rsa, new_password, "#{group}.pem"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.import(group)
|
38
|
+
password = ask("Password:"){ |q| q.echo = '*' }
|
39
|
+
new_password = ask_password false
|
40
|
+
|
41
|
+
rsa = OpenSSL::PKey::RSA.new File.read( "#{group}.pem" ), password
|
42
|
+
store_keys group, rsa, new_password
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.remove(group)
|
46
|
+
if self.get('whatever', group)
|
47
|
+
File.delete group_path(group)
|
48
|
+
else
|
49
|
+
false
|
50
|
+
end
|
51
|
+
rescue
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.list
|
56
|
+
Dir.glob(File.join @config_path, "*.pem").map{ |x| File.basename(x).match(/([^\.]*)\./)[1] }
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.get(service, group, size = nil)
|
60
|
+
group ||= 'default'
|
61
|
+
size ||= 16
|
62
|
+
rsa = OpenSSL::PKey::RSA.new File.read( group_path group ), ask_password
|
63
|
+
Base64.encode64(rsa.private_encrypt(service)).gsub(/[\+\/]/, '').chomp[0..size.to_i]
|
64
|
+
rescue
|
65
|
+
puts "Invalid password or group or something else"
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.group_path(group)
|
69
|
+
File.join @config_path, "#{group}.pem"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.store_keys(group, rsa, password, path = group_path(group))
|
73
|
+
cipher = OpenSSL::Cipher::Cipher.new 'aes-256-cbc'
|
74
|
+
private_key = rsa.to_pem cipher, password
|
75
|
+
public_key = rsa.public_key.to_pem cipher, password
|
76
|
+
File.open(path, 'w'){ |f| f.puts(private_key + public_key) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.ask_password(confirmed = true)
|
80
|
+
password = ask("Password:"){ |q| q.echo = '*' }
|
81
|
+
return password if confirmed
|
82
|
+
|
83
|
+
raise "Passwords didn't match" if ask("Confirm password:"){ |q| q.echo = '*' } != password
|
84
|
+
password
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "password_manager/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "password_manager"
|
7
|
+
s.version = PasswordManager::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Dalton Pinto"]
|
10
|
+
s.email = ["dalthon@alun.ita.br"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A very simple password manager for more secure passwords}
|
13
|
+
s.description = %q{A very simple password manager for more secure passwords}
|
14
|
+
|
15
|
+
s.rubyforge_project = "password_manager"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'clipboard', '>= 0.9.0'
|
23
|
+
s.add_dependency 'highline', '>= 1.6.2'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: password_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dalton Pinto
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-22 00:00:00 -03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: clipboard
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 59
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 0
|
34
|
+
version: 0.9.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: highline
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 6
|
49
|
+
- 2
|
50
|
+
version: 1.6.2
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: A very simple password manager for more secure passwords
|
54
|
+
email:
|
55
|
+
- dalthon@alun.ita.br
|
56
|
+
executables:
|
57
|
+
- pass_manage
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- Rakefile
|
66
|
+
- bin/pass_manage
|
67
|
+
- lib/password_manager.rb
|
68
|
+
- lib/password_manager/version.rb
|
69
|
+
- password_manager.gemspec
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: ""
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project: password_manager
|
100
|
+
rubygems_version: 1.6.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: A very simple password manager for more secure passwords
|
104
|
+
test_files: []
|
105
|
+
|