]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/acl_threshold.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / acl_threshold.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 //
20 // acl_threshold - Threshold-based group ACL subjects.
21 //
22 // This subject type implements threshold (k of n) subjects as per CSSM standard.
23 // Subsubjects are stored and evaluated in the order received. Any subsubject
24 // is presented with all subsamples of the corresponding threshold sample, but
25 // not any other samples possibly present in the credentials. Subsubject evaluation
26 // stops as soon as the threshold is satisfied, or as soon as it becomes numerically
27 // impossible to satisfy the threshold with future matches.
28 // Note that this subject will reject out of hand any threshold sample that
29 // contains more than <n> subsamples. This defeats "sample stuffing" attacks
30 // where the attacker provides thousands of samples in the hope that some may
31 // match by accident. It will however accept threshold samples with fewer than
32 // <n> subsamples, as long as there are at least <k> subsamples.
33 //
34 #ifndef _ACL_THRESHOLD
35 #define _ACL_THRESHOLD
36
37 #include <Security/cssmacl.h>
38 #include <vector>
39
40 #ifdef _CPP_ACL_THRESHOLD
41 #pragma export on
42 #endif
43
44 namespace Security
45 {
46
47 class ThresholdAclSubject : public SimpleAclSubject {
48 typedef ObjectAcl::AclSubjectPointer AclSubjectPointer;
49 typedef vector<AclSubjectPointer> AclSubjectVector;
50 public:
51 bool validate(const AclValidationContext &baseCtx, const TypedList &sample) const;
52 CssmList toList(CssmAllocator &alloc) const;
53
54 ThresholdAclSubject(uint32 n, uint32 k, const AclSubjectVector &subSubjects);
55
56 void exportBlob(Writer::Counter &pub, Writer::Counter &priv);
57 void exportBlob(Writer &pub, Writer &priv);
58
59 IFDUMP(void debugDump() const);
60
61 class Maker : public AclSubject::Maker {
62 public:
63 Maker() : AclSubject::Maker(CSSM_ACL_SUBJECT_TYPE_THRESHOLD) { }
64 ThresholdAclSubject *make(const TypedList &list) const;
65 ThresholdAclSubject *make(Version, Reader &pub, Reader &priv) const;
66 };
67
68 private:
69 uint32 minimumNeeded; // number of matches needed
70 uint32 totalSubjects; // number of subSubjects
71 AclSubjectVector elements; // sub-subject vector
72
73 template <class Action>
74 void ThresholdAclSubject::exportBlobForm(Action &pub, Action &priv);
75 };
76
77 } // end namespace Security
78
79 #ifdef _CPP_ACL_THRESHOLD
80 #pragma export off
81 #endif
82
83 #endif //_ACL_THRESHOLD