]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/bundlediskrep.h
72c126f09bd9dd8f4699cf50297e45dfc3956dbe
[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, const Context *ctx = NULL);
51 BundleDiskRep(CFBundleRef ref, const Context *ctx = NULL);
52
53 CFDataRef component(CodeDirectory::SpecialSlot slot);
54 CFDataRef identification();
55 std::string mainExecutablePath();
56 CFURLRef canonicalPath();
57 std::string resourcesRootPath();
58 void adjustResources(ResourceBuilder &builder);
59 Universal *mainExecutableImage();
60 size_t signingBase();
61 size_t signingLimit();
62 std::string format();
63 CFArrayRef modifiedFiles();
64 UnixPlusPlus::FileDesc &fd();
65 void flush();
66
67 std::string recommendedIdentifier(const SigningContext &ctx);
68 CFDictionaryRef defaultResourceRules(const SigningContext &ctx);
69 const Requirements *defaultRequirements(const Architecture *arch, const SigningContext &ctx);
70 size_t pageSize(const SigningContext &ctx);
71
72 CFBundleRef bundle() const { return mBundle; }
73
74 public:
75 Writer *writer();
76 class Writer;
77 friend class Writer;
78
79 protected:
80 std::string metaPath(const char *name);
81 CFDataRef metaData(const char *name) { return cfLoadFile(CFTempURL(metaPath(name))); }
82 void createMeta(); // (try to) create the meta-file directory
83
84 private:
85 void setup(const Context *ctx); // shared init
86 void checkModifiedFile(CFMutableArrayRef files, CodeDirectory::SpecialSlot slot);
87
88 private:
89 CFRef<CFBundleRef> mBundle;
90 std::string mMetaPath; // path to directory containing signing files
91 bool mMetaExists; // separate meta-file directory exists
92 RefPointer<DiskRep> mExecRep; // DiskRep for main executable file
93 };
94
95
96 //
97 // Writers
98 //
99 //
100 class BundleDiskRep::Writer : public DiskRep::Writer {
101 friend class BundleDiskRep;
102 public:
103 Writer(BundleDiskRep *r);
104
105 void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
106 void remove();
107 void flush();
108
109 protected:
110 DiskRep *execRep() { return rep->mExecRep; }
111 void remove(CodeDirectory::SpecialSlot slot);
112
113 protected:
114 RefPointer<BundleDiskRep> rep;
115 RefPointer<DiskRep::Writer> execWriter;
116 bool mMadeMetaDirectory;
117 };
118
119
120 } // end namespace CodeSigning
121 } // end namespace Security
122
123 #endif // !_H_BUNDLEDISKREP