2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
28 // passphrases - canonical code to obtain passphrases
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"
40 using Authorization::AuthItemSet
;
41 using Authorization::AuthValueVector
;
42 using Security::CodeSigning::OSXCode
;
44 // The common machinery of retryable SecurityAgent queries
48 class SecurityAgentQuery
: protected SecurityAgent::Client
{
50 typedef SecurityAgent::Reason Reason
;
52 static const char defaultName
[];
55 SecurityAgentQuery(uid_t clientUID
, const Session
&clientSession
, const char *agentName
= defaultName
);
57 void inferHints(Process
&thisProcess
);
59 virtual ~SecurityAgentQuery();
61 virtual void activate();
62 virtual void terminate();
71 AuthItemSet mClientHints
;
73 const Session
&mClientSession
;
77 // Specialized for "rogue app" alert queries
79 class QueryKeychainUse
: public SecurityAgentQuery
{
81 QueryKeychainUse(bool needPass
, const Database
*db
);
82 Reason
queryUser (const char* database
, const char *description
, AclAuthorization action
);
85 const KeychainDatabase
*mPassphraseCheck
; // NULL to not check passphrase
90 // Specialized for code signature adjustment queries
92 class QueryCodeCheck
: public SecurityAgentQuery
{
94 bool operator () (const char *aclPath
);
99 // A query for an existing passphrase
101 class QueryUnlock
: public SecurityAgentQuery
{
102 static const int maxTries
= kMaximumAuthorizationTries
;
104 QueryUnlock(KeychainDatabase
&db
) : database(db
) { }
106 KeychainDatabase
&database
;
108 Reason
operator () ();
112 void queryInteractive(CssmOwnedData
&passphrase
);
113 void retryInteractive(CssmOwnedData
&passphrase
, Reason reason
);
114 Reason
accept(CssmManagedData
&passphrase
);
119 // A query for a new passphrase
121 class QueryNewPassphrase
: public SecurityAgentQuery
{
122 static const int maxTries
= 7;
124 QueryNewPassphrase(KeychainDatabase
&db
, Reason reason
) :
125 database(db
), initialReason(reason
),
126 mPassphrase(Allocator::standard(Allocator::sensitive
)),
127 mPassphraseValid(false) { }
129 KeychainDatabase
&database
;
131 Reason
operator () (CssmOwnedData
&passphrase
);
135 Reason
accept(CssmManagedData
&passphrase
, CssmData
*oldPassphrase
);
138 Reason initialReason
;
139 CssmAutoData mPassphrase
;
140 bool mPassphraseValid
;
145 // Generic passphrase query (not associated with a database)
147 class QueryGenericPassphrase
: public SecurityAgentQuery
{
149 QueryGenericPassphrase() { }
150 Reason
operator () (const char *prompt
, bool verify
,
154 Reason
query(const char *prompt
, bool verify
, string
&passphrase
);
158 class QueryInvokeMechanism
: public RefCount
, SecurityAgentQuery
{
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
);
165 bool operator () (const string
&inPluginId
, const string
&inMechanismId
, const Authorization::AuthValueVector
&inArguments
, AuthItemSet
&inHints
, AuthItemSet
&inContext
, AuthorizationResult
*outResult
);
166 void terminateAgent();
167 //~QueryInvokeMechanism();
170 #endif //_H_AGENTQUERY