]> git.saurik.com Git - apple/securityd.git/blob - src/agentquery.h
16a34ad21e4de3d9dcf4b41f74cd183c43a33fb3
[apple/securityd.git] / src / agentquery.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26
27 //
28 // passphrases - canonical code to obtain passphrases
29 //
30 #ifndef _H_AGENTQUERY
31 #define _H_AGENTQUERY
32
33 #include "securityserver.h"
34 #include <security_agent_client/agentclient.h>
35 #include <security_cdsa_utilities/AuthorizationData.h>
36 #include <Security/AuthorizationPlugin.h>
37 #include "kcdatabase.h"
38 #include "AuthorizationEngine.h"
39
40 using Authorization::AuthItemSet;
41 using Authorization::AuthValueVector;
42 using Security::CodeSigning::OSXCode;
43 //
44 // The common machinery of retryable SecurityAgent queries
45 //
46 class Session;
47
48 class SecurityAgentQuery : protected SecurityAgent::Client {
49 public:
50 typedef SecurityAgent::Reason Reason;
51
52 static const char defaultName[];
53
54 SecurityAgentQuery();
55 SecurityAgentQuery(uid_t clientUID, const Session &clientSession, const char *agentName = defaultName);
56
57 void inferHints(Process &thisProcess);
58
59 virtual ~SecurityAgentQuery();
60
61 virtual void activate();
62 virtual void terminate();
63
64 public:
65 void readChoice();
66
67 bool allow;
68 bool remember;
69
70 protected:
71 AuthItemSet mClientHints;
72 private:
73 const Session &mClientSession;
74 };
75
76 //
77 // Specialized for "rogue app" alert queries
78 //
79 class QueryKeychainUse : public SecurityAgentQuery {
80 public:
81 QueryKeychainUse(bool needPass, const Database *db);
82 Reason queryUser (const char* database, const char *description, AclAuthorization action);
83
84 private:
85 const KeychainDatabase *mPassphraseCheck; // NULL to not check passphrase
86 };
87
88
89 //
90 // Specialized for code signature adjustment queries
91 //
92 class QueryCodeCheck : public SecurityAgentQuery {
93 public:
94 bool operator () (const char *aclPath);
95 };
96
97
98 //
99 // A query for an existing passphrase
100 //
101 class QueryUnlock : public SecurityAgentQuery {
102 static const int maxTries = kMaximumAuthorizationTries;
103 public:
104 QueryUnlock(KeychainDatabase &db) : database(db) { }
105
106 KeychainDatabase &database;
107
108 Reason operator () ();
109
110 protected:
111 Reason query();
112 void queryInteractive(CssmOwnedData &passphrase);
113 void retryInteractive(CssmOwnedData &passphrase, Reason reason);
114 Reason accept(CssmManagedData &passphrase);
115 };
116
117
118 //
119 // A query for a new passphrase
120 //
121 class QueryNewPassphrase : public SecurityAgentQuery {
122 static const int maxTries = 7;
123 public:
124 QueryNewPassphrase(KeychainDatabase &db, Reason reason) :
125 database(db), initialReason(reason),
126 mPassphrase(Allocator::standard(Allocator::sensitive)),
127 mPassphraseValid(false) { }
128
129 KeychainDatabase &database;
130
131 Reason operator () (CssmOwnedData &passphrase);
132
133 protected:
134 Reason query();
135 Reason accept(CssmManagedData &passphrase, CssmData *oldPassphrase);
136
137 private:
138 Reason initialReason;
139 CssmAutoData mPassphrase;
140 bool mPassphraseValid;
141 };
142
143
144 //
145 // Generic passphrase query (not associated with a database)
146 //
147 class QueryGenericPassphrase : public SecurityAgentQuery {
148 public:
149 QueryGenericPassphrase() { }
150 Reason operator () (const char *prompt, bool verify,
151 string &passphrase);
152
153 protected:
154 Reason query(const char *prompt, bool verify, string &passphrase);
155 };
156
157
158 class QueryInvokeMechanism : public RefCount, SecurityAgentQuery {
159 public:
160 QueryInvokeMechanism();
161 QueryInvokeMechanism(uid_t clientUID, const Session &session, const char *agentName = NULL);
162 void initialize(const string &inPluginId, const string &inMechanismId, const SessionId inSessionId = 0);
163 void run(const AuthValueVector &inArguments, AuthItemSet &inHints, AuthItemSet &inContext, AuthorizationResult *outResult);
164
165 bool operator () (const string &inPluginId, const string &inMechanismId, const Authorization::AuthValueVector &inArguments, AuthItemSet &inHints, AuthItemSet &inContext, AuthorizationResult *outResult);
166 void terminateAgent();
167 //~QueryInvokeMechanism();
168 };
169
170 #endif //_H_AGENTQUERY