shh 0.0.3 → 0.0.4

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/MIT-LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 Mark Ryall
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2009 Mark Ryall
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
- = SHH
2
-
3
- Secret Squirrel
4
-
5
- This is a command line utility for managing secure information such as accounts, passwords as individual files so that they can be easily managed in a version control repository.
6
-
7
- You won't be hiding anything from the NSA with this level of encryption so it isn't recommended that you make your repository publicly accessible.
1
+ = SHH
2
+
3
+ Secret Squirrel
4
+
5
+ This is a command line utility for managing secure information such as accounts, passwords as individual files so that they can be easily managed in a version control repository.
6
+
7
+ You won't be hiding anything from the NSA with this level of encryption so it isn't recommended that you make your repository publicly accessible.
data/bin/shh CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift File.dirname(__FILE__)+'/../lib'
4
- require 'shh'
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__)+'/../lib'
4
+ require 'shh'
5
5
  Shh::Cli.new.execute(*ARGV)
data/lib/shh/cli.rb CHANGED
@@ -1,95 +1,92 @@
1
- require 'rubygems'
2
- require 'pathname2'
3
- require 'highline/import'
4
- require 'uuid'
5
- require 'shh/crypt'
6
- require 'yaml'
7
- require 'pathname2' # don't ask why i'm loading this twice
8
-
9
- module Shh
10
- class Cli
11
- def execute *args
12
- passphrase = ask('Enter your passphrase') { |q| q.echo = false }
13
-
14
- @uuid = UUID.new
15
- @folder = Pathname.new('secret')
16
- @folder.mkdir_p
17
- @crypt = Crypt.new(passphrase)
18
-
19
- loop do
20
- choose do |menu|
21
- menu.layout = :menu_only
22
- menu.shell = true
23
- menu.choice('list entries') { list }
24
- menu.choice('create entry') { |command, details| create details }
25
- menu.choice('edit entry') { |command, details| edit details }
26
- menu.choice('view entry') { |command, details| view details }
27
- menu.choice('quit') { exit }
28
- end
29
- end
30
- end
31
-
32
- def list
33
- each_entry {|entry| say "#{entry['name']} - #{entry['id']}" }
34
- end
35
-
36
- def create name=''
37
- hash = {'name' => check_name(name), 'id' => @uuid.generate}
38
- persist_entry prompt_loop(hash)
39
- end
40
-
41
- def edit name=''
42
- name = check_name(name)
43
- persist_entry prompt_loop(find_entry(name))
44
- end
45
-
46
- def view name=''
47
- prompt_loop load_entry(check_name(name)), true
48
- end
49
-
50
- private
51
-
52
- def each_entry
53
- @folder.children.each do |child|
54
- yield load_entry(child)
55
- end
56
- end
57
-
58
- def check_name name
59
- name = ask('Enter the entry name') unless name.size > 0
60
- name
61
- end
62
-
63
- def find_entry name
64
- each_entry {|e| return e if e['name'] == name}
65
- end
66
-
67
- def load_entry path
68
- entry = path.open('r') {|io| @crypt.decrypt(io) }
69
- YAML::load(entry)
70
- end
71
-
72
- def persist_entry entry
73
- (@folder + entry['id']).open('w') {|io| @crypt.encrypt(entry.to_yaml, io) }
74
- end
75
-
76
- def prompt_loop hash, read_only=false
77
- loop do
78
- choose do |menu|
79
- menu.layout = :menu_only
80
- menu.shell = true
81
- menu.choice('create key') { |command, name| hash[name] = new_value(name) } unless read_only
82
- menu.choice('list keys') { say(hash.keys.sort.join(',')) }
83
- menu.choice('show key') { |command, name| say(hash[name]) if hash[name] }
84
- menu.choice('delete key') { |command, name| hash[name] = nil } unless read_only
85
- menu.choice('quit') { return hash }
86
- end
87
- end
88
- end
89
-
90
- def new_value name
91
- echo = (name =~ /pass/) ? false : true
92
- ask("Enter new value for #{name}") {|q| q.echo = echo }
93
- end
94
- end
95
- end
1
+ require 'rubygems'
2
+ require 'pathname2'
3
+ require 'highline/import'
4
+ require 'uuidtools'
5
+ require 'yaml'
6
+ require 'shh/crypt'
7
+ require 'shh/clipboard'
8
+
9
+ module Shh
10
+ class Cli
11
+ def execute *args
12
+ passphrase = ask('Enter your passphrase') { |q| q.echo = false }
13
+
14
+ @folder = Pathname.new('secret')
15
+ @folder.mkdir_p
16
+ @crypt = Crypt.new(passphrase)
17
+ @clipboard = Shh.clipboard
18
+
19
+ loop do
20
+ choose do |menu|
21
+ menu.layout = :menu_only
22
+ menu.shell = true
23
+ menu.choice('list entries') { list }
24
+ menu.choice('edit entry') { |command, details| edit details }
25
+ menu.choice('view entry') { |command, details| view details }
26
+ menu.choice('quit') { exit }
27
+ end
28
+ end
29
+ end
30
+
31
+ def list
32
+ each_entry {|entry| say "#{entry['name']} (#{entry['id']})" }
33
+ end
34
+
35
+ def edit name=''
36
+ entry = find_entry(check_name(name))
37
+ entry ||= {'name' => check_name(name), 'id' => UUIDTools::UUID.random_create.to_s}
38
+ persist_entry prompt_loop(entry)
39
+ end
40
+
41
+ def view name=''
42
+ prompt_loop find_entry(check_name(name)), true
43
+ end
44
+
45
+ private
46
+
47
+ def each_entry
48
+ @folder.children.each do |child|
49
+ yield load_entry(child)
50
+ end
51
+ end
52
+
53
+ def check_name name
54
+ name = ask('Enter the entry name') unless name.size > 0
55
+ name
56
+ end
57
+
58
+ def find_entry name
59
+ each_entry {|e| return e if e['name'] == name}
60
+ nil
61
+ end
62
+
63
+ def load_entry path
64
+ entry = path.open('rb') {|io| @crypt.decrypt(io) }
65
+ YAML::load(entry)
66
+ end
67
+
68
+ def persist_entry entry
69
+ (@folder + entry['id']).open('wb') {|io| @crypt.encrypt(entry.to_yaml, io) }
70
+ end
71
+
72
+ def prompt_loop hash, read_only=false
73
+ loop do
74
+ choose do |menu|
75
+ menu.layout = :menu_only
76
+ menu.shell = true
77
+ menu.choice('edit key') { |command, name| hash[name] = new_value(name) } unless read_only
78
+ menu.choice('list keys') { say(hash.keys.sort.join(',')) }
79
+ menu.choice('show key') { |command, name| say(hash[name]) if hash[name] }
80
+ menu.choice('delete key') { |command, name| hash[name] = nil } unless read_only
81
+ menu.choice('copy key') { |command, name| @clipboard.content = hash[name] } if @clipboard
82
+ menu.choice('quit') { return hash }
83
+ end
84
+ end
85
+ end
86
+
87
+ def new_value name
88
+ echo = (name =~ /pass/) ? false : true
89
+ ask("Enter new value for #{name}") {|q| q.echo = echo }
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,9 @@
1
+ module Shh
2
+ def self.clipboard
3
+ if RUBY_PLATFORM =~ /mswin32/
4
+ require 'shh/win32_clipboard'
5
+ return Win32Clipboard.new
6
+ end
7
+ nil
8
+ end
9
+ end
data/lib/shh/crypt.rb CHANGED
@@ -1,25 +1,25 @@
1
- require 'crypt/blowfish'
2
-
3
- module Shh
4
- class Crypt
5
- def initialize passphrase
6
- @blowfish = ::Crypt::Blowfish.new(passphrase)
7
- end
8
-
9
- def encrypt text, out_io
10
- in_io = StringIO.new(text)
11
- while l = in_io.read(8) do
12
- while l.size < 8 do l += "\0" end
13
- out_io.print @blowfish.encrypt_block(l)
14
- end
15
- end
16
-
17
- def decrypt in_io
18
- out_io = StringIO.new
19
- while l = in_io.read(8) do
20
- out_io.print @blowfish.decrypt_block(l)
21
- end
22
- out_io.string.gsub("\0",'')
23
- end
24
- end
1
+ require 'crypt/blowfish'
2
+
3
+ module Shh
4
+ class Crypt
5
+ def initialize passphrase
6
+ @blowfish = ::Crypt::Blowfish.new(passphrase)
7
+ end
8
+
9
+ def encrypt text, out_io
10
+ in_io = StringIO.new(text)
11
+ while l = in_io.read(8) do
12
+ while l.size < 8 do l += "\0" end
13
+ out_io.print @blowfish.encrypt_block(l)
14
+ end
15
+ end
16
+
17
+ def decrypt in_io
18
+ out_io = StringIO.new
19
+ while l = in_io.read(8) do
20
+ out_io.print @blowfish.decrypt_block(l)
21
+ end
22
+ out_io.string.gsub("\0",'')
23
+ end
24
+ end
25
25
  end
@@ -0,0 +1,15 @@
1
+ require 'win32/clipboard'
2
+
3
+ class Win32Clipboard
4
+ def content
5
+ Win32::Clipboard.data
6
+ end
7
+
8
+ def content= text
9
+ Win32::Clipboard.set_data(text)
10
+ end
11
+
12
+ def clear
13
+ Win32::Clipboard.empty
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
@@ -23,14 +23,14 @@ dependencies:
23
23
  version: 1.5.1
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: uuid
26
+ name: uuidtools
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 2.1.0
33
+ version: 2.1.1
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: crypt
@@ -64,7 +64,9 @@ extra_rdoc_files: []
64
64
 
65
65
  files:
66
66
  - lib/shh/cli.rb
67
+ - lib/shh/clipboard.rb
67
68
  - lib/shh/crypt.rb
69
+ - lib/shh/win32_clipboard.rb
68
70
  - lib/shh.rb
69
71
  - bin/shh
70
72
  - README.rdoc