]> git.saurik.com Git - apple/securityd.git/blob - src/agentquery.h
securityd-32596.tar.gz
[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 * 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 //
26 // passphrases - canonical code to obtain passphrases
27 //
28 #ifndef _H_AGENTQUERY
29 #define _H_AGENTQUERY
30
31 #include <security_agent_client/agentclient.h>
32 #include <security_cdsa_utilities/AuthorizationData.h>
33 #include <Security/AuthorizationPlugin.h>
34 #include "kcdatabase.h"
35 #include "AuthorizationEngine.h"
36 #include "authhost.h"
37 #include "server.h"
38 #include "session.h"
39
40 using Authorization::AuthItemSet;
41 using Authorization::AuthValueVector;
42 using Security::OSXCode;
43
44 class SecurityAgentQuery : public SecurityAgent::Client {
45 public:
46 typedef SecurityAgent::Reason Reason;
47
48 SecurityAgentQuery(const AuthHostType type = securityAgent, Session &session = Server::session());
49
50 void inferHints(Process &thisProcess);
51
52 virtual ~SecurityAgentQuery();
53
54 virtual void activate();
55 virtual void terminate();
56 void create(const char *pluginId, const char *mechanismId, const SessionId inSessionId);
57
58 public:
59 void readChoice();
60
61 bool allow;
62 bool remember;
63 AuthHostType mAuthHostType;
64 RefPointer<AuthHostInstance> mHostInstance;
65
66 protected:
67 AuthItemSet mClientHints;
68 private:
69 Port mPort;
70 const RefPointer<Connection> mConnection;
71 };
72
73 //
74 // Specialized for "rogue app" alert queries
75 //
76 class QueryKeychainUse : public SecurityAgentQuery {
77 public:
78 QueryKeychainUse(bool needPass, const Database *db);
79 Reason queryUser (const char* database, const char *description, AclAuthorization action);
80
81 private:
82 const KeychainDatabase *mPassphraseCheck; // NULL to not check passphrase
83 };
84
85
86 //
87 // Specialized for code signature adjustment queries
88 //
89 class QueryCodeCheck : public SecurityAgentQuery {
90 public:
91 bool operator () (const char *aclPath);
92 };
93
94
95 //
96 // A query for an existing passphrase
97 //
98 class QueryOld : public SecurityAgentQuery {
99 static const int maxTries = kMaximumAuthorizationTries;
100 public:
101 QueryOld(Database &db) : database(db) { }
102
103 Database &database;
104
105 Reason operator () ();
106
107 protected:
108 Reason query();
109 virtual Reason accept(CssmManagedData &) = 0;
110 };
111
112
113 class QueryUnlock : public QueryOld {
114 public:
115 QueryUnlock(KeychainDatabase &db) : QueryOld(db) { }
116
117 protected:
118 Reason accept(CssmManagedData &passphrase);
119 };
120
121
122 //
123 // Repurpose QueryUnlock for PIN prompting
124 // Not very clean - but this stuff is an outdated hack as it is...
125 //
126 class QueryPIN : public QueryOld {
127 public:
128 QueryPIN(Database &db);
129
130 const CssmData &pin() const { return mPin; }
131
132 protected:
133 Reason accept(CssmManagedData &pin);
134
135 private:
136 CssmAutoData mPin; // PIN obtained
137 };
138
139
140 //
141 // A query for a new passphrase
142 //
143 class QueryNewPassphrase : public SecurityAgentQuery {
144 static const int maxTries = 7;
145 public:
146 QueryNewPassphrase(Database &db, Reason reason) :
147 database(db), initialReason(reason),
148 mPassphrase(Allocator::standard(Allocator::sensitive)),
149 mPassphraseValid(false) { }
150
151 Database &database;
152
153 Reason operator () (CssmOwnedData &passphrase);
154
155 protected:
156 Reason query();
157 virtual Reason accept(CssmManagedData &passphrase, CssmData *oldPassphrase);
158
159 private:
160 Reason initialReason;
161 CssmAutoData mPassphrase;
162 bool mPassphraseValid;
163 };
164
165
166 //
167 // Generic passphrase query (not associated with a database)
168 //
169 class QueryGenericPassphrase : public SecurityAgentQuery {
170 public:
171 QueryGenericPassphrase() { }
172 Reason operator () (const char *prompt, bool verify,
173 string &passphrase);
174
175 protected:
176 Reason query(const char *prompt, bool verify, string &passphrase);
177 };
178
179
180 //
181 // Generic secret query (not associated with a database)
182 //
183 class QueryDBBlobSecret : public SecurityAgentQuery {
184 static const int maxTries = kMaximumAuthorizationTries;
185 public:
186 QueryDBBlobSecret() { }
187 Reason operator () (DatabaseCryptoCore &dbCore, const DbBlob *secretsBlob);
188
189 void addHint(const char *name, const void *value = NULL, UInt32 valueLen = 0, UInt32 flags = 0);
190
191 protected:
192 Reason query(DatabaseCryptoCore &dbCore, const DbBlob *secretsBlob);
193 Reason accept(CssmManagedData &passphrase, DatabaseCryptoCore &dbCore, const DbBlob *secretsBlob);
194 };
195
196 class QueryInvokeMechanism : public SecurityAgentQuery, public RefCount {
197 public:
198 QueryInvokeMechanism(const AuthHostType type, Session &session);
199 void initialize(const string &inPluginId, const string &inMechanismId, const AuthValueVector &arguments, const SessionId inSessionId = 0);
200 void run(const AuthValueVector &inArguments, AuthItemSet &inHints, AuthItemSet &inContext, AuthorizationResult *outResult);
201
202 bool operator () (const string &inPluginId, const string &inMechanismId, const Authorization::AuthValueVector &inArguments, AuthItemSet &inHints, AuthItemSet &inContext, AuthorizationResult *outResult);
203 void terminateAgent();
204 //~QueryInvokeMechanism();
205
206 AuthValueVector mArguments;
207 };
208
209 #endif //_H_AGENTQUERY