]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
1 | /* |
2 | * Copyright (c) 2006-2011 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 | #define STORE_RECEIPT_DIRECTORY "_MASReceipt" | |
39 | ||
40 | ||
41 | // | |
42 | // A BundleDiskRep represents a standard Mac OS X bundle on disk. | |
43 | // The bundle is expected to have an Info.plist, and a "main executable file" | |
44 | // of some sort (as indicated therein). | |
45 | // The BundleDiskRep stores the necessary components in the main executable | |
46 | // if it is in Mach-O format, or in files in a _CodeSignature directory if not. | |
47 | // This DiskRep supports resource sealing. | |
48 | // | |
49 | class BundleDiskRep : public DiskRep { | |
50 | public: | |
51 | BundleDiskRep(const char *path, const Context *ctx = NULL); | |
52 | BundleDiskRep(CFBundleRef ref, const Context *ctx = NULL); | |
53 | ||
54 | CFDataRef component(CodeDirectory::SpecialSlot slot); | |
55 | CFDataRef identification(); | |
56 | std::string mainExecutablePath(); | |
57 | CFURLRef canonicalPath(); | |
58 | std::string resourcesRootPath(); | |
59 | void adjustResources(ResourceBuilder &builder); | |
60 | Universal *mainExecutableImage(); | |
61 | size_t signingBase(); | |
62 | size_t signingLimit(); | |
63 | std::string format(); | |
64 | CFArrayRef modifiedFiles(); | |
65 | UnixPlusPlus::FileDesc &fd(); | |
66 | void flush(); | |
67 | ||
68 | std::string recommendedIdentifier(const SigningContext &ctx); | |
69 | CFDictionaryRef defaultResourceRules(const SigningContext &ctx); | |
70 | const Requirements *defaultRequirements(const Architecture *arch, const SigningContext &ctx); | |
71 | size_t pageSize(const SigningContext &ctx); | |
72 | ||
73 | CFBundleRef bundle() const { return mBundle; } | |
74 | ||
75 | public: | |
76 | Writer *writer(); | |
77 | class Writer; | |
78 | friend class Writer; | |
79 | ||
80 | protected: | |
81 | std::string metaPath(const char *name); | |
82 | CFDataRef metaData(const char *name) { return cfLoadFile(CFTempURL(metaPath(name))); } | |
83 | void createMeta(); // (try to) create the meta-file directory | |
84 | ||
85 | private: | |
86 | void setup(const Context *ctx); // shared init | |
87 | void checkModifiedFile(CFMutableArrayRef files, CodeDirectory::SpecialSlot slot); | |
88 | ||
89 | private: | |
90 | CFRef<CFBundleRef> mBundle; | |
91 | std::string mMetaPath; // path to directory containing signing files | |
92 | bool mMetaExists; // separate meta-file directory exists | |
93 | CFRef<CFURLRef> mMainExecutableURL; // chosen main executable URL | |
94 | bool mInstallerPackage; // is an installer (not executable) bundle | |
95 | string mFormat; // format description string | |
96 | RefPointer<DiskRep> mExecRep; // DiskRep for main executable file | |
97 | }; | |
98 | ||
99 | ||
100 | // | |
101 | // Writers | |
102 | // | |
103 | // | |
104 | class BundleDiskRep::Writer : public DiskRep::Writer { | |
105 | friend class BundleDiskRep; | |
106 | public: | |
107 | Writer(BundleDiskRep *r); | |
108 | ||
109 | void component(CodeDirectory::SpecialSlot slot, CFDataRef data); | |
110 | void remove(); | |
111 | void flush(); | |
112 | ||
113 | protected: | |
114 | DiskRep *execRep() { return rep->mExecRep; } | |
115 | void remove(CodeDirectory::SpecialSlot slot); | |
116 | ||
117 | protected: | |
118 | RefPointer<BundleDiskRep> rep; | |
119 | RefPointer<DiskRep::Writer> execWriter; | |
120 | bool mMadeMetaDirectory; | |
121 | }; | |
122 | ||
123 | ||
124 | } // end namespace CodeSigning | |
125 | } // end namespace Security | |
126 | ||
127 | #endif // !_H_BUNDLEDISKREP |