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