Module: AppInfo::Android::Signature

Defined in:
lib/app_info/android/signature.rb,
lib/app_info/android/signatures/v1.rb,
lib/app_info/android/signatures/v2.rb,
lib/app_info/android/signatures/v3.rb,
lib/app_info/android/signatures/v4.rb,
lib/app_info/android/signatures/base.rb,
lib/app_info/android/signatures/info.rb

Overview

Android Signature

Support digest and length:

RSA:1024、2048、4096、8192、16384 EC:NIST P-256、P-384、P-521 DSA:1024、2048、3072

Defined Under Namespace

Modules: Version Classes: Base, Info, NotFoundError, SecurityError, V1, V2, V3, V4, VersionError

Constant Summary collapse

UINT32_MAX_VALUE =
2_147_483_647
UINT32_SIZE =
4
UINT64_SIZE =
8

Class Method Summary collapse

Class Method Details

.exist?(version) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/app_info/android/signature.rb', line 102

def exist?(version)
  @versions.key?(version)
end

.fetch(version) ⇒ Object



98
99
100
# File 'lib/app_info/android/signature.rb', line 98

def fetch(version)
  @versions[version]
end

.register(version, verifier) ⇒ Object



94
95
96
# File 'lib/app_info/android/signature.rb', line 94

def register(version, verifier)
  @versions[version] = verifier
end

.registeredObject



90
91
92
# File 'lib/app_info/android/signature.rb', line 90

def registered
  @versions.keys
end

.verify(parser, min_version: Version::V4) ⇒ Array<Hash>

TODO:

version 4 no implantation yet

Verify Android Signature

Examples:

Get unverified v1 certificates, verified v2 certificates,

and not found v3 certificate

 signature.versions(parser)
 # => [
 #   {
 #     version: 1,
 #     verified: false,
 #     certificates: [<AppInfo::Certificate>, ...],
 #     verifier: AppInfo::Androig::Signature
 #   },
 #   {
 #     version: 2,
 #     verified: false,
 #     certificates: [<AppInfo::Certificate>, ...],
 #     verifier: AppInfo::Androig::Signature
 #   },
 #   {
 #     version: 3
 #   }
 # ]

Parameters:

Returns:

  • (Array<Hash>)

    versions



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/app_info/android/signature.rb', line 58

def verify(parser, min_version: Version::V4)
  min_version = min_version.to_i if min_version.is_a?(String)
  if min_version && min_version > Version::V4
    raise VersionError,
          "No signature found in #{min_version} scheme or newer for android file"
  end

  if min_version.zero?
    raise VersionError,
          "Unkonwn version: #{min_version}, avaiables in 1/2/3 and 4 (no implantation yet)"
  end

  # try full version signatures if min_version is nil
  versions = min_version.downto(Version::V1).each_with_object([]) do |version, signatures|
    next unless kclass = fetch(version)

    data = { version: version }
    begin
      verifier = kclass.verify(parser)
      data[:verified] = verifier.verified
      data[:certificates] = verifier.certificates
      data[:verifier] = verifier
    rescue SecurityError, NotFoundError
      # not this version, try the low version
    ensure
      signatures << data
    end
  end

  versions.sort_by { |entry| entry[:version] }
end