Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extension install #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions lib/auto_chrome/chrome_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,44 @@

class AutoChrome::ChromeExtension
attr_reader :path, :id, :key, :manifest, :version

def initialize(crx_path)
@path = crx_path

data = File.read(@path, mode: 'rb')
key_file = File.dirname(path) + "/" + File.basename(@path, ".crx") + ".pub"
if !File.exists?(key_file)
raise "No key file found for extension #{path}"
end
@key = File.read(key_file)
@id = Digest::SHA256.hexdigest(key)[0...32].tr('0-9a-f', 'a-p')

# use open3 to suppress unzip warnings for unexpected crx headers
json, _, _ = Open3.capture3('unzip', '-qc', @path, 'manifest.json')

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

@version = @manifest[:version]
key_file = File.dirname(path) + "/" + File.basename(@path, ".crx") + ".pub"
if !File.exist?(key_file)
if @manifest.dig(:key) != nil
puts "[---] Reading key from manifest, this might not work..."
@key = @manifest[:key]
@id = Digest::SHA256.hexdigest(Base64.decode64(@key))[0...32].tr('0-9a-f', 'a-p')
else
raise "No key file or key in manifest found for extension #{path}"
end
else
@key = File.read(key_file)
@id = Digest::SHA256.hexdigest(key)[0...32].tr('0-9a-f', 'a-p')
@manifest[:key] = Base64.encode64(@key).gsub(/\s/, '')
end

if @manifest.dig(:id) != nil
@id = @manifest[:id]
else
if :id == nil || id.to_s.strip.empty?
raise "No id found for extension #{path}!"
end
end

if @manifest.dig(:version) != nil
@version = @manifest[:version]
else
if :version == nil
raise "No version found for extension #{path}!"
end
end
end
end
6 changes: 5 additions & 1 deletion lib/auto_chrome/profile_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ def add_extension(crx, profiles)

# bypass extension confirmation prompts
profiles.each do |p|
p.secure_prefs["extensions.settings.#{crx.id}"] = {ack_external: true}
p.secure_prefs["extensions.settings.#{crx.id}"] = {
disable_reasons: 0,
ack_external: true,
state: 1 # this will soon be deprecated, better to use disable_reasons right away
}
end
#XXX this will break if we call add_extension multiple times with the same
#extension and different profiles
Expand Down