2 * Copyright (c) 2002-2004,2011,2014 Apple 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@
25 // Access.h - Access control wrappers
27 #ifndef _SECURITY_ACCESS_H_
28 #define _SECURITY_ACCESS_H_
30 #include <security_keychain/ACL.h>
31 #include <security_utilities/trackingallocator.h>
32 #include <security_cdsa_utilities/cssmaclpod.h>
33 #include <security_cdsa_utilities/cssmacl.h>
34 #include <security_cdsa_client/aclclient.h>
35 #include <security_keychain/TrustedApplication.h>
39 namespace KeychainCore
{
41 using CssmClient::AclBearer
;
44 class Access
: public SecCFObject
{
47 SECCFFUNCTIONS(Access
, SecAccessRef
, errSecInvalidItemRef
, gTypes().Access
)
51 static const size_t keySize
= 16; // number of (random) bytes
54 enum MakerType
{kStandardMakerType
, kAnyMakerType
};
56 Maker(Allocator
&alloc
= Allocator::standard(), MakerType makerType
= kStandardMakerType
);
58 void initialOwner(ResourceControlContext
&ctx
, const AccessCredentials
*creds
= NULL
);
59 const AccessCredentials
*cred();
61 TrackingAllocator allocator
;
63 static const char creationEntryTag
[];
65 MakerType
makerType() {return mMakerType
;}
70 AutoCredentials mCreds
;
76 Access(const string
&description
);
77 Access(const string
&description
, const ACL::ApplicationList
&trusted
);
78 Access(const string
&description
, const ACL::ApplicationList
&trusted
,
79 const AclAuthorizationSet
&limitedRights
, const AclAuthorizationSet
&freeRights
);
81 // make a completely open Access (anyone can do anything)
84 // retrieve from an existing AclBearer
85 Access(AclBearer
&source
);
87 // make from CSSM layer information (presumably retrieved by caller)
88 Access(const CSSM_ACL_OWNER_PROTOTYPE
&owner
,
89 uint32 aclCount
, const CSSM_ACL_ENTRY_INFO
*acls
);
93 CFArrayRef
copySecACLs() const;
94 CFArrayRef
copySecACLs(CSSM_ACL_AUTHORIZATION_TAG action
) const;
96 void add(ACL
*newAcl
);
97 void addOwner(ACL
*newOwnerAcl
);
99 void setAccess(AclBearer
&target
, bool update
= false);
100 void setAccess(AclBearer
&target
, Maker
&maker
);
102 void editAccess(AclBearer
&target
, bool update
, const AccessCredentials
*cred
);
104 template <class Container
>
105 void findAclsForRight(AclAuthorization right
, Container
&cont
)
108 for (Map::const_iterator it
= mAcls
.begin(); it
!= mAcls
.end(); it
++)
109 if (it
->second
->authorizes(right
))
110 cont
.push_back(it
->second
);
113 // findAclsForRight may return ACLs that have an empty authorization list (and thus "authorize everything")
114 // or CSSM_ACL_AUTHORIZATION_ANY, but sometimes you need positive confirmation of a right.
115 template <class Container
>
116 void findSpecificAclsForRight(AclAuthorization right
, Container
&cont
)
119 for (Map::const_iterator it
= mAcls
.begin(); it
!= mAcls
.end(); it
++)
120 if (it
->second
->authorizesSpecifically(right
))
121 cont
.push_back(it
->second
);
124 // Remove all acl entries that refer to this right.
125 void removeAclsForRight(AclAuthorization right
);
127 std::string
promptDescription() const; // from any one of the ACLs contained
129 void addApplicationToRight(AclAuthorization right
, TrustedApplication
*app
);
131 void copyOwnerAndAcl(CSSM_ACL_OWNER_PROTOTYPE
* &owner
,
132 uint32
&aclCount
, CSSM_ACL_ENTRY_INFO
* &acls
);
135 void makeStandard(const string
&description
, const ACL::ApplicationList
&trusted
,
136 const AclAuthorizationSet
&limitedRights
= AclAuthorizationSet(),
137 const AclAuthorizationSet
&freeRights
= AclAuthorizationSet());
138 void compile(const CSSM_ACL_OWNER_PROTOTYPE
&owner
,
139 uint32 aclCount
, const CSSM_ACL_ENTRY_INFO
*acls
);
143 static const CSSM_ACL_HANDLE ownerHandle
= ACL::ownerHandle
;
144 typedef map
<CSSM_ACL_HANDLE
, SecPointer
<ACL
> > Map
;
146 Map mAcls
; // set of ACL entries
151 } // end namespace KeychainCore
152 } // end namespace Security
154 #endif // !_SECURITY_ACCESS_H_