1 #include "SecManifest.h"
2 #include <security_utilities/security_utilities.h>
4 #include <security_utilities/seccfobject.h>
5 #include <security_cdsa_utilities/cssmbridge.h>
6 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
9 * Copyright (c) 2004 Apple Computer, 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 memFullErr; } \
38 catch (...) { return internalComponentErr; } \
41 #define API_END_GENERIC_CATCH } catch (...) { return; }
43 #define API_END_ERROR_CATCH(bad) } catch (...) { return bad; }
47 OSStatus
SecManifestGetVersion (UInt32
*version
)
49 secdebug ("manifest", "SecManifestGetVersion");
50 *version
= 0x01000000;
56 OSStatus
SecManifestCreate(SecManifestRef
*manifest
)
60 Manifest
* manifestPtr
= new Manifest ();
61 *manifest
= (SecManifestRef
) manifestPtr
;
63 secdebug ("manifest", "SecManifestCreate(%p)", manifest
);
70 void SecManifestRelease (SecManifestRef manifest
)
72 delete (Manifest
*) manifest
;
77 static const char* GetDescription (CFTypeRef object
)
79 return CFStringGetCStringPtr (CFCopyDescription (object
), kCFStringEncodingMacRoman
);
84 OSStatus
SecManifestVerifySignature (CFDataRef data
,
85 SecManifestTrustSetupCallback setupCallback
,
87 SecManifestTrustEvaluateCallback evaluateCallback
,
88 void* evaluateContext
,
89 SecManifestRef
*manifest
)
91 return SecManifestVerifySignatureWithPolicy (data
, setupCallback
, setupContext
, evaluateCallback
,
92 evaluateContext
, NULL
, manifest
);
97 OSStatus
SecManifestVerifySignatureWithPolicy (CFDataRef data
,
98 SecManifestTrustSetupCallback setupCallback
,
100 SecManifestTrustEvaluateCallback evaluateCallback
,
101 void* evaluateContext
,
102 SecPolicyRef policyRef
,
103 SecManifestRef
*manifest
)
107 secdebug ("manifest", "SecManifestVerifySignature (%s, %p, %p, %p, %p)", GetDescription (data
), setupCallback
, setupContext
, evaluateCallback
, evaluateContext
);
109 Required (setupCallback
);
110 Required (evaluateCallback
);
112 Manifest
* mp
= new Manifest ();
114 // make a temporary manifest for this operation
116 tm
.MakeSigner (kAppleSigner
);
121 tm
.GetSigner ()->Verify (data
, setupCallback
, setupContext
, evaluateCallback
, evaluateContext
,
122 policyRef
, manifest
== NULL
? NULL
: &mp
->GetManifestInternal ());
123 if (manifest
== NULL
)
129 *manifest
= (SecManifestRef
) mp
;
143 OSStatus
SecManifestCreateSignature(SecManifestRef manifest
, UInt32 options
, CFDataRef
*data
)
147 secdebug ("manifest", "SecManifestCreateSignature(%p, %ul, %p)", manifest
, (unsigned int) options
, data
);
148 Manifest
* manifestPtr
= (Manifest
*) manifest
;
155 // check to see if there is a serializer present
156 const ManifestSigner
* signer
= manifestPtr
->GetSigner ();
158 if (signer
== NULL
) // no serializer?
160 manifestPtr
->MakeSigner (kAppleSigner
);
163 *data
= manifestPtr
->GetSigner ()->Export (manifestPtr
->GetManifestInternal ());
170 OSStatus
SecManifestAddObject(SecManifestRef manifest
, CFTypeRef object
, CFArrayRef exceptionList
)
174 secdebug ("manifest", "SecManifestAddObject(%p), %s, %s",
175 manifest
, GetDescription (object
),
176 exceptionList
? GetDescription (exceptionList
) : "NULL");
178 Manifest
* manifestPtr
= (Manifest
*) manifest
;
179 manifestPtr
->GetManifestInternal ().GetItemList ().AddObject (object
, exceptionList
);
186 OSStatus
SecManifestCompare(SecManifestRef manifest1
, SecManifestRef manifest2
, SecManifestCompareOptions options
)
190 secdebug ("manifest", "SecManifestVerify(%p, %p, %d)", manifest1
, manifest2
, (int) options
);
192 ManifestInternal
&m1
= ((Manifest
*) (manifest1
))->GetManifestInternal ();
193 ManifestInternal
&m2
= ((Manifest
*) (manifest2
))->GetManifestInternal ();
195 ManifestInternal::CompareManifests (m1
, m2
, options
);
202 OSStatus
SecManifestAddSigner(SecManifestRef manifest
, SecIdentityRef identity
)
206 secdebug ("manifest", "SecManifestAddSigner(%p, %p)", manifest
, identity
);
207 Manifest
* manifestPtr
= (Manifest
*) (manifest
);
209 // check to see if there is a serializer present
210 const ManifestSigner
* signer
= manifestPtr
->GetSigner ();
212 if (signer
== NULL
) // no serializer?
214 manifestPtr
->MakeSigner (kAppleSigner
);
217 manifestPtr
->GetSigner ()->AddSigner (identity
);