Skip to content

Commit

Permalink
Merge pull request #871 from fr0l/keystore_with_key_password
Browse files Browse the repository at this point in the history
 Allow to use keys encrypted with password in JavaKeystore
  • Loading branch information
jmoody committed Jul 17, 2018
2 parents ef6f950 + d7594a8 commit 8189ae4
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions ruby-gem/lib/calabash-android/java_keystore.rb
Expand Up @@ -2,7 +2,7 @@ class JavaKeystore
attr_reader :errors, :location, :keystore_alias, :password, :fingerprint
attr_reader :signature_algorithm_name

def initialize(location, keystore_alias, password)
def initialize(location, keystore_alias, password, key_password = nil)
raise "No such keystore file '#{location}'" unless File.exists?(File.expand_path(location))
log "Reading keystore data from keystore file '#{File.expand_path(location)}'"

Expand Down Expand Up @@ -36,6 +36,7 @@ def initialize(location, keystore_alias, password)
@location = location
@keystore_alias = keystore_alias
@password = password
@key_password = key_password
log "Key store data:"
log keystore_data
@fingerprint = extract_sha1_fingerprint(keystore_data)
Expand All @@ -56,7 +57,26 @@ def sign_apk(apk_path, dest_path)
log "Signing using the signature algorithm: '#{signing_algorithm}'"
log "Signing using the digest algorithm: '#{digest_algorithm}'"

unless system_with_stdout_on_success(Calabash::Android::Dependencies.jarsigner_path, '-sigfile', 'CERT', '-sigalg', signing_algorithm, '-digestalg', digest_algorithm, '-signedjar', dest_path, '-storepass', password, '-keystore', location, apk_path, keystore_alias)
cmd_args = {
'-sigfile' => 'CERT',
'-sigalg' => signing_algorithm,
'-digestalg' => digest_algorithm,
'-signedjar' => dest_path,
'-storepass' => password,
'-keystore' => location,
}

unless @key_password.nil?
cmd_args['-keypass'] = @key_password
end

cmd_args = cmd_args.flatten
cmd_args << apk_path
cmd_args << keystore_alias

result = system_with_stdout_on_success(Calabash::Android::Dependencies.jarsigner_path, *cmd_args)

unless result
raise "Could not sign app: #{apk_path}"
end
end
Expand Down Expand Up @@ -92,7 +112,7 @@ def self.read_keystore_with_default_password_and_alias(path)
end

def self.get_keystores
if keystore = keystore_from_settings
if keystore = keystore_from_settings
[ keystore ]
else
[
Expand All @@ -113,7 +133,7 @@ def self.keystore_from_settings
fail_if_key_missing(keystore, "keystore_alias")
keystore["keystore_location"] = File.expand_path(keystore["keystore_location"])
log("Keystore location specified in #{File.exist?(".calabash_settings") ? ".calabash_settings" : "calabash_settings"}.")
JavaKeystore.new(keystore["keystore_location"], keystore["keystore_alias"], keystore["keystore_password"])
JavaKeystore.new(keystore["keystore_location"], keystore["keystore_alias"], keystore["keystore_password"], keystore['key_password'])
end

def self.fail_if_key_missing(map, key)
Expand Down

0 comments on commit 8189ae4

Please sign in to comment.