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