2 * Copyright (c) 2002 Apple Computer, 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.
19 // ACL.h - ACL control wrappers
21 #ifndef _SECURITY_ACL_H_
22 #define _SECURITY_ACL_H_
24 #include <Security/SecRuntime.h>
25 #include <Security/cssmaclpod.h>
26 #include <Security/aclclient.h>
27 #include <Security/cssmdata.h>
31 namespace KeychainCore
{
33 using CssmClient::AclBearer
;
36 class TrustedApplication
;
40 // An ACL Entry for an Access object
42 class ACL
: public SecCFObject
{
45 // create from CSSM layer ACL entry
46 ACL(Access
&acc
, const AclEntryInfo
&info
,
47 CssmAllocator
&alloc
= CssmAllocator::standard());
48 // create from CSSM layer owner prototype
49 ACL(Access
&acc
, const AclOwnerPrototype
&owner
,
50 CssmAllocator
&alloc
= CssmAllocator::standard());
51 // create an "any" ACL
52 ACL(Access
&acc
, CssmAllocator
&alloc
= CssmAllocator::standard());
53 // create from "standard form" arguments (with empty application list)
54 ACL(Access
&acc
, string description
, const CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
&promptSelector
,
55 CssmAllocator
&alloc
= CssmAllocator::standard());
58 CssmAllocator
&allocator
;
61 unchanged
, // unchanged from source
63 modified
, // was changed (replace)
64 deleted
// was deleted (now invalid)
66 State
state() const { return mState
; }
69 invalidForm
, // invalid
70 customForm
, // not a recognized format (but valid)
71 allowAllForm
, // indiscriminate
72 appListForm
// list of apps + prompt confirm
74 Form
form() const { return mForm
; }
75 void form(Form f
) { mForm
= f
; }
77 Access
&access
; // we belong to this Access
80 AclAuthorizationSet
&authorizations() { return mAuthorizations
; }
81 bool authorizes(AclAuthorization right
) const;
82 void setAuthorization(CSSM_ACL_AUTHORIZATION_TAG auth
)
83 { mAuthorizations
.clear(); mAuthorizations
.insert(auth
); }
85 typedef vector
< RefPointer
<TrustedApplication
> > ApplicationList
;
86 ApplicationList
&applications()
87 { assert(form() == appListForm
); return mAppList
; }
88 void addApplication(TrustedApplication
*app
);
90 CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
&promptSelector()
91 { assert(form() == appListForm
); return mPromptSelector
; }
92 string
&promptDescription()
93 { assert(form() == appListForm
); return mPromptDescription
; }
95 CSSM_ACL_HANDLE
entryHandle() const { return mCssmHandle
; }
97 static const CSSM_ACL_HANDLE ownerHandle
= 0xff0e2743; // pseudo-handle for owner ACL
98 bool isOwner() const { return mCssmHandle
== ownerHandle
; }
99 void makeOwner() { mCssmHandle
= ownerHandle
; }
105 void setAccess(AclBearer
&target
, bool update
= false,
106 const AccessCredentials
*cred
= NULL
);
109 struct ParseError
{ };
112 static const CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR defaultSelector
;
115 void parse(const TypedList
&subject
);
116 void parsePrompt(const TypedList
&subject
);
118 void clearSubjects(Form newForm
);
121 State mState
; // change state
122 Form mForm
; // format type
124 // AclEntryPrototype fields (minus subject, which is virtually constructed)
125 CSSM_ACL_HANDLE mCssmHandle
; // CSSM entry handle (for updates)
126 string mEntryTag
; // CSSM entry tag (64 bytes or so, they say)
127 bool mDelegate
; // CSSM delegate flag
128 AclAuthorizationSet mAuthorizations
; // rights for this ACL entry
130 // composite AclEntryPrototype (constructed when needed)
131 TypedList
*mSubjectForm
;
133 // following values valid only if form() == appListForm
134 ApplicationList mAppList
; // list of trusted applications
135 CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR mPromptSelector
; // selector field of PROMPT subject
136 string mPromptDescription
; // description field of PROMPT subject
140 } // end namespace KeychainCore
141 } // end namespace Security
143 #endif // !_SECURITY_ACL_H_