]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/bundlediskrep.h
a6ffe2b258f164297228621d5ca51fdc2b695beb
[apple/libsecurity_codesigning.git] / lib / bundlediskrep.h
1 /*
2 * Copyright (c) 2006-2007 Apple 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 // bundlediskrep - bundle directory disk representation
26 //
27 #ifndef _H_BUNDLEDISKREP
28 #define _H_BUNDLEDISKREP
29
30 #include "diskrep.h"
31 #include "machorep.h"
32
33 namespace Security {
34 namespace CodeSigning {
35
36
37 #define BUNDLEDISKREP_DIRECTORY "_CodeSignature"
38
39
40 //
41 // A BundleDiskRep represents a standard Mac OS X bundle on disk.
42 // The bundle is expected to have an Info.plist, and a "main executable file"
43 // of some sort (as indicated therein).
44 // The BundleDiskRep stores the necessary components in the main executable
45 // if it is in Mach-O format, or in Contents files if not.
46 // This DiskRep supports resource sealing.
47 //
48 class BundleDiskRep : public DiskRep {
49 public:
50 BundleDiskRep(const char *path);
51 BundleDiskRep(CFBundleRef ref);
52
53 CFDataRef component(CodeDirectory::SpecialSlot slot);
54 std::string mainExecutablePath();
55 CFURLRef canonicalPath();
56 std::string recommendedIdentifier();
57 std::string resourcesRootPath();
58 CFDictionaryRef defaultResourceRules();
59 void adjustResources(ResourceBuilder &builder);
60 const Requirements *defaultRequirements(const Architecture *arch);
61 Universal *mainExecutableImage();
62 size_t pageSize();
63 size_t signingBase();
64 size_t signingLimit();
65 std::string format();
66 CFArrayRef modifiedFiles();
67 UnixPlusPlus::FileDesc &fd();
68 void flush();
69
70 CFBundleRef bundle() const { return mBundle; }
71
72 public:
73 Writer *writer();
74 class Writer;
75 friend class Writer;
76
77 protected:
78 std::string metaPath(const char *name);
79 CFDataRef metaData(const char *name) { return cfLoadFile(CFTempURL(metaPath(name))); }
80 void createMeta(); // (try to) create the meta-file directory
81
82 private:
83 void checkModifiedFile(CFMutableArrayRef files, CodeDirectory::SpecialSlot slot);
84
85 private:
86 CFRef<CFBundleRef> mBundle;
87 std::string mMetaPath; // path to directory containing signing files
88 bool mMetaExists; // separate meta-file directory exists
89 RefPointer<DiskRep> mExecRep; // DiskRep for main executable file
90 };
91
92
93 //
94 // Writers
95 //
96 //
97 class BundleDiskRep::Writer : public DiskRep::Writer {
98 friend class BundleDiskRep;
99 public:
100 Writer(BundleDiskRep *r);
101
102 void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
103 void flush();
104
105 protected:
106 DiskRep *execRep() { return rep->mExecRep; }
107
108 protected:
109 RefPointer<BundleDiskRep> rep;
110 RefPointer<DiskRep::Writer> execWriter;
111 bool mMadeMetaDirectory;
112 };
113
114
115 } // end namespace CodeSigning
116 } // end namespace Security
117
118 #endif // !_H_BUNDLEDISKREP