tpclient.cpp
1 /* 2 * Copyright (c) 2000-2002,2011,2014 Apple Inc. All Rights Reserved. 3 * 4 * The contents of this file constitute Original Code as defined in and are 5 * subject to the Apple Public Source License Version 1.2 (the 'License'). 6 * You may not use this file except in compliance with the License. Please obtain 7 * a copy of the License at http://www.apple.com/publicsource and read it before 8 * using this file. 9 * 10 * This Original Code and all software distributed under the License are 11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS 12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT 13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the 15 * specific language governing rights and limitations under the License. 16 */ 17 18 19 // 20 // tpclient - client interface to CSSM TPs and their operations 21 // 22 #include <security_cdsa_client/tpclient.h> 23 24 namespace Security { 25 namespace CssmClient { 26 27 28 // 29 // Manage TP attachments 30 // 31 TPImpl::TPImpl(const Guid &guid) 32 : AttachmentImpl(guid, CSSM_SERVICE_TP), mUseCL(NULL), mUseCSP(NULL), 33 mOwnCL(false), mOwnCSP(false) 34 { 35 } 36 37 TPImpl::TPImpl(const Module &module) 38 : AttachmentImpl(module, CSSM_SERVICE_TP), mUseCL(NULL), mUseCSP(NULL), 39 mOwnCL(false), mOwnCSP(false) 40 { 41 } 42 43 TPImpl::~TPImpl() 44 { 45 if (mOwnCL) 46 delete mUseCL; 47 if (mOwnCSP) 48 delete mUseCSP; 49 } 50 51 52 // 53 // Verify a CertGroup 54 // 55 void TPImpl::certGroupVerify(const CertGroup &certGroup, 56 const TPVerifyContext &context, 57 TPVerifyResult *result) 58 { 59 setupCL(); 60 setupCSP(); 61 check(CSSM_TP_CertGroupVerify(handle(), (*mUseCL)->handle(), (*mUseCSP)->handle(), 62 &certGroup, &context, result)); 63 } 64 65 66 // 67 // Initialize auxiliary modules for operation 68 // 69 void TPImpl::setupCL() 70 { 71 if (mUseCL == NULL) { 72 secinfo("tpclient", "TP is auto-attaching supporting CL"); 73 mUseCL = new CL(gGuidAppleX509CL); 74 mOwnCL = true; 75 } 76 } 77 78 void TPImpl::setupCSP() 79 { 80 if (mUseCSP == NULL) { 81 secinfo("tpclient", "TP is auto-attaching supporting CSP"); 82 mUseCSP = new CSP(gGuidAppleCSP); 83 mOwnCSP = true; 84 } 85 } 86 87 void TPImpl::use(CL &cl) 88 { 89 if (mOwnCL) 90 delete mUseCL; 91 mUseCL = &cl; 92 mOwnCL = false; 93 } 94 95 void TPImpl::use(CSP &csp) 96 { 97 if (mOwnCSP) 98 delete mUseCSP; 99 mUseCSP = &csp; 100 mOwnCSP = false; 101 } 102 103 CL &TPImpl::usedCL() 104 { 105 setupCL(); 106 return *mUseCL; 107 } 108 109 CSP &TPImpl::usedCSP() 110 { 111 setupCSP(); 112 return *mUseCSP; 113 } 114 115 116 // 117 // A TPBuildVerifyContext 118 // 119 TPBuildVerifyContext::TPBuildVerifyContext(CSSM_TP_ACTION action, Allocator &alloc) 120 : allocator(alloc) 121 { 122 // clear out the PODs 123 clearPod(); 124 mCallerAuth.clearPod(); 125 mDlDbList.clearPod(); 126 127 // set initial elements 128 Action = action; 129 callerAuthPtr(&mCallerAuth); 130 mCallerAuth.dlDbList() = &mDlDbList; 131 } 132 133 134 } // end namespace CssmClient 135 } // end namespace Security 136