crxmake 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/crxmake.rb +38 -21
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51b7ae60790d87dde2e173105028ae9a84ef4d35
4
- data.tar.gz: 97dcbe4fd38e5f9c631c81db272ef3097b89eba6
3
+ metadata.gz: 1896b138aaa3d78181c9843cace2c494207ace8d
4
+ data.tar.gz: 2e1ead40b42f5ec57fd669bd723d9e4e9ce74c7d
5
5
  SHA512:
6
- metadata.gz: d9ce02f3dc7a96258cc4b99712d4dea14c7d013e190b2bd1001b4cd6191c74f9c2902c29acd2088dc7079011efea6b8bb9428c6f7452c7a6ac5d909eb4198d3a
7
- data.tar.gz: 40b0e4b2b11c0c3bab0744e25a1c0851c52056179717130c5b8729523e3443e0ec40de81d8c1bbd9e74300d39d015b0a7228aa99fbaf49e2415adc08768bf789
6
+ metadata.gz: a82df144b2d407f48ce845cbc2fd7198093c9ce8d68844795b78e53a2ec071878de74d051b56e628452522bae784f98da0baf15bacdba72f86aba4bc3223047b
7
+ data.tar.gz: d29ab638a88d0ff6512137ffd60abb90ee1dacbf1dcb18cab20c2ebe2e840f56661f2746119dd4d9d7f63e8a16b89180bb664127798039f1241e10a5ffe8b924
@@ -1,15 +1,24 @@
1
1
  #!/usr/bin/ruby
2
2
  # vim: fileencoding=utf-8
3
3
  require 'rubygems'
4
- require 'zip/zip'
4
+ require 'zip'
5
5
  require 'openssl'
6
6
  require 'digest/sha1'
7
7
  require 'fileutils'
8
8
  require 'find'
9
9
  require 'pathname'
10
10
 
11
+ begin
12
+ require 'openssl_pkcs8'
13
+ class OpenSSL::PKey::RSA
14
+ alias_method :to_pem, :to_pem_pkcs8
15
+ end
16
+ rescue LoadError
17
+ $pkcs8_warning=1
18
+ end
19
+
11
20
  class CrxMake < Object
12
- VERSION = '2.1.2'
21
+ VERSION = '2.1.3'
13
22
  # thx masover
14
23
  MAGIC = 'Cr24'
15
24
 
@@ -31,11 +40,11 @@ class CrxMake < Object
31
40
  else
32
41
  generate_key
33
42
  end
34
- create_zip
35
- sign_zip
36
- write_crx
43
+ zip_buffer = create_zip
44
+ sign_zip(zip_buffer)
45
+ write_crx(zip_buffer)
37
46
  ensure
38
- remove_zip
47
+ #remove_zip
39
48
  end
40
49
 
41
50
  def zip
@@ -44,11 +53,12 @@ class CrxMake < Object
44
53
  generate_key
45
54
  @pkey = @pkey_o
46
55
  end
47
- remove_zip
48
- create_zip do |zip|
56
+ #remove_zip
57
+ zip_buffer = create_zip do |zip|
49
58
  puts "include pem key: \"#{@pkey}\"" if @verbose
50
59
  zip.add('key.pem', @pkey)
51
60
  end
61
+ File.open(@zip,'wb'){|f|f<<zip_buffer}
52
62
  end
53
63
 
54
64
  private
@@ -141,17 +151,21 @@ ext dir: \"#{@exdir}\"
141
151
  end
142
152
 
143
153
  def generate_key
154
+ if defined?($pkcs8_warning)&&@verbose
155
+ $stderr.puts 'Warn: generated pem must be converted into PKCS8 in order to upload to Chrome WebStore.'
156
+ $stderr.puts 'To suppress this message, do: gem install openssl_pkcs8'
157
+ end
144
158
  puts "generate pemkey to \"#{@pkey_o}\"" if @verbose
145
159
  @key = OpenSSL::PKey::RSA.generate(KEY_SIZE)
146
160
  # save key
147
161
  File.open(@pkey_o, 'wb') do |file|
148
- file << @key.export()
162
+ file << @key.to_pem
149
163
  end
150
164
  end
151
165
 
152
166
  def create_zip
153
167
  puts "create zip" if @verbose
154
- Zip::ZipFile.open(@zip, Zip::ZipFile::CREATE) do |zip|
168
+ buffer = Zip::File.add_buffer do |zip|
155
169
  Find.find(@exdir) do |path|
156
170
  unless path == @exdir
157
171
  if File.directory?(path)
@@ -178,22 +192,24 @@ ext dir: \"#{@exdir}\"
178
192
  create zip...done
179
193
  zip file at \"#{@zip}\"
180
194
  EOS
195
+ return buffer.string
181
196
  end
182
197
 
183
198
  def get_relative base, target
184
199
  Pathname.new(target.to_s).relative_path_from(Pathname.new(base.to_s)).to_s
185
200
  end
186
201
 
187
- def sign_zip
202
+ def sign_zip(zip_buffer)
188
203
  puts "sign zip" if @verbose
189
204
  plain = nil
190
- File.open(@zip, 'rb') do |file|
191
- plain = file.read
192
- end
205
+ #File.open(@zip, 'rb') do |file|
206
+ # plain = file.read
207
+ #end
208
+ plain = zip_buffer
193
209
  @sig = @key.sign(OpenSSL::Digest::SHA1.new, plain)
194
210
  end
195
211
 
196
- def write_crx
212
+ def write_crx(zip_buffer)
197
213
  print "write crx..." if @verbose
198
214
  key = @key.public_key.to_der
199
215
  key.index(KEY) != 0 and key = KEY + key
@@ -204,9 +220,10 @@ zip file at \"#{@zip}\"
204
220
  file << to_sizet(@sig.size)
205
221
  file << key
206
222
  file << @sig
207
- File.open(@zip, 'rb') do |zip|
208
- file << zip.read
209
- end
223
+ #File.open(@zip, 'rb') do |zip|
224
+ # file << zip.read
225
+ #end
226
+ file << zip_buffer
210
227
  end
211
228
  puts "done at \"#{@crx}\"" if @verbose
212
229
  end
@@ -215,9 +232,9 @@ zip file at \"#{@zip}\"
215
232
  return [num].pack('V')
216
233
  end
217
234
 
218
- def remove_zip
219
- FileUtils.rm_rf(@zip) if @zip && File.exist?(@zip)
220
- end
235
+ #def remove_zip
236
+ # FileUtils.rm_rf(@zip) if @zip && File.exist?(@zip)
237
+ #end
221
238
 
222
239
  class << self
223
240
  def make opt
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crxmake
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Constellation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-14 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip