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