Sha256: 3ff8f376b8491e96b220361f593be9ca5a1ced0ddcde8137e6d704d51bda695e

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module AppInfo::Android::Signature
  # Android v1 Signature
  class V1 < Base
    DESCRIPTION = 'JAR signing'

    PKCS7_HEADER = [0x30, 0x82].freeze

    attr_reader :certificates, :signatures

    def version
      Version::V1
    end

    def description
      DESCRIPTION
    end

    def verify
      @signatures = fetch_signatures
      @certificates = fetch_certificates

      raise NotFoundError, 'Not found certificates' if @certificates.empty?
    end

    private

    def fetch_signatures
      case @parser
      when AppInfo::APK
        signatures_from(@parser.apk)
      when AppInfo::AAB
        signatures_from(@parser)
      end
    end

    def fetch_certificates
      @signatures.each_with_object([]) do |(_, sign), obj|
        next if sign.certificates.empty?

        obj << AppInfo::Certificate.new(sign.certificates[0])
      end
    end

    def signatures_from(parser)
      signs = {}
      parser.each_file do |path, data|
        # find META-INF/xxx.{RSA|DSA|EC}
        next unless path =~ %r{^META-INF/} && data.unpack('CC') == PKCS7_HEADER

        signs[path] = OpenSSL::PKCS7.new(data)
      end
      signs
    end
  end

  register(Version::V1, V1)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
app-info-3.0.0.beta1 lib/app_info/android/signatures/v1.rb