Skip to content

Commit 4f4421d

Browse files
committed
add installation for extensions without keyfile
1 parent 97f716b commit 4f4421d

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

lib/auto_chrome/chrome_extension.rb

+32-11
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,44 @@
44

55
class AutoChrome::ChromeExtension
66
attr_reader :path, :id, :key, :manifest, :version
7+
78
def initialize(crx_path)
89
@path = crx_path
910

10-
data = File.read(@path, mode: 'rb')
11-
key_file = File.dirname(path) + "/" + File.basename(@path, ".crx") + ".pub"
12-
if !File.exists?(key_file)
13-
raise "No key file found for extension #{path}"
14-
end
15-
@key = File.read(key_file)
16-
@id = Digest::SHA256.hexdigest(key)[0...32].tr('0-9a-f', 'a-p')
17-
1811
# use open3 to suppress unzip warnings for unexpected crx headers
1912
json, _, _ = Open3.capture3('unzip', '-qc', @path, 'manifest.json')
2013

2114
@manifest = JSON.parse(json, symbolize_names: true)
22-
@manifest[:key] = Base64.encode64(@key).gsub(/\s/, '')
2315

24-
@version = @manifest[:version]
16+
key_file = File.dirname(path) + "/" + File.basename(@path, ".crx") + ".pub"
17+
unless File.exists?(key_file)
18+
if @manifest.dig(:key) != nil
19+
puts "[---] Reading key from manifest, this might not work..."
20+
@key = @manifest[:key]
21+
@id = Digest::SHA256.hexdigest(Base64.decode64(@key))[0...32].tr('0-9a-f', 'a-p')
22+
else
23+
raise "No key file or key in manifest found for extension #{path}"
24+
end
25+
else
26+
@key = File.read(key_file)
27+
@id = Digest::SHA256.hexdigest(key)[0...32].tr('0-9a-f', 'a-p')
28+
@manifest[:key] = Base64.encode64(@key).gsub(/\s/, '')
29+
end
30+
31+
if @manifest.dig(:id) != nil
32+
@id = @manifest[:id]
33+
else
34+
if :id == nil || id.to_s.strip.empty?
35+
raise "No id found for extension #{path}!"
36+
end
37+
end
38+
39+
if @manifest.dig(:version) != nil
40+
@version = @manifest[:version]
41+
else
42+
if :version == nil
43+
raise "No version found for extension #{path}!"
44+
end
45+
end
2546
end
26-
end
47+
end

lib/auto_chrome/profile_builder.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ def add_extension(crx, profiles)
126126

127127
# bypass extension confirmation prompts
128128
profiles.each do |p|
129-
p.secure_prefs["extensions.settings.#{crx.id}"] = {ack_external: true}
129+
p.secure_prefs["extensions.settings.#{crx.id}"] = {
130+
disable_reasons: 0,
131+
ack_external: true,
132+
state: 1 # this will soon be deprecated, better to use disable_reasons right away
133+
}
130134
end
131135
#XXX this will break if we call add_extension multiple times with the same
132136
#extension and different profiles

0 commit comments

Comments
 (0)