2 * Copyright (c) 2000-2001,2007,2011 Apple Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
22 #ifndef _H_CDSA_CLIENT_ACLCLIENT
23 #define _H_CDSA_CLIENT_ACLCLIENT 1
25 #include <security_cdsa_utilities/cssmaclpod.h>
26 #include <security_cdsa_utilities/cssmacl.h>
27 #include <security_cdsa_utilities/cssmcred.h>
28 #include <security_utilities/refcount.h>
29 #include <security_utilities/globalizer.h>
32 namespace CssmClient
{
38 // Any client-side object that has CSSM-layer ACLs shall be
39 // derived from AclBearer and implement its methods accordingly.
40 // Note the (shared/virtual) RefCount - you should handle AclBearer
41 // references via RefPointers.
42 // All the non-pure methods are implemented (in AclBearer) in terms of
43 // the pure virtual methods; they just restate the problem in various ways.
45 class AclBearer
: public virtual RefCount
{
50 virtual void getAcl(AutoAclEntryInfoList
&aclInfos
,
51 const char *selectionTag
= NULL
) const = 0;
52 virtual void changeAcl(const CSSM_ACL_EDIT
&aclEdit
,
53 const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
) = 0;
55 void addAcl(const AclEntryInput
&input
, const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
);
56 void changeAcl(CSSM_ACL_HANDLE handle
, const AclEntryInput
&input
,
57 const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
);
58 void deleteAcl(CSSM_ACL_HANDLE handle
, const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
);
59 void deleteAcl(const char *tag
= NULL
, const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
);
61 // Acl owner manipulation
62 virtual void getOwner(AutoAclOwnerPrototype
&owner
) const = 0;
63 virtual void changeOwner(const CSSM_ACL_OWNER_PROTOTYPE
&newOwner
,
64 const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
) = 0;
69 // An AclBearer applied to a raw CSSM key
71 class KeyAclBearer
: public AclBearer
{
73 KeyAclBearer(CSSM_CSP_HANDLE cspH
, CSSM_KEY
&theKey
, Allocator
&alloc
)
74 : csp(cspH
), key(theKey
), allocator(alloc
) { }
76 const CSSM_CSP_HANDLE csp
;
81 void getAcl(AutoAclEntryInfoList
&aclInfos
,
82 const char *selectionTag
= NULL
) const;
83 void changeAcl(const CSSM_ACL_EDIT
&aclEdit
,
84 const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
);
85 void getOwner(AutoAclOwnerPrototype
&owner
) const;
86 void changeOwner(const CSSM_ACL_OWNER_PROTOTYPE
&newOwner
,
87 const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
);
92 // An AclFactory helps create and maintain CSSM-layer AccessCredentials
93 // and matching samples. There is state in an AclFactory, though simple
94 // uses may not care about it.
99 virtual ~AclFactory();
101 // these values are owned by the AclFactory and persist
102 // until it is destroyed. You don't own the memory.
103 const AccessCredentials
*nullCred() const; // conforming empty
104 const AccessCredentials
*promptCred() const; // enable interactive prompting
105 const AccessCredentials
*unlockCred() const;
106 const AccessCredentials
*cancelCred() const;
107 const AccessCredentials
*promptedPINCred() const;
108 const AccessCredentials
*promptedPINItemCred() const;
110 const AclOwnerPrototype
&anyOwner() const; // wide-open owner
111 const AclEntryInfo
&anyAcl() const; // wide-open ACL entry (authorizes anything)
114 class KeychainCredentials
{
116 KeychainCredentials(Allocator
&alloc
)
117 : allocator(alloc
), mCredentials(new AutoCredentials(alloc
)) { }
118 virtual ~KeychainCredentials();
120 Allocator
&allocator
;
122 operator const AccessCredentials
* () const { return mCredentials
; }
123 AccessCredentials
* getAccessCredentials() const { return mCredentials
; }
126 AutoCredentials
*mCredentials
;
130 // create a self-managed AccessCredentials to explicitly provide a keychain passphrase
131 class PassphraseUnlockCredentials
: public KeychainCredentials
{
133 PassphraseUnlockCredentials (const CssmData
& password
, Allocator
& allocator
);
136 // create a self-managed AccessCredentials to change a keychain passphrase
137 class PasswordChangeCredentials
: public KeychainCredentials
{
139 PasswordChangeCredentials (const CssmData
& password
, Allocator
& allocator
);
142 // create an AccessCredentials to explicitly provide a keychain master key
143 class MasterKeyUnlockCredentials
: public KeychainCredentials
{
145 MasterKeyUnlockCredentials (const Key
& key
, Allocator
& allocator
);
149 class AnyResourceContext
: public ResourceControlContext
{
151 AnyResourceContext(const CSSM_ACCESS_CREDENTIALS
*cred
= NULL
);
155 CSSM_ACL_AUTHORIZATION_TAG mTag
;
160 // Subject makers. Contents are chunk-allocated with the Allocator given
162 struct Subject
: public TypedList
{
163 Subject(Allocator
&alloc
, CSSM_ACL_SUBJECT_TYPE type
);
166 // an ANY subject, allocated dynamically for you
167 struct AnySubject
: public Subject
{
168 AnySubject(Allocator
&alloc
) : Subject(alloc
, CSSM_ACL_SUBJECT_TYPE_ANY
) { }
171 // a "nobody" subject (something guaranteed never to match)
172 struct NobodySubject
: public Subject
{
173 NobodySubject(Allocator
&alloc
) : Subject(alloc
, CSSM_ACL_SUBJECT_TYPE_COMMENT
) { }
177 struct PWSubject
: public Subject
{
178 PWSubject(Allocator
&alloc
); // no secret
179 PWSubject(Allocator
&alloc
, const CssmData
&secret
); // this secret
182 struct PromptPWSubject
: public Subject
{
183 PromptPWSubject(Allocator
&alloc
, const CssmData
&prompt
);
184 PromptPWSubject(Allocator
&alloc
, const CssmData
&prompt
, const CssmData
&secret
);
187 struct ProtectedPWSubject
: public Subject
{
188 ProtectedPWSubject(Allocator
&alloc
);
191 // PIN (pre-auth) reference, origin side
192 struct PinSubject
: public Subject
{
193 PinSubject(Allocator
&alloc
, uint32 slot
);
196 // PIN (pre-auth) source site
197 struct PinSourceSubject
: public Subject
{
198 PinSourceSubject(Allocator
&alloc
, const TypedList
&form
);
203 } // end namespace CssmClient
204 } // end namespace Security
206 #endif // _H_CDSA_CLIENT_ACLCLIENT