1/* 2 * Copyright (c) 2006-2007,2011 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 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 11 * file. 12 * 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. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24// 25// SecCodeHost - Host Code API 26// 27#include "cs.h" 28#include "SecCodeHost.h" 29#include <security_utilities/cfutilities.h> 30#include <security_utilities/globalizer.h> 31#include <securityd_client/ssclient.h> 32 33using namespace CodeSigning; 34 35 36// 37// Munge a CFDictionary into a CssmData representing its plist 38// 39class DictData : public CFRef<CFDataRef> { 40public: 41 DictData(CFDictionaryRef dict) : CFRef<CFDataRef>(makeCFData(dict)) { } 42 43 operator CssmData() const 44 { 45 if (*this) 46 return CssmData::wrap(CFDataGetBytePtr(*this), CFDataGetLength(*this)); 47 else 48 return CssmData(); 49 } 50}; 51 52 53OSStatus SecHostCreateGuest(SecGuestRef host, 54 uint32_t status, CFURLRef path, CFDictionaryRef attributes, 55 SecCSFlags flags, SecGuestRef *newGuest) 56{ 57 BEGIN_CSAPI 58 59 checkFlags(flags, kSecCSDedicatedHost | kSecCSGenerateGuestHash); 60 CodeSigning::Required(newGuest) = SecurityServer::ClientSession().createGuest(host, 61 status, cfString(path).c_str(), CssmData(), DictData(attributes), flags); 62 63 END_CSAPI 64} 65 66OSStatus SecHostRemoveGuest(SecGuestRef host, SecGuestRef guest, SecCSFlags flags) 67{ 68 BEGIN_CSAPI 69 70 checkFlags(flags); 71 SecurityServer::ClientSession().removeGuest(host, guest); 72 73 END_CSAPI 74} 75 76OSStatus SecHostSelectGuest(SecGuestRef guestRef, SecCSFlags flags) 77{ 78 BEGIN_CSAPI 79 80 checkFlags(flags); 81 SecurityServer::ClientSession().selectGuest(guestRef); 82 83 END_CSAPI 84} 85 86 87OSStatus SecHostSelectedGuest(SecCSFlags flags, SecGuestRef *guestRef) 88{ 89 BEGIN_CSAPI 90 91 checkFlags(flags); 92 CodeSigning::Required(guestRef) = SecurityServer::ClientSession().selectedGuest(); 93 94 END_CSAPI 95} 96 97OSStatus SecHostSetGuestStatus(SecGuestRef guestRef, 98 uint32_t status, CFDictionaryRef attributes, 99 SecCSFlags flags) 100{ 101 BEGIN_CSAPI 102 103 checkFlags(flags); 104 SecurityServer::ClientSession().setGuestStatus(guestRef, status, DictData(attributes)); 105 106 END_CSAPI 107} 108 109OSStatus SecHostSetHostingPort(mach_port_t hostingPort, SecCSFlags flags) 110{ 111 BEGIN_CSAPI 112 113 checkFlags(flags); 114 SecurityServer::ClientSession().registerHosting(hostingPort, flags); 115 116 END_CSAPI 117} 118