wutang 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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wutang.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Justin Mazzi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Wutang
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'wutang'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wutang
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
3
+
4
+ require 'wutang'
5
+
6
+ interface = Wutang::Interface.new
7
+ cli = Wutang::Cli.new(interface)
8
+ cli.handle
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+ require 'securerandom'
3
+ require 'base64'
4
+ require 'yaml'
5
+
6
+ require "wutang/version"
7
+ require "wutang/interface"
8
+ require "wutang/cli"
9
+ require "wutang/encryption"
10
+ require "wutang/entry"
11
+ require "wutang/persistence"
12
+ require "wutang/config"
13
+
14
+ module Wutang
15
+ end
@@ -0,0 +1,52 @@
1
+ module Wutang
2
+ class Cli
3
+ PUBLIC_COMMANDS = [:create, :update, :search, :list]
4
+ attr_reader :command, :args, :wutang
5
+
6
+ def initialize(wutang)
7
+ @command = ARGV.shift.to_s.to_sym
8
+ @args = ARGV
9
+ @wutang = wutang
10
+ end
11
+
12
+ def handle
13
+ if PUBLIC_COMMANDS.include?(command)
14
+ send(command)
15
+ else
16
+ puts "Unknown command #{command}"
17
+ end
18
+ end
19
+
20
+ def create
21
+ entry = wutang.create attributes
22
+ puts "Created #{entry}"
23
+ end
24
+
25
+ def update
26
+ if entry = wutang.find(args.shift)
27
+ wutang.update entry, attributes
28
+ puts "Entry updated with the following changes: #{attributes}"
29
+ else
30
+ puts "Entry not found"
31
+ end
32
+ end
33
+
34
+ def search
35
+ criteria = args.shift
36
+ puts wutang.search criteria
37
+ end
38
+
39
+ def list
40
+ puts wutang.entries
41
+ end
42
+
43
+ def attributes
44
+ {}.tap do|hash|
45
+ args.each do |arg|
46
+ key, value = arg.split(':')
47
+ hash[key.to_sym] = value
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ module Wutang
2
+ class Config
3
+ attr_reader :config_file, :attributes
4
+
5
+ def initialize
6
+ @config_file = File.expand_path('~/.wutang.yml')
7
+ parse
8
+ end
9
+
10
+ def parse
11
+ if File.world_readable?(config_file)
12
+ puts "Your config file has world readable permissions"
13
+ puts "Please run: chmod 640 ~/.wutang.yml"
14
+ exit 1
15
+ elsif File.exists?(config_file)
16
+ @attributes = YAML.load_file(config_file)
17
+ else
18
+ puts "Please create a ~/.wutang.yml with a `path` and `pasphrase`"
19
+ exit 1
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module Wutang
2
+ class Encryption
3
+ SEPARATOR = ":36_chambers:"
4
+
5
+ attr_accessor :key, :aes
6
+
7
+ def initialize(passphrase)
8
+ @aes = ::OpenSSL::Cipher::Cipher.new("AES-256-CBC")
9
+ @aes.padding = 1
10
+ @key = Digest::SHA256.digest(passphrase)
11
+ end
12
+
13
+ def encrypt(value)
14
+ return value if value == '' || value.nil?
15
+ aes.encrypt
16
+ aes.key = key
17
+ Base64::encode64("#{aes.random_iv}#{SEPARATOR}#{aes.update(value.to_s) + aes.final}")
18
+ end
19
+
20
+ def decrypt(value)
21
+ return value if value == '' || value.nil?
22
+ iv, value = Base64::decode64(value.to_s).split(SEPARATOR)
23
+ aes.decrypt
24
+ aes.key = key
25
+ aes.iv = iv
26
+ aes.update(value) + aes.final
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module Wutang
2
+ class Entry
3
+ attr_reader :attributes, :path
4
+
5
+ def initialize(attributes, path)
6
+ @attributes = attributes
7
+ @path = path
8
+ end
9
+
10
+ def [](key)
11
+ attributes[key]
12
+ end
13
+
14
+ def []=(key, value)
15
+ attributes[key] = value
16
+ end
17
+
18
+ def as_json
19
+ attributes
20
+ end
21
+
22
+ def to_s
23
+ attributes.merge(id: path).to_s
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ module Wutang
2
+ class Interface
3
+ attr_reader :persistence, :config
4
+
5
+ def initialize
6
+ @config = Config.new.attributes
7
+ end
8
+
9
+ def persistence
10
+ @persistence ||= Persistence.new(config['path'], config['passphrase'])
11
+ end
12
+
13
+ def entries
14
+ persistence.all
15
+ end
16
+
17
+ def create(attributes)
18
+ Entry.new(attributes, Persistence.generate_filename).tap do |entry|
19
+ persistence.write entry.path, entry.as_json
20
+ end
21
+ end
22
+
23
+ def update(entry, updates)
24
+ entry.tap do
25
+ entry.attributes.merge! updates
26
+ persistence.write entry.path, entry.as_json
27
+ end
28
+ end
29
+
30
+ def search(criteria)
31
+ entries.select do |entry|
32
+ attributes = entry.attributes
33
+ attributes.keys.any? { |key| attributes[key] =~ /#{criteria}/ }
34
+ end
35
+ end
36
+
37
+ def find(entry_id)
38
+ entries.detect { |entry| entry.path == entry_id }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ module Wutang
2
+ class Persistence
3
+ attr_reader :path, :crypto
4
+
5
+ def initialize(path, passphrase)
6
+ @path = File.expand_path(path)
7
+ @crypto = Encryption.new(passphrase)
8
+ Dir.mkdir(@path) unless File.exists?(@path)
9
+ end
10
+
11
+ def read(filename)
12
+ data = IO.read("#{path}/#{filename}.json")
13
+ plaintext = crypto.decrypt(data)
14
+
15
+ JSON.parse(plaintext, symbolize_names: true)
16
+ end
17
+
18
+ def write(filename, content)
19
+ File.open("#{path}/#{filename}.json", "w") do |f|
20
+ ciphertext = crypto.encrypt(content.to_json)
21
+ f.write ciphertext
22
+ end
23
+ end
24
+
25
+ def all
26
+ files.map do |file|
27
+ content = read(file)
28
+ Entry.new(content, file)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def files
35
+ Dir["#{path}/*.json"].map { |f| File.basename(f, '.json') }
36
+ end
37
+
38
+ def self.generate_filename
39
+ "#{SecureRandom.uuid}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Wutang
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wutang/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wutang"
8
+ spec.version = Wutang::VERSION
9
+ spec.authors = ["Justin Mazzi"]
10
+ spec.email = ["jmazzi@gmail.com"]
11
+ spec.description = %q{An experimental command line password manager}
12
+ spec.summary = %q{An experimental command line password manager}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wutang
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Mazzi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: An experimental command line password manager
47
+ email:
48
+ - jmazzi@gmail.com
49
+ executables:
50
+ - wutang
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/wutang
60
+ - lib/wutang.rb
61
+ - lib/wutang/cli.rb
62
+ - lib/wutang/config.rb
63
+ - lib/wutang/encryption.rb
64
+ - lib/wutang/entry.rb
65
+ - lib/wutang/interface.rb
66
+ - lib/wutang/persistence.rb
67
+ - lib/wutang/version.rb
68
+ - wutang.gemspec
69
+ homepage: ''
70
+ licenses:
71
+ - MIT
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.23
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: An experimental command line password manager
94
+ test_files: []
95
+ has_rdoc: