thieve 0.1.13 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2bcbee04bbe31d26b9bddb01c33fff3ebc94aaf
4
- data.tar.gz: 654c3f571c69e4988ae7a0af9bb42e42198564e6
3
+ metadata.gz: 6669f9697e445d879fa6dfd8eabfaeb8ed3cc0f2
4
+ data.tar.gz: d9b817848851ea9b2ecce7402429b0b0076173ab
5
5
  SHA512:
6
- metadata.gz: 317640992a981662dff126a9561b3c653b860a3328cacd5bfd735d8c0c29da19c9fbb505e60ebe6a8b99a00a4cb591cc2f091035821d56efefe4ebda39c27310
7
- data.tar.gz: 3b07161b5cb1fecdf0a4b57c531aee1a863471043c6ead0585efbdeab7ad7e31a69dbdb585812a469a934daff180a7841e32b75e7607e8d798e5a6b164f356fd
6
+ metadata.gz: 8390e68bf3c9e2fad1ae9d36fe69a9c488477360a8d1135701e19c79b77b17ace32f821bc5efe0e79d20660c9cb6907b34c7254bf16d3c14feab2014646b04d2
7
+ data.tar.gz: 33b2ebc3b697b6739be459e78c794093fb8444511148b3be329763fd5f6dee58bad85d9ce87cf49f7329e0ba955e58353600c5e5f7c4419e87dd53a9f22c018a
data/bin/thieve CHANGED
@@ -18,6 +18,7 @@ end
18
18
  def parse(args)
19
19
  options = Hash.new
20
20
  options["export"] = nil
21
+ options["ignore"] = Array.new
21
22
  options["verbose"] = false
22
23
 
23
24
  info = "Searches through provided directories, looking for " \
@@ -50,6 +51,14 @@ def parse(args)
50
51
  exit ThieveExit::GOOD
51
52
  end
52
53
 
54
+ opts.on(
55
+ "-i",
56
+ "--ignore=PATTERN",
57
+ "Ignore dirs/files matching PATTERN"
58
+ ) do |pattern|
59
+ options["ignore"].push(pattern)
60
+ end
61
+
53
62
  opts.on("--nocolor", "Disable colorized output") do
54
63
  Hilighter.disable
55
64
  end
@@ -98,7 +107,7 @@ options = parse(ARGV)
98
107
  begin
99
108
  thieve = Thieve.new(!Hilighter.disable?)
100
109
  options["dirs"].each do |dir|
101
- thieve.steal_from(dir)
110
+ thieve.steal_from(dir, options["ignore"])
102
111
  end
103
112
  thieve.find_matches
104
113
 
@@ -48,15 +48,12 @@ class Thieve::KeyInfo
48
48
  def hilight_match(match = @match)
49
49
  return "" if (match.nil?)
50
50
  return "Matches #{match}" if (!Thieve.hilight?)
51
- return [
52
- "Matches".light_blue,
53
- match.light_green
54
- ].join(" ")
51
+ return ["Matches".light_blue, match.light_green].join(" ")
55
52
  end
56
53
  private :hilight_match
57
54
 
58
55
  def initialize(file, type, key)
59
- @ext = type.gsub(/ +/, ".").downcase
56
+ @ext = type.gsub(/ +/, "_").downcase
60
57
  @file = file
61
58
  @key = key
62
59
  @match = nil
@@ -116,7 +113,6 @@ class Thieve::KeyInfo
116
113
  @openssl = nil
117
114
  when "PGP SIGNATURE"
118
115
  # Not really sure what to do with this
119
- @ext = "asc"
120
116
  @fingerprint = Digest::SHA256.hexdigest(@file.to_s + @key)
121
117
  @openssl = nil
122
118
  when "PRIVATE KEY"
@@ -140,7 +136,6 @@ class Thieve::KeyInfo
140
136
  @openssl.to_der
141
137
  ).to_s
142
138
  else
143
- @ext = "unknown"
144
139
  @fingerprint = Digest::SHA256.hexdigest(@file.to_s + @key)
145
140
  @openssl = nil
146
141
  end
data/lib/thieve.rb CHANGED
@@ -30,38 +30,59 @@ class Thieve
30
30
  key = ""
31
31
 
32
32
  File.open(file).each do |line|
33
- if (line.include?("BEGIN"))
34
- start = true
35
- end
33
+ start = true if (line.include?("BEGIN"))
36
34
 
37
- if (start)
38
- key += line.unpack("C*").pack("U*").lstrip.rstrip
39
- if (key.end_with?("\\n\\"))
40
- key = key[0..-4]
41
- end
42
- key += "\\n"
43
- end
35
+ # Don't include newlines for now
36
+ key += line.unpack("C*").pack("U*").strip if (start)
44
37
 
45
38
  if (line.include?("END"))
46
- key.scan(/(-----BEGIN(.*)[^-]+-----END\2)/) do |m, t|
47
- keydata = m.gsub(/\\+n/, "\n").chomp
48
- type = t.gsub(/-----.*/, "").strip
39
+ # Remove " + " or ' + '
40
+ key.gsub!(%r{["'] *\+ *["']}, "")
41
+
42
+ # Remove bad characters
43
+ key.gsub!(%r{[^-A-Za-z0-9+/= ]+}, "")
44
+
45
+ # Find base64 key (accept spaces as we'll remove those
46
+ # later)
47
+ key_regex = [
48
+ "(",
49
+ "-----BEGIN ([A-Za-z0-9 ]+)-----",
50
+ "([A-Za-z0-9+/= ]+)",
51
+ "-----END \\2-----",
52
+ ")"
53
+ ].join
54
+
55
+ # Scan for valid key
56
+ key.scan(%r{#{key_regex}}) do |m, type, k|
57
+ # Remove spaces from key
58
+ k.gsub!(/ +/, "")
59
+
60
+ # Format the keydata
61
+ keydata = k.scan(/.{,64}/).keep_if do |l|
62
+ !l.empty?
63
+ end
64
+ keydata.insert(0, "-----BEGIN #{type}-----")
65
+ keydata.push("-----END #{type}-----")
49
66
 
50
67
  @loot[type] ||= Array.new
51
68
  begin
52
69
  @loot[type].push(
53
- Thieve::KeyInfo.new(file, type, keydata)
70
+ Thieve::KeyInfo.new(
71
+ file,
72
+ type,
73
+ keydata.join("\n")
74
+ )
54
75
  )
55
76
  rescue Exception => e
56
77
  if (@@hilight)
57
78
  $stderr.puts file.to_s.light_blue
58
- keydata.each_line do |line|
59
- $stderr.puts line.strip.light_yellow
79
+ keydata.each do |l|
80
+ $stderr.puts l.light_yellow
60
81
  end
61
82
  $stderr.puts e.message.white.on_red
62
83
  else
63
84
  $stderr.puts file
64
- $stderr.puts keydata
85
+ $stderr.puts keydata.join("\n")
65
86
  $stderr.puts e.message
66
87
  end
67
88
  $stderr.puts
@@ -116,15 +137,25 @@ class Thieve
116
137
  @loot = Hash.new
117
138
  end
118
139
 
119
- def steal_from(filename)
140
+ def steal_from(filename, ignores = Array.new)
120
141
  file = Pathname.new(filename).expand_path
121
142
 
143
+ skip = ignores.any? do |ignore|
144
+ file.to_s.match(%r{#{ignore}})
145
+ end
146
+ return @loot if (skip)
147
+
122
148
  if (file.directory?)
123
149
  files = Dir[File.join(file, "**", "*")].reject do |f|
124
150
  Pathname.new(f).directory? || Pathname.new(f).symlink?
125
151
  end
126
152
 
127
153
  files.each do |f|
154
+ skip = ignores.any? do |ignore|
155
+ f.to_s.match(%r{#{ignore}})
156
+ end
157
+ next if (skip)
158
+
128
159
  extract_from(Pathname.new(f).expand_path)
129
160
  end
130
161
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thieve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Whittaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '11.2'
19
+ version: '12.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 11.2.2
22
+ version: 12.0.0
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '11.2'
29
+ version: '12.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 11.2.2
32
+ version: 12.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: hilighter
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.4.5.1
106
+ rubygems_version: 2.6.8
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Steal keys/certs