]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/resources.h
834d8945740bcf07e284bd0ab5e9f598f85fcc2a
[apple/libsecurity_codesigning.git] / lib / resources.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 //
25 // resource directory construction and verification
26 //
27 #ifndef _H_RSIGN
28 #define _H_RSIGN
29
30 #include "renum.h"
31 #include <security_utilities/utilities.h>
32 #include <security_utilities/cfutilities.h>
33 #include <security_utilities/hashing.h>
34 #include "regex.h"
35 #include <CoreFoundation/CoreFoundation.h>
36 #include <vector>
37
38 namespace Security {
39 namespace CodeSigning {
40
41
42 //
43 // The builder of ResourceDirectories.
44 //
45 // Note that this *is* a ResourceEnumerate, which can enumerate
46 // its source directory once (only).
47 //
48 class ResourceBuilder : public ResourceEnumerator {
49 public:
50 ResourceBuilder(const std::string &root, CFDictionaryRef rules);
51 ~ResourceBuilder();
52
53 CFDictionaryRef build();
54
55 enum Action {
56 optional = 0x01, // may be absent at runtime
57 omitted = 0x02, // do not seal even if present
58 exclusion = 0x04, // overriding exclusion (stop looking)
59 };
60
61 typedef unsigned int Weight;
62
63 public:
64 class Rule : private regex_t {
65 public:
66 Rule(const std::string &pattern, Weight weight, uint32_t flags);
67 ~Rule();
68
69 bool match(const char *s) const;
70
71 const Weight weight;
72 const uint32_t flags;
73 };
74 void addRule(Rule *rule) { mRules.push_back(rule); }
75 void addExclusion(const std::string &pattern) { mRules.insert(mRules.begin(), new Rule(pattern, 0, exclusion)); }
76
77 FTSENT *next(std::string &path, Rule * &rule); // enumerate next file and match rule
78
79 protected:
80 void addRule(CFTypeRef key, CFTypeRef value);
81 CFDataRef hashFile(const char *path);
82
83 private:
84 CFCopyRef<CFDictionaryRef> mRawRules;
85 typedef std::vector<Rule *> Rules;
86 Rules mRules;
87 };
88
89
90 //
91 // The "seal" on a single resource.
92 //
93 class ResourceSeal {
94 public:
95 ResourceSeal(CFTypeRef ref);
96
97 public:
98 operator bool () const { return mHash; }
99 bool operator ! () const { return mHash == NULL; }
100
101 const SHA1::Byte *hash() const { return CFDataGetBytePtr(mHash); }
102 bool optional() const { return mOptional; }
103
104 private:
105 CFDataRef mHash;
106 int mOptional;
107 };
108
109
110 } // end namespace CodeSigning
111 } // end namespace Security
112
113 #endif // !_H_RSIGN