Skip to content

Commit

Permalink
Merge pull request #17 from DeployGate/fix/invalid_jar_signed_but_ins…
Browse files Browse the repository at this point in the history
…tallable_apk

Fixed no signature issue for installable apks but invalid jar sign
  • Loading branch information
jmatsu authored Oct 7, 2019
2 parents bbb409b + 25252de commit 93cdf55
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/android_apk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,22 @@ def self.read_signature(apk, filepath)
apk.verified = exit_status.success?

if !exit_status.success? || certs_hunk.nil?
# Use a previous method as a fallback because apksigner cannot get a signature from an non installable apk
# For RSA or DSA encryption
print_certs_command = "unzip -p #{filepath.shellescape} META-INF/*.RSA META-INF/*.DSA | openssl pkcs7 -inform DER -text -print_certs | keytool -printcert | grep SHA1:"
certs_hunk, _, exit_status = Open3.capture3(print_certs_command)
end

if !exit_status.success? || certs_hunk.nil?
# Use a previous method as a fallback just in case
print_certs_command = "unzip -p #{filepath.shellescape} META-INF/*.RSA META-INF/*.DSA | keytool -printcert | grep SHA1:"
certs_hunk, _, exit_status = Open3.capture3(print_certs_command)
end

if exit_status.success? && !certs_hunk.nil?
signatures = certs_hunk.scan(/(?:[0-9a-zA-Z]{2}:?){20}/)
apk.signature = signatures[0].delete(":").downcase if signatures.length == 1
else
apk.signature = nil # make sure being nil
end
end

Expand Down

0 comments on commit 93cdf55

Please sign in to comment.