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 <../../base/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         secinfo ("manifest", "SecManifestGetVersion"); 
  49         *version 
= 0x01000000; 
  55 OSStatus 
SecManifestCreate(SecManifestRef 
*manifest
) 
  59         Manifest
* manifestPtr 
= new Manifest (); 
  60         *manifest 
= (SecManifestRef
) manifestPtr
; 
  62         secinfo ("manifest", "SecManifestCreate(%p)", manifest
); 
  69 void SecManifestRelease (SecManifestRef manifest
) 
  71         delete (Manifest
*) manifest
; 
  74 // On release builds, this function isn't called (due to how secinfo works). Assure the compiler this is okay. 
  75 #pragma clang diagnostic push 
  76 #pragma clang diagnostic ignored "-Wunused-function" 
  77 static const char* GetDescription (CFTypeRef object
) 
  79         return CFStringGetCStringPtr (CFCopyDescription (object
), kCFStringEncodingMacRoman
); 
  81 #pragma clang diagnostic pop 
  85 OSStatus 
SecManifestVerifySignature (CFDataRef data
, 
  86                                                                          SecManifestTrustSetupCallback setupCallback
, 
  88                                                                          SecManifestTrustEvaluateCallback evaluateCallback
, 
  89                                                                          void* evaluateContext
, 
  90                                                                          SecManifestRef 
*manifest
) 
  92         return SecManifestVerifySignatureWithPolicy (data
, setupCallback
, setupContext
, evaluateCallback
, 
  93                                                                                                  evaluateContext
, NULL
, manifest
); 
  98 OSStatus 
SecManifestVerifySignatureWithPolicy (CFDataRef data
, 
  99                                                                                            SecManifestTrustSetupCallback setupCallback
, 
 101                                                                                            SecManifestTrustEvaluateCallback evaluateCallback
, 
 102                                                                                            void* evaluateContext
, 
 103                                                                                            SecPolicyRef policyRef
, 
 104                                                                                            SecManifestRef 
*manifest
) 
 108         secinfo ("manifest", "SecManifestVerifySignature (%s, %p, %p, %p, %p)", GetDescription (data
), setupCallback
, setupContext
, evaluateCallback
, evaluateContext
); 
 110         Required (setupCallback
); 
 111         Required (evaluateCallback
); 
 113         Manifest
* mp 
= new Manifest (); 
 115         // make a temporary manifest for this operation 
 117         tm
.MakeSigner (kAppleSigner
); 
 122                 tm
.GetSigner ()->Verify (data
, setupCallback
, setupContext
, evaluateCallback
, evaluateContext
, 
 123                                                                  policyRef
, manifest 
== NULL 
? NULL 
: &mp
->GetManifestInternal ()); 
 124                 if (manifest 
== NULL
) 
 130                         *manifest 
= (SecManifestRef
) mp
; 
 144 OSStatus 
SecManifestCreateSignature(SecManifestRef manifest
, UInt32 options
, CFDataRef 
*data
) 
 148         secinfo ("manifest", "SecManifestCreateSignature(%p, %ul, %p)", manifest
, (unsigned int) options
, data
); 
 149         Manifest
* manifestPtr 
= (Manifest
*) manifest
; 
 153                 return errSecUnimplemented
; 
 156         // check to see if there is a serializer present 
 157         const ManifestSigner
* signer 
= manifestPtr
->GetSigner (); 
 159         if (signer 
== NULL
) // no serializer? 
 161                 manifestPtr
->MakeSigner (kAppleSigner
); 
 164         *data 
= manifestPtr
->GetSigner ()->Export (manifestPtr
->GetManifestInternal ()); 
 171 OSStatus 
SecManifestAddObject(SecManifestRef manifest
, CFTypeRef object
, CFArrayRef exceptionList
) 
 175         secinfo ("manifest", "SecManifestAddObject(%p), %s, %s", 
 176                                                   manifest
, GetDescription (object
), 
 177                                                   exceptionList 
? GetDescription (exceptionList
) : "NULL"); 
 179         Manifest
* manifestPtr 
= (Manifest
*) manifest
; 
 180         manifestPtr
->GetManifestInternal ().GetItemList ().AddObject (object
, exceptionList
); 
 187 OSStatus 
SecManifestCompare(SecManifestRef manifest1
, SecManifestRef manifest2
, SecManifestCompareOptions options
) 
 191         secinfo ("manifest", "SecManifestVerify(%p, %p, %d)", manifest1
, manifest2
, (int) options
); 
 193         ManifestInternal 
&m1 
= ((Manifest
*) (manifest1
))->GetManifestInternal (); 
 194         ManifestInternal 
&m2 
= ((Manifest
*) (manifest2
))->GetManifestInternal (); 
 196         ManifestInternal::CompareManifests (m1
, m2
, options
); 
 203 OSStatus 
SecManifestAddSigner(SecManifestRef manifest
, SecIdentityRef identity
) 
 207         secinfo ("manifest", "SecManifestAddSigner(%p, %p)", manifest
, identity
); 
 208         Manifest
* manifestPtr 
= (Manifest
*) (manifest
); 
 210         // check to see if there is a serializer present 
 211         const ManifestSigner
* signer 
= manifestPtr
->GetSigner (); 
 213         if (signer 
== NULL
) // no serializer? 
 215                 manifestPtr
->MakeSigner (kAppleSigner
); 
 218         manifestPtr
->GetSigner ()->AddSigner (identity
);