2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // SecurityAgentClient - client interface to SecurityAgent
22 #ifndef _H_SECURITYAGENTCLIENT
23 #define _H_SECURITYAGENTCLIENT
25 #if defined(__cplusplus)
27 #include <Security/mach++.h>
28 #include <Security/osxsigning.h>
29 #include <Security/cssmacl.h>
30 #include <Security/cssm.h>
34 using MachPlusPlus::Port
;
35 using CodeSigning::OSXCode
;
38 namespace SecurityAgent
{
42 // Note: Following section also available to C code for inclusion
44 static const unsigned int maxPassphraseLength
= 1024;
45 static const unsigned int maxUsernameLength
= 80;
49 // Unified reason codes transmitted to SecurityAgent (and internationalized there)
52 noReason
= 0, // no reason (not used, used as a NULL)
53 unknownReason
, // something else (catch-all internal error)
55 // reasons for asking for a new passphrase
56 newDatabase
= 11, // need passphrase for a new database
57 changePassphrase
, // changing passphrase for existing database
59 // reasons for retrying an unlock query
60 invalidPassphrase
= 21, // passphrase was wrong
62 // reasons for retrying a new passphrase query
63 passphraseIsNull
= 31, // empty passphrase
64 passphraseTooSimple
, // passphrase is not complex enough
65 passphraseRepeated
, // passphrase was used before (must use new one)
66 passphraseUnacceptable
, // passphrase unacceptable for some other reason
68 // reasons for retrying an authorization query
69 userNotInGroup
= 41, // authenticated user not in needed group
70 unacceptableUser
, // authenticated user unacceptable for some other reason
72 // reasons for canceling a staged query
73 tooManyTries
= 61, // too many failed attempts to get it right
74 noLongerNeeded
, // the queried item is no longer needed
75 keychainAddFailed
, // the requested itemed couldn't be added to the keychain
76 generalErrorCancel
// something went wrong so we have to give up now
79 #if defined(__cplusplus)
83 // The client interface to the SecurityAgent.
90 void activate(const char *bootstrapName
= NULL
);
93 bool keepAlive() const { return mKeepAlive
; }
94 void keepAlive(bool ka
) { mKeepAlive
= ka
; }
96 // common stage termination calls
97 void finishStagedQuery();
98 void cancelStagedQuery(Reason reason
);
102 bool show
; // show the "save in keychain" checkbox (in)
103 bool setting
; // value of the checkbox (in/out)
107 // ask to unlock an existing database. Staged protocol
108 void queryUnlockDatabase(const OSXCode
*requestor
, pid_t requestPid
,
109 const char *database
, char passphrase
[maxPassphraseLength
]);
110 void retryUnlockDatabase(Reason reason
, char passphrase
[maxPassphraseLength
]);
112 // ask for a new passphrase for a database. Not yet staged
113 void queryNewPassphrase(const OSXCode
*requestor
, pid_t requestPid
,
114 const char *database
, Reason reason
, char passphrase
[maxPassphraseLength
]);
115 void retryNewPassphrase(Reason reason
, char passphrase
[maxPassphraseLength
]);
117 // ask permission to use an item in a database
118 struct KeychainChoice
{
120 bool continueGrantingToCaller
;
122 void queryKeychainAccess(const OSXCode
*requestor
, pid_t requestPid
,
123 const char *database
, const char *itemName
, AclAuthorization action
,
124 KeychainChoice
&choice
);
126 // generic old passphrase query
127 void queryOldGenericPassphrase(const OSXCode
*requestor
, pid_t requestPid
,
129 KeychainBox
&addToKeychain
, char passphrase
[maxPassphraseLength
]);
130 void retryOldGenericPassphrase(Reason reason
,
131 bool &addToKeychain
, char passphrase
[maxPassphraseLength
]);
133 // generic new passphrase query
134 void queryNewGenericPassphrase(const OSXCode
*requestor
, pid_t requestPid
,
135 const char *prompt
, Reason reason
,
136 KeychainBox
&addToKeychain
, char passphrase
[maxPassphraseLength
]);
137 void retryNewGenericPassphrase(Reason reason
,
138 bool &addToKeychain
, char passphrase
[maxPassphraseLength
]);
140 // authenticate a user for the purpose of authorization
141 bool authorizationAuthenticate(const OSXCode
*requestor
, pid_t requestPid
,
142 const char *neededGroup
, const char *candidateUser
,
143 char username
[maxUsernameLength
], char passphrase
[maxPassphraseLength
]);
144 bool retryAuthorizationAuthenticate(Reason reason
,
145 char username
[maxUsernameLength
], char passphrase
[maxPassphraseLength
]);
147 // Cancel a pending client call in another thread by sending a cancel message.
148 // This call (only) may be made from another thread.
152 // used by client call wrappers to receive IPC return-status
161 mach_port_t pbsBootstrap
;
165 mainStage
, // in between requests
166 unlockStage
, // in unlock sub-protocol
167 newPassphraseStage
, // in get-new-passphrase sub-protocol
168 newGenericPassphraseStage
, // in get-new-generic-passphrase sub-protocol
169 oldGenericPassphraseStage
, // in get-old-generic-passphrase sub-protocol
170 authorizeStage
// in authorize-by-group-membership sub-protocol
174 void locateDesktop();
175 void establishServer(const char *name
);
176 void check(kern_return_t error
);
180 static const int cancelMessagePseudoID
= 1200;
183 }; // end namespace SecurityAgent
185 } // end namespace Security
189 #endif //_H_SECURITYAGENTCLIENT