Module: AppleDEPClient::Callback

Defined in:
lib/apple_dep_client/callback.rb

Class Method Summary collapse

Class Method Details

.decode_callback(callback_data) ⇒ Object

Given an XML plist that is CMS-signed and DER encoded, return a ruby Hash of the data



9
10
11
12
# File 'lib/apple_dep_client/callback.rb', line 9

def self.decode_callback(callback_data)
  data = decrypt_data callback_data
  parse_data data
end

.decrypt_data(callback_data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/apple_dep_client/callback.rb', line 14

def self.decrypt_data(callback_data)
  data = AppleDEPClient::Token.create_temp_file("data", callback_data, binary: true)
  command = "openssl asn1parse -inform DER -in #{data.path}"
  decrypted_data, errors = AppleDEPClient::Token.run_command command
  AppleDEPClient::Token.remove_temp_file data
  if decrypted_data == "" || errors != ""
    raise AppleDEPClient::Error::CallbackError, "Incorrect data #{errors}"
  end
  remove_encryption_data(decrypted_data)
end

.parse_data(data) ⇒ Object



43
44
45
# File 'lib/apple_dep_client/callback.rb', line 43

def self.parse_data(data)
  Plist::parse_xml(data)
end

.remove_encryption_data(callback_data) ⇒ Object

This is a bit hacky, because there doesn’t seem to be a good way to decrypt and clean the data



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/apple_dep_client/callback.rb', line 27

def self.remove_encryption_data(callback_data)
  callback_data = callback_data.split
  read = false
  callback_data.select! do |line|
    if line.include? "<!DOCTYPE"
      read = true
    end
    read_line = read
    if line.include? "</plist>"
      read = false
    end
    read_line
  end
  callback_data.join("\n")
end