]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/bundlediskrep.h
Security-58286.251.4.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / lib / bundlediskrep.h
1 /*
2 * Copyright (c) 2006-2012,2014 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 #include <sys/cdefs.h>
34
35 #if TARGET_OS_OSX
36 __BEGIN_DECLS
37 #include <AppleFSCompression/AppleFSCompression.h>
38 __END_DECLS
39 #endif
40
41 namespace Security {
42 namespace CodeSigning {
43
44
45 #define BUNDLEDISKREP_DIRECTORY "_CodeSignature"
46 #define CODERESOURCES_LINK "CodeResources"
47 #define STORE_RECEIPT_DIRECTORY "_MASReceipt"
48
49
50 //
51 // A BundleDiskRep represents a standard Mac OS X bundle on disk.
52 // The bundle is expected to have an Info.plist, and a "main executable file"
53 // of some sort (as indicated therein).
54 // The BundleDiskRep stores the necessary components in the main executable
55 // if it is in Mach-O format, or in files in a _CodeSignature directory if not.
56 // This DiskRep supports resource sealing.
57 //
58 class BundleDiskRep : public DiskRep, public EditableDiskRep {
59 public:
60 BundleDiskRep(const char *path, const Context *ctx = NULL);
61 BundleDiskRep(CFBundleRef ref, const Context *ctx = NULL);
62 ~BundleDiskRep();
63
64 CFDataRef component(CodeDirectory::SpecialSlot slot);
65 RawComponentMap createRawComponents();
66 CFDataRef identification();
67 DiskRep *mainExecRep() const { return mExecRep.get(); };
68 std::string mainExecutablePath();
69 CFURLRef copyCanonicalPath();
70 std::string resourcesRootPath();
71 std::string resourcesRelativePath();
72 void adjustResources(ResourceBuilder &builder);
73 Universal *mainExecutableImage();
74 void prepareForSigning(SigningContext &context);
75 size_t signingBase();
76 size_t signingLimit();
77 size_t execSegBase(const Architecture *arch);
78 size_t execSegLimit(const Architecture *arch);
79 std::string format();
80 CFArrayRef modifiedFiles();
81 UnixPlusPlus::FileDesc &fd();
82 void flush();
83 CFDictionaryRef diskRepInformation();
84
85 std::string recommendedIdentifier(const SigningContext &ctx);
86 CFDictionaryRef defaultResourceRules(const SigningContext &ctx);
87 const Requirements *defaultRequirements(const Architecture *arch, const SigningContext &ctx);
88 size_t pageSize(const SigningContext &ctx);
89
90 void strictValidate(const CodeDirectory* cd, const ToleratedErrors& tolerated, SecCSFlags flags);
91 CFArrayRef allowedResourceOmissions();
92
93 void registerStapledTicket();
94
95 bool appleInternalForcePlatform() const {return forcePlatform;};
96
97 CFBundleRef bundle() const { return mBundle; }
98
99 public:
100 Writer *writer();
101 class Writer;
102 friend class Writer;
103
104 protected:
105 std::string metaPath(const char *name);
106 void createMeta(); // (try to) create the meta-file directory
107 CFDataRef metaData(const char *name);
108 CFDataRef metaData(CodeDirectory::SpecialSlot slot);
109
110 private:
111 void setup(const Context *ctx); // shared init
112 void checkModifiedFile(CFMutableArrayRef files, CodeDirectory::SpecialSlot slot);
113 CFDataRef loadRegularFile(CFURLRef url);
114 void recordStrictError(OSStatus error);
115 void validateMetaDirectory(const CodeDirectory* cd);
116 void validateFrameworkRoot(std::string root);
117 void checkPlainFile(UnixPlusPlus::FileDesc fd, const std::string& path);
118 void checkForks(UnixPlusPlus::FileDesc fd);
119 void checkMoved(CFURLRef oldPath, CFURLRef newPath);
120 void componentFromExec(bool fromExec);
121
122 private:
123 CFRef<CFBundleRef> mBundle;
124 std::string mMetaPath; // path to directory containing signing files
125 bool mMetaExists; // separate meta-file directory exists
126 CFRef<CFURLRef> mMainExecutableURL; // chosen main executable URL
127 bool mInstallerPackage; // is an installer (not executable) bundle
128 bool mAppLike; // is some form of app
129 string mFormat; // format description string
130 RefPointer<DiskRep> mExecRep; // DiskRep for main executable file
131 bool mComponentsFromExec; // components are drawn from main executable diskrep
132 bool mComponentsFromExecValid; // mComponentsFromExec is valid (tri-state)
133 std::set<CodeDirectory::SpecialSlot> mUsedComponents; // remember what components we've retrieved
134 std::set<OSStatus> mStrictErrors; // strict validation errors encountered
135 bool forcePlatform; // treat as anchor apple on apple internal
136 };
137
138
139 //
140 // Writers
141 //
142 //
143 class BundleDiskRep::Writer : public DiskRep::Writer {
144 friend class BundleDiskRep;
145 public:
146 Writer(BundleDiskRep *r);
147
148 void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
149 void remove();
150 void flush();
151
152 protected:
153 DiskRep *execRep() { return rep->mExecRep; }
154 void remove(CodeDirectory::SpecialSlot slot);
155 void purgeMetaDirectory();
156
157 protected:
158 RefPointer<BundleDiskRep> rep;
159 RefPointer<DiskRep::Writer> execWriter;
160 bool mMadeMetaDirectory;
161 std::set<std::string> mWrittenFiles;
162 };
163
164
165 } // end namespace CodeSigning
166 } // end namespace Security
167
168 #endif // !_H_BUNDLEDISKREP