2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 // passphrases - canonical code to obtain passphrases
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"
40 using Authorization::AuthItemSet
;
41 using Authorization::AuthValueVector
;
42 using Security::OSXCode
;
44 class SecurityAgentQuery
: public SecurityAgent::Client
{
46 typedef SecurityAgent::Reason Reason
;
48 SecurityAgentQuery(const AuthHostType type
= securityAgent
, Session
&session
= Server::session());
50 void inferHints(Process
&thisProcess
);
51 void addHint(const char *name
, const void *value
= NULL
, UInt32 valueLen
= 0, UInt32 flags
= 0);
53 virtual ~SecurityAgentQuery();
55 virtual void activate();
56 virtual void terminate();
57 void create(const char *pluginId
, const char *mechanismId
, const SessionId inSessionId
);
64 AuthHostType mAuthHostType
;
65 RefPointer
<AuthHostInstance
> mHostInstance
;
68 AuthItemSet mClientHints
;
71 const RefPointer
<Connection
> mConnection
;
75 // Specialized for "rogue app" alert queries
77 class QueryKeychainUse
: public SecurityAgentQuery
{
79 QueryKeychainUse(bool needPass
, const Database
*db
);
80 Reason
queryUser (const char* database
, const char *description
, AclAuthorization action
);
83 const KeychainDatabase
*mPassphraseCheck
; // NULL to not check passphrase
88 // Specialized for code signature adjustment queries
90 class QueryCodeCheck
: public SecurityAgentQuery
{
92 bool operator () (const char *aclPath
);
97 // A query for an existing passphrase
99 class QueryOld
: public SecurityAgentQuery
{
100 static const int maxTries
= kMaximumAuthorizationTries
;
102 QueryOld(Database
&db
) : database(db
) { }
106 Reason
operator () ();
110 virtual Reason
accept(CssmManagedData
&) = 0;
114 class QueryUnlock
: public QueryOld
{
116 QueryUnlock(KeychainDatabase
&db
) : QueryOld(db
) { }
119 Reason
accept(CssmManagedData
&passphrase
);
124 // Repurpose QueryUnlock for PIN prompting
125 // Not very clean - but this stuff is an outdated hack as it is...
127 class QueryPIN
: public QueryOld
{
129 QueryPIN(Database
&db
);
131 const CssmData
&pin() const { return mPin
; }
134 Reason
accept(CssmManagedData
&pin
);
137 CssmAutoData mPin
; // PIN obtained
142 // A query for a new passphrase
144 class QueryNewPassphrase
: public SecurityAgentQuery
{
145 static const int maxTries
= 7;
147 QueryNewPassphrase(Database
&db
, Reason reason
) :
148 database(db
), initialReason(reason
),
149 mPassphrase(Allocator::standard(Allocator::sensitive
)),
150 mPassphraseValid(false) { }
154 Reason
operator () (CssmOwnedData
&passphrase
);
158 virtual Reason
accept(CssmManagedData
&passphrase
, CssmData
*oldPassphrase
);
161 Reason initialReason
;
162 CssmAutoData mPassphrase
;
163 bool mPassphraseValid
;
168 // Generic passphrase query (not associated with a database)
170 class QueryGenericPassphrase
: public SecurityAgentQuery
{
172 QueryGenericPassphrase() { }
173 Reason
operator () (const char *prompt
, bool verify
,
177 Reason
query(const char *prompt
, bool verify
, string
&passphrase
);
182 // Generic secret query (not associated with a database)
184 class QueryDBBlobSecret
: public SecurityAgentQuery
{
185 static const int maxTries
= kMaximumAuthorizationTries
;
187 QueryDBBlobSecret() { }
188 Reason
operator () (DatabaseCryptoCore
&dbCore
, const DbBlob
*secretsBlob
);
191 Reason
query(DatabaseCryptoCore
&dbCore
, const DbBlob
*secretsBlob
);
192 Reason
accept(CssmManagedData
&passphrase
, DatabaseCryptoCore
&dbCore
, const DbBlob
*secretsBlob
);
195 class QueryInvokeMechanism
: public SecurityAgentQuery
, public RefCount
{
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
);
201 bool operator () (const string
&inPluginId
, const string
&inMechanismId
, const Authorization::AuthValueVector
&inArguments
, AuthItemSet
&inHints
, AuthItemSet
&inContext
, AuthorizationResult
*outResult
);
202 void terminateAgent();
203 //~QueryInvokeMechanism();
205 AuthValueVector mArguments
;
208 #endif //_H_AGENTQUERY