File Coverage

blib/lib/Config/Apple/Profile/Payload/Certificate/PEM.pm
Criterion Covered Total %
statement 29 30 96.6
branch 2 4 50.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             # This is the code for Config::Apple::Profile::Payload::Certificate::PEM.
2             # For Copyright, please see the bottom of the file.
3              
4             package Config::Apple::Profile::Payload::Certificate::PEM;
5              
6 2     2   1368 use 5.10.1;
  2         6  
  2         77  
7 2     2   8 use strict;
  2         2  
  2         56  
8 2     2   8 use warnings FATAL => 'all';
  2         2  
  2         57  
9 2     2   8 use base qw(Config::Apple::Profile::Payload::Certificate);
  2         3  
  2         523  
10              
11             our $VERSION = '0.87.1';
12              
13 2     2   19 use Config::Apple::Profile::Targets qw(:all);
  2         3  
  2         310  
14 2     2   12 use Config::Apple::Profile::Payload::Certificate;
  2         3  
  2         55  
15 2     2   8 use Config::Apple::Profile::Payload::Types qw($ProfileNumber $ProfileString);
  2         2  
  2         169  
16 2     2   12 use Readonly;
  2         4  
  2         354  
17              
18              
19             =encoding utf8
20              
21             =head1 NAME
22              
23             Config::Apple::Profile::Payload::Certificate::PEM - Certificate payload with
24             a PEM-format certificate.
25              
26             =head1 SYNOPSIS
27              
28             use Config::Apple::Profile;
29             use Config::Apple::Profile::Payload::Certificate::PEM;
30            
31             my $cert = new Config::Apple::Profile::Payload::Certificate::PEM;
32             $cert->payload->{PayloadIdentifier} = 'local.acme.CAcert';
33             $cert->payload->{PayloadDisplayName} = 'AcmeCorp internal CA';
34             $cert->payload->{PayloadDescription} = 'The certificate authority used for internal web sites.';
35             $cert->payload->{PayloadOrganization} = 'Acme, Inc.';
36             $cert->payload->{PayloadCertificateFileName} = 'acme.crt';
37             $cert->payload->{PayloadContent} = '.................'; # Long string here
38            
39             my $profile = new Config::Apple::Profile;
40             push @{$profile->content}, $cert;
41            
42             print $profile->export;
43            
44             =head1 DESCRIPTION
45              
46             This class implements the PEM type of Certificate payload.
47              
48             This payload contains a single certificate, in a PKCS#1 container,
49             PEM-encoded. If you have a file that has "BEGIN CERTIFICATE"
50             in it, you've probably got this type of certificate.
51              
52             This payload is used to hold B certificate. If you have multiple
53             certificates, use multiple payloads.
54              
55              
56             =head1 INSTANCE METHODS
57              
58             The following instance methods are provided, or overridden, by this class.
59              
60             =head2 validate_key($key, $value)
61              
62             Performs additional validation for a certain payload key in this class:
63              
64             =over 4
65              
66             =item * C
67              
68             This must be a PEM-format certificate that OpenSSL can recognize.
69              
70             All other payload keys will be checked as usual by the parent class.
71              
72             =back
73              
74             See also the documentation in L.
75              
76             =cut
77              
78             sub validate_key {
79 2     2 1 6 my ($self, $key, $value) = @_;
80              
81             # First, let the parent do validation
82 2         31 my $parent_validation = $self->SUPER::validate_key($key, $value);
83 2 50       7 return $parent_validation if !defined($parent_validation);
84            
85             # Next, if we are setting payload content, and we can check it, do so!
86 2 50       7 if ($key eq 'PayloadContent') {
87 2         18 return $self->SUPER::validate_cert($value, 'PEM');
88             }
89            
90             # For all other keys, return what the parent validated
91             else {
92 0           return $parent_validation;
93             }
94             }
95              
96              
97             =head1 PAYLOAD KEYS
98              
99             All of the payload keys defined in
100             L are used by this
101             payload.
102              
103             This payload has the following additional keys:
104              
105             =head2 C
106              
107             This is fixed to the string C.
108              
109             =head2 C
110              
111             This is fixed to the value C<1>.
112              
113             =cut
114              
115             Readonly our %payloadKeys => (
116             # Bring in the certificate keys...
117             %Config::Apple::Profile::Payload::Certificate::payloadKeys,
118            
119             # Since we can't go any deeper, define the type and version!
120             'PayloadType' => {
121             type => $ProfileString,
122             targets => {
123             $TargetIOS => '5.0',
124             $TargetMACOSX => '10.7',
125             },
126             value => 'com.apple.security.pem',
127             },
128             'PayloadVersion' => {
129             type => $ProfileNumber,
130             targets => {
131             $TargetIOS => '5.0',
132             $TargetMACOSX => '10.7',
133             },
134             value => 1,
135             },
136             ); # End of %payloadKeys
137              
138              
139              
140             =head1 ACKNOWLEDGEMENTS
141              
142             Refer to L for acknowledgements.
143              
144             =head1 AUTHOR
145              
146             A. Karl Kornel, C<< >>
147              
148             =head1 COPYRIGHT AND LICENSE
149              
150             Copyright © 2014 A. Karl Kornel.
151              
152             This program is free software; you can redistribute it and/or modify it
153             under the terms of either: the GNU General Public License as published
154             by the Free Software Foundation; or the Artistic License.
155              
156             See L for more information.
157              
158             =cut
159              
160             1;