Class: Thieve
- Inherits:
-
Object
- Object
- Thieve
- Defined in:
- lib/thieve.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#loot ⇒ Object
Returns the value of attribute loot.
Class Method Summary collapse
Instance Method Summary collapse
- #export_loot(dir, priv_only = @private) ⇒ Object
- #find_matches ⇒ Object
-
#initialize(hilight = false) ⇒ Thieve
constructor
A new instance of Thieve.
- #only_private(priv) ⇒ Object
- #steal_from(filename, ignores = Array.new, binaries = false) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hilight = false) ⇒ Thieve
Returns a new instance of Thieve.
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/thieve.rb', line 179 def initialize(hilight = false) if (ScoobyDoo.where_are_you("gpg").nil?) raise Thieve::Error::ExecutableNotFound.new("gpg") end if (ScoobyDoo.where_are_you("grep").nil?) raise Thieve::Error::ExecutableNotFound.new("grep") end @@hilight = hilight @loot = Hash.new @private = false end |
Instance Attribute Details
#loot ⇒ Object
Returns the value of attribute loot.
10 11 12 |
# File 'lib/thieve.rb', line 10 def loot @loot end |
Class Method Details
.hilight? ⇒ Boolean
168 169 170 171 |
# File 'lib/thieve.rb', line 168 def self.hilight? @@hilight ||= false return @@hilight end |
Instance Method Details
#export_loot(dir, priv_only = @private) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/thieve.rb', line 28 def export_loot(dir, priv_only = @private) exported = Hash.new @loot.each do |type, keys| next if (priv_only && !type.match(/CERTIFICATE|PRIVATE/)) keys.each do |key| if (priv_only && type.match(/CERTIFICATE/)) next if (key.match.nil?) end key.export(dir) exported[type] ||= Hash.new exported[type]["#{key.fingerprint}.#{key.ext}"] = key.to_json end end FileUtils.mkdir_p(dir) File.open("#{dir}/loot.json", "w") do |f| f.write(JSON.pretty_generate(exported)) end end |
#find_matches ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/thieve.rb', line 147 def find_matches return if (@loot["CERTIFICATE"].nil?) @loot["CERTIFICATE"].each do |c| next if (c.openssl.nil?) @loot.each do |type, keys| next if (type == "CERTIFICATE") keys.each do |k| next if (k.openssl.nil?) begin if (c.openssl.check_private_key(k.openssl)) c.match = "#{k.fingerprint}.#{k.ext}" k.match = "#{c.fingerprint}.#{c.ext}" end rescue # Do nothing. Private key is needed. end end end end end |
#only_private(priv) ⇒ Object
193 194 195 |
# File 'lib/thieve.rb', line 193 def only_private(priv) @private = priv end |
#steal_from(filename, ignores = Array.new, binaries = false) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/thieve.rb', line 197 def steal_from(filename, ignores = Array.new, binaries = false) cmd = ["\\grep"] cmd.push("-a") if (binaries) ignores.each do |ignore| cmd.push("--exclude-dir \"#{ignore}\"") cmd.push("--exclude \"#{ignore}\"") end cmd.push("-I") if (!binaries) cmd.push("-lrs -- \"-----BEGIN\" #{filename}") %x(#{cmd.join(" ")}).each_line do |f| file = Pathname.new(f.strip). skip = ignores.any? do |ignore| File.fnmatch(ignore, file.to_s) end next if (skip) extract_from(file) end return @loot end |
#to_s ⇒ Object
242 243 244 |
# File 'lib/thieve.rb', line 242 def to_s return summarize_loot end |