Class: IOSConfig::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/ios_config/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Profile

Returns a new instance of Profile.



18
19
20
21
22
23
24
25
26
# File 'lib/ios_config/profile.rb', line 18

def initialize(options = {})
  options.each { |k,v| self.send("#{k}=", v) }
  puts self.allow_removal
  puts self.allow_removal.nil?
  self.allow_removal  = true if self.allow_removal.nil?
  self.type           ||= 'Configuration'
  self.version        ||= 1
  self.payloads       ||= []
end

Instance Attribute Details

#allow_removalObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def allow_removal
  @allow_removal
end

#client_certsObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def client_certs
  @client_certs
end

#descriptionObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def description
  @description
end

#display_nameObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def display_name
  @display_name
end

#identifierObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def identifier
  @identifier
end

#organizationObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def organization
  @organization
end

#payloadsObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def payloads
  @payloads
end

#typeObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def type
  @type
end

#uuidObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def uuid
  @uuid
end

#versionObject

if profile can be deleted by device user. defaults to true



7
8
9
# File 'lib/ios_config/profile.rb', line 7

def version
  @version
end

Instance Method Details

#signed(mdm_cert, mdm_intermediate_cert, mdm_private_key) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/ios_config/profile.rb', line 28

def signed(mdm_cert, mdm_intermediate_cert, mdm_private_key)
  certificate   = OpenSSL::X509::Certificate.new(File.read(mdm_cert))
  intermediate  = OpenSSL::X509::Certificate.new(File.read(mdm_intermediate_cert))
  private_key   = OpenSSL::PKey::RSA.new(File.read(mdm_private_key))

  signed_profile = OpenSSL::PKCS7.sign(certificate, private_key, unsigned, [intermediate], OpenSSL::PKCS7::BINARY)
  signed_profile.to_der
end

#unsignedObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ios_config/profile.rb', line 37

def unsigned
  raise_if_blank [:version, :uuid, :type, :identifier, :display_name]

  profile = {
    'PayloadDisplayName'        => self.display_name,
    'PayloadVersion'            => self.version,
    'PayloadUUID'               => self.uuid,
    'PayloadIdentifier'         => self.identifier,
    'PayloadType'               => self.type,
    'PayloadRemovalDisallowed'  => !self.allow_removal
  }
  profile['PayloadOrganization']  = self.organization if self.organization
  profile['PayloadDescription']   = self.description  if self.description
      
  if self.client_certs.nil?
    profile['PayloadContent'] = payloads
  else
    encrypted_payload_content = OpenSSL::PKCS7.encrypt( self.client_certs, 
                                                        payloads.to_plist, 
                                                        OpenSSL::Cipher::Cipher::new("des-ede3-cbc"), 
                                                        OpenSSL::PKCS7::BINARY)
  
    profile['EncryptedPayloadContent'] = StringIO.new encrypted_payload_content.to_der
  end

  profile.to_plist
end