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
);
52 virtual ~SecurityAgentQuery();
54 virtual void activate();
55 virtual void terminate();
56 void create(const char *pluginId
, const char *mechanismId
, const SessionId inSessionId
);
63 AuthHostType mAuthHostType
;
64 RefPointer
<AuthHostInstance
> mHostInstance
;
67 AuthItemSet mClientHints
;
70 const RefPointer
<Connection
> mConnection
;
74 // Specialized for "rogue app" alert queries
76 class QueryKeychainUse
: public SecurityAgentQuery
{
78 QueryKeychainUse(bool needPass
, const Database
*db
);
79 Reason
queryUser (const char* database
, const char *description
, AclAuthorization action
);
82 const KeychainDatabase
*mPassphraseCheck
; // NULL to not check passphrase
87 // Specialized for code signature adjustment queries
89 class QueryCodeCheck
: public SecurityAgentQuery
{
91 bool operator () (const char *aclPath
);
96 // A query for an existing passphrase
98 class QueryOld
: public SecurityAgentQuery
{
99 static const int maxTries
= kMaximumAuthorizationTries
;
101 QueryOld(Database
&db
) : database(db
) { }
105 Reason
operator () ();
109 virtual Reason
accept(CssmManagedData
&) = 0;
113 class QueryUnlock
: public QueryOld
{
115 QueryUnlock(KeychainDatabase
&db
) : QueryOld(db
) { }
118 Reason
accept(CssmManagedData
&passphrase
);
123 // Repurpose QueryUnlock for PIN prompting
124 // Not very clean - but this stuff is an outdated hack as it is...
126 class QueryPIN
: public QueryOld
{
128 QueryPIN(Database
&db
);
130 const CssmData
&pin() const { return mPin
; }
133 Reason
accept(CssmManagedData
&pin
);
136 CssmAutoData mPin
; // PIN obtained
141 // A query for a new passphrase
143 class QueryNewPassphrase
: public SecurityAgentQuery
{
144 static const int maxTries
= 7;
146 QueryNewPassphrase(Database
&db
, Reason reason
) :
147 database(db
), initialReason(reason
),
148 mPassphrase(Allocator::standard(Allocator::sensitive
)),
149 mPassphraseValid(false) { }
153 Reason
operator () (CssmOwnedData
&passphrase
);
157 virtual Reason
accept(CssmManagedData
&passphrase
, CssmData
*oldPassphrase
);
160 Reason initialReason
;
161 CssmAutoData mPassphrase
;
162 bool mPassphraseValid
;
167 // Generic passphrase query (not associated with a database)
169 class QueryGenericPassphrase
: public SecurityAgentQuery
{
171 QueryGenericPassphrase() { }
172 Reason
operator () (const char *prompt
, bool verify
,
176 Reason
query(const char *prompt
, bool verify
, string
&passphrase
);
181 // Generic secret query (not associated with a database)
183 class QueryDBBlobSecret
: public SecurityAgentQuery
{
184 static const int maxTries
= kMaximumAuthorizationTries
;
186 QueryDBBlobSecret() { }
187 Reason
operator () (DatabaseCryptoCore
&dbCore
, const DbBlob
*secretsBlob
);
189 void addHint(const char *name
, const void *value
= NULL
, UInt32 valueLen
= 0, UInt32 flags
= 0);
192 Reason
query(DatabaseCryptoCore
&dbCore
, const DbBlob
*secretsBlob
);
193 Reason
accept(CssmManagedData
&passphrase
, DatabaseCryptoCore
&dbCore
, const DbBlob
*secretsBlob
);
196 class QueryInvokeMechanism
: public SecurityAgentQuery
, public RefCount
{
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
);
202 bool operator () (const string
&inPluginId
, const string
&inMechanismId
, const Authorization::AuthValueVector
&inArguments
, AuthItemSet
&inHints
, AuthItemSet
&inContext
, AuthorizationResult
*outResult
);
203 void terminateAgent();
204 //~QueryInvokeMechanism();
206 AuthValueVector mArguments
;
209 #endif //_H_AGENTQUERY