]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/cs.h
   2  * Copyright (c) 2006,2011,2013-2014 Apple Inc. All Rights Reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. Please obtain a copy of the License at 
  10  * http://www.opensource.apple.com/apsl/ and read it before using this 
  13  * The Original Code and all software distributed under the License are 
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  18  * Please see the License for the specific language governing rights and 
  19  * limitations under the License. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  25 // cs.h - code signing core header 
  31 #include "codesigning_dtrace.h" 
  32 #include <Security/CSCommonPriv.h> 
  33 #include <Security/SecCodePriv.h> 
  34 #include <Security/SecStaticCodePriv.h> 
  35 #include <Security/SecRequirementPriv.h> 
  36 #include <Security/SecCodeSigner.h> 
  37 #include <Security/SecBasePriv.h> 
  38 #include <security_utilities/globalizer.h> 
  39 #include <security_utilities/seccfobject.h> 
  40 #include <security_utilities/cfclass.h> 
  41 #include <security_utilities/errors.h> 
  42 #include <security_utilities/sqlite++.h> 
  43 #include <security_utilities/cfutilities.h> 
  44 #include <security_utilities/logging.h> 
  48 namespace CodeSigning 
{ 
  52 // API per-thread globals 
  55         SecCSFlags flags
;                               // flags of pending API call 
  69         ThreadNexus
<PerThread
> perThread
; 
  71         SecCSFlags 
&flags() { return perThread().flags
; } 
  74 extern ModuleNexus
<CFObjects
> gCFObjects
; 
  76 OSStatus 
dbError(const SQLite3::Error 
&err
); 
  78 // Embedded platform does not have this function so skip the conversion 
  80 #define SecKeychainErrFromOSStatus(status) (status) 
  85 // Code Signing API brackets 
  92         catch (const UnixError &err) { \ 
  93                 switch (err.error) { \ 
  94                 case ENOEXEC: return errSecCSBadObjectFormat; \ 
  95                 default: return err.osStatus(); \ 
  97     catch (const MacOSError &err) { return err.osStatus(); } \ 
  98     catch (const SQLite3::Error &err) { return dbError(err); } \ 
  99     catch (const CommonError &err) { return SecKeychainErrFromOSStatus(err.osStatus()); } \ 
 100     catch (const std::bad_alloc &) { return errSecAllocate; } \ 
 101     catch (...) { Syslog::notice("unknown exception in CSAPI"); return errSecCSInternalError; } \ 
 102         return errSecSuccess; 
 104 #define END_CSAPI_ERRORS \ 
 106         catch (const CSError &err) { return err.cfError(errors); } \ 
 107         catch (const UnixError &err) { \ 
 108                 switch (err.error) { \ 
 109                 case ENOEXEC: return CSError::cfError(errors, errSecCSBadObjectFormat); \ 
 110                 default: return CSError::cfError(errors, err.osStatus()); \ 
 112     catch (const MacOSError &err) { return CSError::cfError(errors, err.osStatus()); } \ 
 113     catch (const SQLite3::Error &err) { return CSError::cfError(errors, dbError(err)); } \ 
 114     catch (const CommonError &err) { return CSError::cfError(errors, SecKeychainErrFromOSStatus(err.osStatus())); } \ 
 115     catch (const std::bad_alloc &) { return CSError::cfError(errors, errSecAllocate); } \ 
 116     catch (...) { Syslog::notice("unknown exception in CSAPI"); return CSError::cfError(errors, errSecCSInternalError); } \ 
 117         return errSecSuccess; 
 119 #define END_CSAPI1(bad)    } catch (...) { return bad; } 
 122 #define END_CSAPI_ERRORS1(bad) \ 
 124         catch (const CSError &err) { err.cfError(errors); } \ 
 125         catch (const UnixError &err) { \ 
 126                 switch (err.error) { \ 
 127                 case ENOEXEC: CSError::cfError(errors, errSecCSBadObjectFormat); \ 
 128                 default: CSError::cfError(errors, err.osStatus()); \ 
 130     catch (const MacOSError &err) { CSError::cfError(errors, err.osStatus()); } \ 
 131     catch (const SQLite3::Error &err) { CSError::cfError(errors, dbError(err)); } \ 
 132     catch (const CommonError &err) { CSError::cfError(errors, SecKeychainErrFromOSStatus(err.osStatus())); } \ 
 133     catch (const std::bad_alloc &) { CSError::cfError(errors, errSecAllocate); } \ 
 134     catch (...) { Syslog::notice("unknown exception in CSAPI"); CSError::cfError(errors, errSecCSInternalError); } \ 
 139 // A version of CodeSigning::Required 
 142 static inline T 
&Required(T 
*ptr
) 
 145                 MacOSError::throwMe(errSecCSObjectRequired
); 
 149 static inline void Required(const void *ptr
) 
 152                 MacOSError::throwMe(errSecCSObjectRequired
); 
 157 // Check flags against a validity mask 
 159 static inline void checkFlags(SecCSFlags flags
, SecCSFlags acceptable 
= 0) 
 161         if (flags 
& ~acceptable
) 
 162                 MacOSError::throwMe(errSecCSInvalidFlags
); 
 167 // DTrace USDT function bracket. 
 169 //      DTRACK(PROVIDER_PROBE_PREFIX, arguments-after-this); 
 171 //      PROVIDER_PROBE_PREFIX_START(this, arguments-after-this) 
 173 //      PROVIDER_PROBE_PREFIX_END(this) 
 175 #define DTRACK(_prefix, _obj, _args...) \ 
 176         if (_prefix ## _START_ENABLED()) _prefix ## _START((_obj), ## _args); \ 
 177         struct _DTFrame ## _prefix { void *me; \ 
 178                 _DTFrame ## _prefix(void *m) : me(m) { } \ 
 179                 ~_DTFrame ## _prefix() { _prefix ## _END(me); } \ 
 180         } _dtframe##_prefix((_obj));