1 #include "SecManifest.h"
2 #include <security_utilities/security_utilities.h>
3 #include <utilities/SecCFRelease.h>
5 #include <security_utilities/seccfobject.h>
6 #include <security_cdsa_utilities/cssmbridge.h>
7 #include <../../base/SecBase.h>
9 * Copyright (c) 2004,2011,2013-2014 Apple Inc. All Rights Reserved.
11 * @APPLE_LICENSE_HEADER_START@
13 * This file contains Original Code and/or Modifications of Original Code
14 * as defined in and that are subject to the Apple Public Source License
15 * Version 2.0 (the 'License'). You may not use this file except in
16 * compliance with the License. Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_HEADER_END@
36 catch (const MacOSError &err) { return err.osStatus(); } \
37 catch (const std::bad_alloc &) { return errSecAllocate; } \
38 catch (...) { return errSecInternalComponent; } \
41 #define API_END_GENERIC_CATCH } catch (...) { return; }
43 #define API_END_ERROR_CATCH(bad) } catch (...) { return bad; }
47 OSStatus
SecManifestGetVersion (UInt32
*version
)
49 secinfo ("manifest", "SecManifestGetVersion");
50 *version
= 0x01000000;
56 OSStatus
SecManifestCreate(SecManifestRef
*manifest
)
60 Manifest
* manifestPtr
= new Manifest ();
61 *manifest
= (SecManifestRef
) manifestPtr
;
63 secinfo ("manifest", "SecManifestCreate(%p)", manifest
);
70 void SecManifestRelease (SecManifestRef manifest
)
72 delete (Manifest
*) manifest
;
75 // On release builds, this function isn't called (due to how secinfo works). Assure the compiler this is okay.
76 #pragma clang diagnostic push
77 #pragma clang diagnostic ignored "-Wunused-function"
78 static const char* GetDescription (CFTypeRef object
)
80 CFStringRef s
= CFCopyDescription (object
);
81 const char * p
= CFStringGetCStringPtr (s
, kCFStringEncodingMacRoman
);
85 #pragma clang diagnostic pop
89 OSStatus
SecManifestVerifySignature (CFDataRef data
,
90 SecManifestTrustSetupCallback setupCallback
,
92 SecManifestTrustEvaluateCallback evaluateCallback
,
93 void* evaluateContext
,
94 SecManifestRef
*manifest
)
96 return SecManifestVerifySignatureWithPolicy (data
, setupCallback
, setupContext
, evaluateCallback
,
97 evaluateContext
, NULL
, manifest
);
102 OSStatus
SecManifestVerifySignatureWithPolicy (CFDataRef data
,
103 SecManifestTrustSetupCallback setupCallback
,
105 SecManifestTrustEvaluateCallback evaluateCallback
,
106 void* evaluateContext
,
107 SecPolicyRef policyRef
,
108 SecManifestRef
*manifest
)
112 secinfo ("manifest", "SecManifestVerifySignature (%s, %p, %p, %p, %p)", GetDescription (data
), setupCallback
, setupContext
, evaluateCallback
, evaluateContext
);
114 Required (setupCallback
);
115 Required (evaluateCallback
);
117 Manifest
* mp
= new Manifest ();
119 // make a temporary manifest for this operation
121 tm
.MakeSigner (kAppleSigner
);
126 tm
.GetSigner ()->Verify (data
, setupCallback
, setupContext
, evaluateCallback
, evaluateContext
,
127 policyRef
, manifest
== NULL
? NULL
: &mp
->GetManifestInternal ());
128 if (manifest
== NULL
)
134 *manifest
= (SecManifestRef
) mp
;
148 OSStatus
SecManifestCreateSignature(SecManifestRef manifest
, UInt32 options
, CFDataRef
*data
)
152 secinfo ("manifest", "SecManifestCreateSignature(%p, %ul, %p)", manifest
, (unsigned int) options
, data
);
153 Manifest
* manifestPtr
= (Manifest
*) manifest
;
157 return errSecUnimplemented
;
160 // check to see if there is a serializer present
161 const ManifestSigner
* signer
= manifestPtr
->GetSigner ();
163 if (signer
== NULL
) // no serializer?
165 manifestPtr
->MakeSigner (kAppleSigner
);
168 *data
= manifestPtr
->GetSigner ()->Export (manifestPtr
->GetManifestInternal ());
175 OSStatus
SecManifestAddObject(SecManifestRef manifest
, CFTypeRef object
, CFArrayRef exceptionList
)
179 secinfo ("manifest", "SecManifestAddObject(%p), %s, %s",
180 manifest
, GetDescription (object
),
181 exceptionList
? GetDescription (exceptionList
) : "NULL");
183 Manifest
* manifestPtr
= (Manifest
*) manifest
;
184 manifestPtr
->GetManifestInternal ().GetItemList ().AddObject (object
, exceptionList
);
191 OSStatus
SecManifestCompare(SecManifestRef manifest1
, SecManifestRef manifest2
, SecManifestCompareOptions options
)
195 secinfo ("manifest", "SecManifestVerify(%p, %p, %d)", manifest1
, manifest2
, (int) options
);
197 ManifestInternal
&m1
= ((Manifest
*) (manifest1
))->GetManifestInternal ();
198 ManifestInternal
&m2
= ((Manifest
*) (manifest2
))->GetManifestInternal ();
200 ManifestInternal::CompareManifests (m1
, m2
, options
);
207 OSStatus
SecManifestAddSigner(SecManifestRef manifest
, SecIdentityRef identity
)
211 secinfo ("manifest", "SecManifestAddSigner(%p, %p)", manifest
, identity
);
212 Manifest
* manifestPtr
= (Manifest
*) (manifest
);
214 // check to see if there is a serializer present
215 const ManifestSigner
* signer
= manifestPtr
->GetSigner ();
217 if (signer
== NULL
) // no serializer?
219 manifestPtr
->MakeSigner (kAppleSigner
);
222 manifestPtr
->GetSigner ()->AddSigner (identity
);