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.



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

def initialize(options = {})
  options.each { |k,v| self.send("#{k}=", v) }

  @allow_removal  = true if @allow_removal.nil?
  @type           ||= 'Configuration'
  @version        ||= 1
  @payloads       ||= []
end

Instance Attribute Details

#allow_removalObject

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



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

def allow_removal
  @allow_removal
end

#client_certsObject

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



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

def client_certs
  @client_certs
end

#descriptionObject

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



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

def description
  @description
end

#display_nameObject

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



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

def display_name
  @display_name
end

#identifierObject

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



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

def identifier
  @identifier
end

#organizationObject

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



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

def organization
  @organization
end

#payloadsObject

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



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

def payloads
  @payloads
end

#typeObject

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



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

def type
  @type
end

#uuidObject

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



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

def uuid
  @uuid
end

#versionObject

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



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

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

#unsigned(format = :binary) ⇒ Object



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
64
65
66
67
68
69
70
71
# File 'lib/ios_config/profile.rb', line 37

def unsigned(format = :binary)
  raise_if_blank [:version, :uuid, :type, :identifier, :display_name]

  profile = {
    'PayloadDisplayName'        => @display_name,
    'PayloadVersion'            => @version,
    'PayloadUUID'               => @uuid,
    'PayloadIdentifier'         => @identifier,
    'PayloadType'               => @type,
    'PayloadRemovalDisallowed'  => !@allow_removal
  }
  profile['PayloadOrganization']  = @organization if @organization
  profile['PayloadDescription']   = @description  if @description

  if @client_certs.nil?
    profile['PayloadContent'] = @payloads
  else
    encrypted_payload_content = OpenSSL::PKCS7.encrypt( @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

  case format
  when :binary
    profile.to_plist
  when :xml
    Plist::Emit.dump(profile)
  else
    raise ArgumentError, 'unknown format'
  end

end