hoodie 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/lib/hoodie/obfuscate.rb +13 -13
- data/lib/hoodie/{path_finder.rb → rash.rb} +33 -5
- data/lib/hoodie/stash/disk_store.rb +9 -11
- data/lib/hoodie/version.rb +1 -1
- data/lib/hoodie.rb +0 -2
- metadata +3 -4
- data/lib/hoodie/file.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e46f18510e5d271dc609c2e510f08f7d0d49d25
|
4
|
+
data.tar.gz: 43349beea6d6c2fca52e534eac69ecfd9c146999
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 270b6fec98410b23e1c4900b5336d52307d0278413e7a23d3f63ec32dbd78dea8be314cd934d6ef9e0bae0e714ffa8c27adc01c83437bdbd6d0eabfe2eb9d879
|
7
|
+
data.tar.gz: 14e4012d160e7878054b8c0f938b092447a5cd016e15efbb4043cbef07d1451b2fd4d72c45335114378f7091b7b98be5589f5bcbfdd9b1a1229f324041f338ee
|
data/Rakefile
CHANGED
data/lib/hoodie/obfuscate.rb
CHANGED
@@ -29,12 +29,12 @@ module Hoodie
|
|
29
29
|
end
|
30
30
|
|
31
31
|
require 'digest/sha2'
|
32
|
-
require
|
32
|
+
require 'base64'
|
33
33
|
|
34
34
|
# Befuddle and enlighten values in StashCache::Store
|
35
35
|
#
|
36
36
|
module Obfuscate
|
37
|
-
ESOTERIC_TYPE =
|
37
|
+
ESOTERIC_TYPE = 'aes-256-cbc' unless defined?(ESOTERIC_TYPE)
|
38
38
|
|
39
39
|
def self.check_platform_can_discombobulate!
|
40
40
|
return true unless INCOMPREHENSIBLE_ERROR
|
@@ -49,7 +49,7 @@ module Hoodie
|
|
49
49
|
# @return [String] befuddleed text, suitable for deciphering with
|
50
50
|
# Obfuscate#enlighten (decrypt)
|
51
51
|
#
|
52
|
-
def self.befuddle plaintext, befuddle_pass, options={}
|
52
|
+
def self.befuddle plaintext, befuddle_pass, options = {}
|
53
53
|
cipher = new_cipher :befuddle, befuddle_pass, options
|
54
54
|
cipher.iv = iv = cipher.random_iv
|
55
55
|
ciphertext = cipher.update(plaintext)
|
@@ -61,11 +61,11 @@ module Hoodie
|
|
61
61
|
#
|
62
62
|
# @param ciphertext the text to enlighten, probably produced with
|
63
63
|
# Obfuscate#befuddle (encrypt)
|
64
|
-
# @param [String] befuddle_pass secret
|
64
|
+
# @param [String] befuddle_pass secret sauce to enlighten with
|
65
65
|
#
|
66
66
|
# @return [String] the enlightened plaintext
|
67
67
|
#
|
68
|
-
def self.enlighten enc_ciphertext, befuddle_pass, options={}
|
68
|
+
def self.enlighten enc_ciphertext, befuddle_pass, options = {}
|
69
69
|
iv_and_ciphertext = Base64.decode64(enc_ciphertext)
|
70
70
|
cipher = new_cipher :enlighten, befuddle_pass, options
|
71
71
|
cipher.iv, ciphertext = separate_iv_and_ciphertext(cipher, iv_and_ciphertext)
|
@@ -80,41 +80,41 @@ module Hoodie
|
|
80
80
|
# direction to infinity
|
81
81
|
#
|
82
82
|
# @param [:befuddle, :enlighten] to befuddle or enlighten
|
83
|
-
# @param [String] befuddle_pass secret
|
83
|
+
# @param [String] befuddle_pass secret sauce to enlighten with
|
84
84
|
#
|
85
|
-
def self.new_cipher direction, befuddle_pass, options={}
|
85
|
+
def self.new_cipher direction, befuddle_pass, options = {}
|
86
86
|
check_platform_can_discombobulate!
|
87
87
|
cipher = OpenSSL::Cipher::Cipher.new(ESOTERIC_TYPE)
|
88
88
|
case direction
|
89
89
|
when :befuddle
|
90
90
|
cipher.encrypt
|
91
91
|
when :enlighten
|
92
|
-
|
92
|
+
cipher.decrypt
|
93
93
|
else raise "Bad cipher direction #{direction}"
|
94
94
|
end
|
95
95
|
cipher.key = befuddle_key(befuddle_pass, options)
|
96
96
|
cipher
|
97
97
|
end
|
98
98
|
|
99
|
-
#
|
99
|
+
# vector inspect encoder serialize prepend initialization message
|
100
100
|
def self.combine_iv_and_ciphertext iv, message
|
101
101
|
message.force_encoding("BINARY") if message.respond_to?(:force_encoding)
|
102
102
|
iv.force_encoding("BINARY") if iv.respond_to?(:force_encoding)
|
103
103
|
iv + message
|
104
104
|
end
|
105
105
|
|
106
|
-
#
|
106
|
+
# front vector initialization, encoded pull message
|
107
107
|
def self.separate_iv_and_ciphertext cipher, iv_and_ciphertext
|
108
108
|
idx = cipher.iv_len
|
109
109
|
[ iv_and_ciphertext[0..(idx-1)], iv_and_ciphertext[idx..-1] ]
|
110
110
|
end
|
111
111
|
|
112
|
-
# Convert the befuddle_pass passphrase into the key used for
|
112
|
+
# Convert the befuddle_pass passphrase into the key used for
|
113
|
+
# befuddletion
|
113
114
|
def self.befuddle_key befuddle_pass, options={}
|
114
115
|
befuddle_pass = befuddle_pass.to_s
|
115
116
|
raise 'Missing befuddled password!' if befuddle_pass.empty?
|
116
|
-
#
|
117
|
-
# cipher
|
117
|
+
# 256 beers on the wall, keys for cipher required of aes cbc
|
118
118
|
Digest::SHA256.digest(befuddle_pass)
|
119
119
|
end
|
120
120
|
end
|
@@ -18,26 +18,54 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
# TODO: This doesn't belong in here, it's cookbook specific...
|
21
|
-
require 'anemone'
|
21
|
+
require 'anemone' unless defined?(Anemone)
|
22
22
|
require 'hoodie/memoizable' unless defined?(Memoizable)
|
23
23
|
|
24
|
-
class
|
24
|
+
class Rash
|
25
25
|
include Memoizable
|
26
26
|
|
27
|
-
def initialize(url)
|
27
|
+
def initialize(url, path)
|
28
28
|
@url = url
|
29
|
+
@path = path
|
29
30
|
memoize [:fetch], Stash.new(DiskStash::Cache.new)
|
31
|
+
@store = fetch
|
30
32
|
end
|
31
33
|
|
32
|
-
def fetch
|
34
|
+
def fetch
|
33
35
|
results = []
|
34
36
|
Anemone.crawl(@url, discard_page_bodies: true) do |anemone|
|
35
|
-
anemone.on_pages_like(/\/#{path}\/\w+\/\w+\.(ini|zip)$/i) do |page|
|
37
|
+
anemone.on_pages_like(/\/#{@path}\/\w+\/\w+\.(ini|zip)$/i) do |page|
|
36
38
|
results << page.to_hash
|
37
39
|
end
|
38
40
|
end
|
39
41
|
results.reduce({}, :recursive_merge)
|
40
42
|
end
|
43
|
+
|
44
|
+
# Retrieves the value for a given key
|
45
|
+
#
|
46
|
+
# @param key [Symbol, String] representing the key
|
47
|
+
#
|
48
|
+
# @return [Hash, Array, String] value for key
|
49
|
+
#
|
50
|
+
def [](key)
|
51
|
+
@store[key]
|
52
|
+
end
|
53
|
+
|
54
|
+
# return the size of the store as an integer
|
55
|
+
#
|
56
|
+
# @return [Fixnum]
|
57
|
+
#
|
58
|
+
def size
|
59
|
+
@store.size
|
60
|
+
end
|
61
|
+
|
62
|
+
# return all keys in the store as an array
|
63
|
+
#
|
64
|
+
# @return [Array<String, Symbol>] all the keys in store
|
65
|
+
#
|
66
|
+
def keys
|
67
|
+
@store.keys
|
68
|
+
end
|
41
69
|
end
|
42
70
|
|
43
71
|
# to_hash smoke cache
|
@@ -36,7 +36,7 @@ module DiskStash
|
|
36
36
|
#
|
37
37
|
def initialize(store = file_store)
|
38
38
|
@store = store
|
39
|
-
|
39
|
+
_ensure_store_directory
|
40
40
|
end
|
41
41
|
|
42
42
|
# Clear the whole stash or the value of a key
|
@@ -58,23 +58,21 @@ module DiskStash
|
|
58
58
|
end
|
59
59
|
|
60
60
|
# Retrieves the value for a given key, if nothing is set,
|
61
|
-
# returns
|
61
|
+
# returns nil
|
62
62
|
#
|
63
63
|
# @param key [Symbol, String] representing the key
|
64
64
|
#
|
65
|
-
# @raise [KeyError] if no such key found
|
66
|
-
#
|
67
65
|
# @return [Hash, Array, String] value for key
|
68
66
|
#
|
69
67
|
def [](key)
|
70
68
|
if key.is_a? Array
|
71
69
|
hash = {}
|
72
70
|
key.each do |k|
|
73
|
-
hash[k] = Marshal::load(
|
71
|
+
hash[k] = Marshal::load(_read_cache_file(k))
|
74
72
|
end
|
75
73
|
hash unless hash.empty?
|
76
74
|
else
|
77
|
-
Marshal::load(
|
75
|
+
Marshal::load(_read_cache_file(key))
|
78
76
|
end
|
79
77
|
rescue Errno::ENOENT
|
80
78
|
nil # key hasn't been created
|
@@ -83,7 +81,7 @@ module DiskStash
|
|
83
81
|
# Store the given value with the given key, either an an argument
|
84
82
|
# or block. If a previous value was set it will be overwritten
|
85
83
|
# with the new value.
|
86
|
-
#
|
84
|
+
#
|
87
85
|
# @param key [Symbol, String] representing the key
|
88
86
|
# @param value [Object] that represents the value (optional)
|
89
87
|
# @param block [&block] that returns the value to set (optional)
|
@@ -91,7 +89,7 @@ module DiskStash
|
|
91
89
|
# @return nothing.
|
92
90
|
#
|
93
91
|
def []=(key, value)
|
94
|
-
|
92
|
+
_write_cache_file(key, Marshal::dump(value))
|
95
93
|
end
|
96
94
|
|
97
95
|
# returns path to cache file with 'key'
|
@@ -123,7 +121,7 @@ module DiskStash
|
|
123
121
|
path.gsub!(::File::SEPARATOR, (::File::ALT_SEPARATOR || '\\'))
|
124
122
|
end
|
125
123
|
|
126
|
-
def
|
124
|
+
def _write_cache_file(key, content)
|
127
125
|
f = ::File.open(cache_file(key), 'w+' )
|
128
126
|
f.flock(::File::LOCK_EX)
|
129
127
|
f.write(content)
|
@@ -131,7 +129,7 @@ module DiskStash
|
|
131
129
|
content
|
132
130
|
end
|
133
131
|
|
134
|
-
def
|
132
|
+
def _read_cache_file(key)
|
135
133
|
f = ::File.open(cache_file(key), 'r')
|
136
134
|
f.flock(::File::LOCK_SH)
|
137
135
|
out = f.read
|
@@ -144,7 +142,7 @@ module DiskStash
|
|
144
142
|
::File.mtime(cache_file(key))
|
145
143
|
end
|
146
144
|
|
147
|
-
def
|
145
|
+
def _ensure_store_directory
|
148
146
|
::Dir.mkdir(store) unless ::File.directory?(store)
|
149
147
|
end
|
150
148
|
end
|
data/lib/hoodie/version.rb
CHANGED
data/lib/hoodie.rb
CHANGED
@@ -19,13 +19,11 @@
|
|
19
19
|
|
20
20
|
require 'hoodie/stash/mem_store'
|
21
21
|
require 'hoodie/stash/disk_store'
|
22
|
-
require 'hoodie/path_finder'
|
23
22
|
require 'hoodie/memoizable'
|
24
23
|
require 'hoodie/obfuscate'
|
25
24
|
require 'hoodie/version'
|
26
25
|
require 'hoodie/utils'
|
27
26
|
require 'hoodie/stash'
|
28
27
|
require 'hoodie/blank'
|
29
|
-
require 'hoodie/file'
|
30
28
|
require 'hoodie/hash'
|
31
29
|
require 'hoodie/os'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Harding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anemone
|
@@ -122,12 +122,11 @@ files:
|
|
122
122
|
- hoodie.gemspec
|
123
123
|
- lib/hoodie.rb
|
124
124
|
- lib/hoodie/blank.rb
|
125
|
-
- lib/hoodie/file.rb
|
126
125
|
- lib/hoodie/hash.rb
|
127
126
|
- lib/hoodie/memoizable.rb
|
128
127
|
- lib/hoodie/obfuscate.rb
|
129
128
|
- lib/hoodie/os.rb
|
130
|
-
- lib/hoodie/
|
129
|
+
- lib/hoodie/rash.rb
|
131
130
|
- lib/hoodie/stash.rb
|
132
131
|
- lib/hoodie/stash/disk_store.rb
|
133
132
|
- lib/hoodie/stash/mem_store.rb
|
data/lib/hoodie/file.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
-
#
|
5
|
-
# Copyright (C) 2014 Stefano Harding
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require 'fileutils'
|
21
|
-
|
22
|
-
class ::File
|
23
|
-
def self.atomic_write(file_name, temp_dir = ::Dir.tmpdir)
|
24
|
-
require 'tempfile' unless defined?(Tempfile)
|
25
|
-
require 'fileutils' unless defined?(FileUtils)
|
26
|
-
|
27
|
-
temp_file = Tempfile.new(basename(file_name), temp_dir)
|
28
|
-
temp_file.binmode
|
29
|
-
yield temp_file
|
30
|
-
temp_file.close
|
31
|
-
|
32
|
-
if ::File.exist?(file_name)
|
33
|
-
# Get original file permissions
|
34
|
-
old_stat = stat(file_name)
|
35
|
-
else
|
36
|
-
# If not possible, probe which are the default permissions in the
|
37
|
-
# destination directory.
|
38
|
-
old_stat = probe_stat_in(dirname(file_name))
|
39
|
-
end
|
40
|
-
|
41
|
-
# Overwrite original file with temp file
|
42
|
-
FileUtils.mv(temp_file.path, file_name)
|
43
|
-
|
44
|
-
# Set correct permissions on new file
|
45
|
-
begin
|
46
|
-
chown(old_stat.uid, old_stat.gid, file_name)
|
47
|
-
# This operation will affect filesystem ACL's
|
48
|
-
chmod(old_stat.mode, file_name)
|
49
|
-
rescue Errno::EPERM
|
50
|
-
# Changing file ownership failed, moving on.
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Private utility method.
|
55
|
-
def self.probe_stat_in(dir) #:nodoc:
|
56
|
-
basename = [
|
57
|
-
'.permissions_check',
|
58
|
-
Thread.current.object_id,
|
59
|
-
Process.pid,
|
60
|
-
rand(1000000)
|
61
|
-
].join('.')
|
62
|
-
|
63
|
-
file_name = join(dir, basename)
|
64
|
-
FileUtils.touch(file_name)
|
65
|
-
stat(file_name)
|
66
|
-
ensure
|
67
|
-
FileUtils.rm_f(file_name) if file_name
|
68
|
-
end
|
69
|
-
end
|