Class: MooTool::Models::EncryptedPayload

Inherits:
Object
  • Object
show all
Includes:
Helpers::IMG4
Defined in:
lib/mootool/models/encrypted_payload.rb

Constant Summary

Constants included from Helpers::IMG4

Helpers::IMG4::DECODE_TAGS, Helpers::IMG4::FIRMWARE_TAGS, Helpers::IMG4::HASH_LENGTHS, Helpers::IMG4::KEY_INSTANCE_TAGS, Helpers::IMG4::KVP_TAGS, Helpers::IMG4::OCTET_TAGS, Helpers::IMG4::SEQUENCE_TAGS, Helpers::IMG4::SIGNATURE_TAGS

Instance Method Summary collapse

Methods included from Helpers::IMG4

#construct, #construct_object, #decode_construct, parse_4cc

Constructor Details

#initialize(payload) ⇒ EncryptedPayload

Returns a new instance of EncryptedPayload.



8
9
10
11
12
13
14
15
16
17
# File 'lib/mootool/models/encrypted_payload.rb', line 8

def initialize(payload)
  @data = OpenSSL::ASN1.decode(payload)
  @value = construct(@data)

  @value[1][4].hint ||= 'ECCEncryptedData'

  @algorithm = ALGORITHMS[@value[0]]
  @point = parse_point_with_match(@value[1][1])
  @nonce = @value[1][0]
end

Instance Method Details

#parse_point_any(point) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/mootool/models/encrypted_payload.rb', line 29

def parse_point_any(point)
  %w[prime256v1 secp384r1].map do |group|
    group = OpenSSL::PKey::EC::Group.new(group)
    OpenSSL::PKey::EC::Point.new(group, point)
  rescue StandardError
    nil
  end.compact.first
end

#parse_point_with_match(point) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/mootool/models/encrypted_payload.rb', line 19

def parse_point_with_match(point)
  point = parse_point_any(point)
  matches = Models::CertificateIndex.current.matching_key(point)
  if matches.any?
    { key: point, matches: matches }
  else
    point
  end
end

#to_hObject



38
39
40
41
42
43
44
45
46
# File 'lib/mootool/models/encrypted_payload.rb', line 38

def to_h
  {
    hmac_function: @algorithm,
    ecies_iv: Models::Digest.create(@value[1][2].raw, 'IV AES128'),
    data_iv: Models::Digest.create(@value[1][3].raw, 'IV AES128'),
    ecies: Models::ECIESEncryption.new(@point, @nonce),
    encrypted_data: @value[1][4]
  }
end