2  * Copyright (c) 2000-2004,2006,2011,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@ 
  26 // ssclient - SecurityServer client interface library 
  32 namespace SecurityServer 
{ 
  34 uint32 
CommonBlob::getCurrentVersion() { 
  35   uint32 ret 
= version_MacOS_10_0
; 
  36   // If the integrity protections are turned on, use version_partition. 
  37   // else, use version_MacOS_10_0. 
  38   CFTypeRef integrity 
= (CFNumberRef
)CFPreferencesCopyValue(CFSTR("KeychainIntegrity"), CFSTR("com.apple.security"), kCFPreferencesAnyUser
, kCFPreferencesCurrentHost
); 
  39   if (integrity 
&& CFGetTypeID(integrity
) == CFBooleanGetTypeID()) { 
  40     bool integrityProtections 
= CFBooleanGetValue((CFBooleanRef
)integrity
); 
  42     if(integrityProtections
) { 
  43       secdebugfunc("integrity", "creating a partition keychain; global is on"); 
  44       ret 
= version_partition
; 
  46       secdebugfunc("integrity", "creating a old-style keychain; global is off"); 
  47       ret 
= version_MacOS_10_0
; 
  56 void CommonBlob::initialize() 
  60     this->blobVersion 
= getCurrentVersion(); 
  64 // Initialize the blob header for a given version 
  66 void CommonBlob::initialize(uint32 version
) 
  70     secdebugfunc("integrity", "creating a partition keychain with version %d", version
); 
  71     this->blobVersion 
= version
; 
  76 // Verify the blob header for basic sane-ness. 
  78 bool CommonBlob::isValid() const 
  80         return magic 
== magicNumber
; 
  83 void CommonBlob::validate(CSSM_RETURN failureCode
) const 
  86         CssmError::throwMe(failureCode
); 
  90  * This string is placed in KeyBlob.blobSignature to indicate a cleartext 
  93 static const char clearPubKeySig
[] = "Cleartext public key"; 
  95 bool KeyBlob::isClearText() 
  97         return (memcmp(blobSignature
, clearPubKeySig
,  
  98                 sizeof(blobSignature
)) == 0); 
 101 void KeyBlob::setClearTextSignature() 
 103         memmove(blobSignature
, clearPubKeySig
, sizeof(blobSignature
)); 
 108 } // end namespace SecurityServer 
 110 } // end namespace Security