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 <../sec/Security/SecBase.h>
8 * Copyright (c) 2004,2011,2013-2014 Apple Inc. All Rights Reserved.
10 * @APPLE_LICENSE_HEADER_START@
12 * This file contains Original Code and/or Modifications of Original Code
13 * as defined in and that are subject to the Apple Public Source License
14 * Version 2.0 (the 'License'). You may not use this file except in
15 * compliance with the License. Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this
19 * The Original Code and all software distributed under the License are
20 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
21 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
22 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
24 * Please see the License for the specific language governing rights and
25 * limitations under the License.
27 * @APPLE_LICENSE_HEADER_END@
35 catch (const MacOSError &err) { return err.osStatus(); } \
36 catch (const std::bad_alloc &) { return errSecAllocate; } \
37 catch (...) { return errSecInternalComponent; } \
40 #define API_END_GENERIC_CATCH } catch (...) { return; }
42 #define API_END_ERROR_CATCH(bad) } catch (...) { return bad; }
46 OSStatus
SecManifestGetVersion (UInt32
*version
)
48 secdebug ("manifest", "SecManifestGetVersion");
49 *version
= 0x01000000;
55 OSStatus
SecManifestCreate(SecManifestRef
*manifest
)
59 Manifest
* manifestPtr
= new Manifest ();
60 *manifest
= (SecManifestRef
) manifestPtr
;
62 secdebug ("manifest", "SecManifestCreate(%p)", manifest
);
69 void SecManifestRelease (SecManifestRef manifest
)
71 delete (Manifest
*) manifest
;
76 static const char* GetDescription (CFTypeRef object
)
78 return CFStringGetCStringPtr (CFCopyDescription (object
), kCFStringEncodingMacRoman
);
83 OSStatus
SecManifestVerifySignature (CFDataRef data
,
84 SecManifestTrustSetupCallback setupCallback
,
86 SecManifestTrustEvaluateCallback evaluateCallback
,
87 void* evaluateContext
,
88 SecManifestRef
*manifest
)
90 return SecManifestVerifySignatureWithPolicy (data
, setupCallback
, setupContext
, evaluateCallback
,
91 evaluateContext
, NULL
, manifest
);
96 OSStatus
SecManifestVerifySignatureWithPolicy (CFDataRef data
,
97 SecManifestTrustSetupCallback setupCallback
,
99 SecManifestTrustEvaluateCallback evaluateCallback
,
100 void* evaluateContext
,
101 SecPolicyRef policyRef
,
102 SecManifestRef
*manifest
)
106 secdebug ("manifest", "SecManifestVerifySignature (%s, %p, %p, %p, %p)", GetDescription (data
), setupCallback
, setupContext
, evaluateCallback
, evaluateContext
);
108 Required (setupCallback
);
109 Required (evaluateCallback
);
111 Manifest
* mp
= new Manifest ();
113 // make a temporary manifest for this operation
115 tm
.MakeSigner (kAppleSigner
);
120 tm
.GetSigner ()->Verify (data
, setupCallback
, setupContext
, evaluateCallback
, evaluateContext
,
121 policyRef
, manifest
== NULL
? NULL
: &mp
->GetManifestInternal ());
122 if (manifest
== NULL
)
128 *manifest
= (SecManifestRef
) mp
;
142 OSStatus
SecManifestCreateSignature(SecManifestRef manifest
, UInt32 options
, CFDataRef
*data
)
146 secdebug ("manifest", "SecManifestCreateSignature(%p, %ul, %p)", manifest
, (unsigned int) options
, data
);
147 Manifest
* manifestPtr
= (Manifest
*) manifest
;
151 return errSecUnimplemented
;
154 // check to see if there is a serializer present
155 const ManifestSigner
* signer
= manifestPtr
->GetSigner ();
157 if (signer
== NULL
) // no serializer?
159 manifestPtr
->MakeSigner (kAppleSigner
);
162 *data
= manifestPtr
->GetSigner ()->Export (manifestPtr
->GetManifestInternal ());
169 OSStatus
SecManifestAddObject(SecManifestRef manifest
, CFTypeRef object
, CFArrayRef exceptionList
)
173 secdebug ("manifest", "SecManifestAddObject(%p), %s, %s",
174 manifest
, GetDescription (object
),
175 exceptionList
? GetDescription (exceptionList
) : "NULL");
177 Manifest
* manifestPtr
= (Manifest
*) manifest
;
178 manifestPtr
->GetManifestInternal ().GetItemList ().AddObject (object
, exceptionList
);
185 OSStatus
SecManifestCompare(SecManifestRef manifest1
, SecManifestRef manifest2
, SecManifestCompareOptions options
)
189 secdebug ("manifest", "SecManifestVerify(%p, %p, %d)", manifest1
, manifest2
, (int) options
);
191 ManifestInternal
&m1
= ((Manifest
*) (manifest1
))->GetManifestInternal ();
192 ManifestInternal
&m2
= ((Manifest
*) (manifest2
))->GetManifestInternal ();
194 ManifestInternal::CompareManifests (m1
, m2
, options
);
201 OSStatus
SecManifestAddSigner(SecManifestRef manifest
, SecIdentityRef identity
)
205 secdebug ("manifest", "SecManifestAddSigner(%p, %p)", manifest
, identity
);
206 Manifest
* manifestPtr
= (Manifest
*) (manifest
);
208 // check to see if there is a serializer present
209 const ManifestSigner
* signer
= manifestPtr
->GetSigner ();
211 if (signer
== NULL
) // no serializer?
213 manifestPtr
->MakeSigner (kAppleSigner
);
216 manifestPtr
->GetSigner ()->AddSigner (identity
);