]> git.saurik.com Git - apple/security.git/blame - OSX/libsecurity_codesigning/lib/bundlediskrep.h
Security-58286.240.4.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
79b9da22
A
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
b1ab9ed8
A
41namespace Security {
42namespace CodeSigning {
43
44
45#define BUNDLEDISKREP_DIRECTORY "_CodeSignature"
427c49bc 46#define CODERESOURCES_LINK "CodeResources"
b1ab9ed8
A
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//
58class BundleDiskRep : public DiskRep {
59public:
60 BundleDiskRep(const char *path, const Context *ctx = NULL);
61 BundleDiskRep(CFBundleRef ref, const Context *ctx = NULL);
427c49bc 62 ~BundleDiskRep();
b1ab9ed8
A
63
64 CFDataRef component(CodeDirectory::SpecialSlot slot);
65 CFDataRef identification();
66 std::string mainExecutablePath();
80e23899 67 CFURLRef copyCanonicalPath();
b1ab9ed8 68 std::string resourcesRootPath();
80e23899 69 std::string resourcesRelativePath();
b1ab9ed8
A
70 void adjustResources(ResourceBuilder &builder);
71 Universal *mainExecutableImage();
e3d460c9 72 void prepareForSigning(SigningContext &context);
b1ab9ed8
A
73 size_t signingBase();
74 size_t signingLimit();
866f8763
A
75 size_t execSegBase(const Architecture *arch);
76 size_t execSegLimit(const Architecture *arch);
b1ab9ed8
A
77 std::string format();
78 CFArrayRef modifiedFiles();
79 UnixPlusPlus::FileDesc &fd();
80 void flush();
fa7225c8
A
81 CFDictionaryRef diskRepInformation();
82
b1ab9ed8
A
83 std::string recommendedIdentifier(const SigningContext &ctx);
84 CFDictionaryRef defaultResourceRules(const SigningContext &ctx);
85 const Requirements *defaultRequirements(const Architecture *arch, const SigningContext &ctx);
86 size_t pageSize(const SigningContext &ctx);
87
e3d460c9 88 void strictValidate(const CodeDirectory* cd, const ToleratedErrors& tolerated, SecCSFlags flags);
80e23899
A
89 CFArrayRef allowedResourceOmissions();
90
79b9da22
A
91 void registerStapledTicket();
92
93 bool appleInternalForcePlatform() const {return forcePlatform;};
94
b1ab9ed8 95 CFBundleRef bundle() const { return mBundle; }
d8f41ccd 96
b1ab9ed8
A
97public:
98 Writer *writer();
99 class Writer;
100 friend class Writer;
101
102protected:
103 std::string metaPath(const char *name);
b1ab9ed8 104 void createMeta(); // (try to) create the meta-file directory
fa7225c8
A
105 CFDataRef metaData(const char *name);
106 CFDataRef metaData(CodeDirectory::SpecialSlot slot);
b1ab9ed8
A
107
108private:
109 void setup(const Context *ctx); // shared init
110 void checkModifiedFile(CFMutableArrayRef files, CodeDirectory::SpecialSlot slot);
80e23899
A
111 CFDataRef loadRegularFile(CFURLRef url);
112 void recordStrictError(OSStatus error);
fa7225c8 113 void validateMetaDirectory(const CodeDirectory* cd);
80e23899 114 void validateFrameworkRoot(std::string root);
fa7225c8
A
115 void checkPlainFile(UnixPlusPlus::FileDesc fd, const std::string& path);
116 void checkForks(UnixPlusPlus::FileDesc fd);
d87e1158 117 void checkMoved(CFURLRef oldPath, CFURLRef newPath);
fa7225c8 118 void componentFromExec(bool fromExec);
b1ab9ed8
A
119
120private:
121 CFRef<CFBundleRef> mBundle;
122 std::string mMetaPath; // path to directory containing signing files
123 bool mMetaExists; // separate meta-file directory exists
124 CFRef<CFURLRef> mMainExecutableURL; // chosen main executable URL
125 bool mInstallerPackage; // is an installer (not executable) bundle
e3d460c9 126 bool mAppLike; // is some form of app
b1ab9ed8
A
127 string mFormat; // format description string
128 RefPointer<DiskRep> mExecRep; // DiskRep for main executable file
fa7225c8
A
129 bool mComponentsFromExec; // components are drawn from main executable diskrep
130 bool mComponentsFromExecValid; // mComponentsFromExec is valid (tri-state)
131 std::set<CodeDirectory::SpecialSlot> mUsedComponents; // remember what components we've retrieved
80e23899 132 std::set<OSStatus> mStrictErrors; // strict validation errors encountered
79b9da22 133 bool forcePlatform; // treat as anchor apple on apple internal
b1ab9ed8
A
134};
135
136
137//
138// Writers
139//
140//
141class BundleDiskRep::Writer : public DiskRep::Writer {
142 friend class BundleDiskRep;
143public:
144 Writer(BundleDiskRep *r);
145
146 void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
147 void remove();
148 void flush();
149
150protected:
151 DiskRep *execRep() { return rep->mExecRep; }
152 void remove(CodeDirectory::SpecialSlot slot);
fa7225c8 153 void purgeMetaDirectory();
b1ab9ed8
A
154
155protected:
156 RefPointer<BundleDiskRep> rep;
157 RefPointer<DiskRep::Writer> execWriter;
158 bool mMadeMetaDirectory;
fa7225c8 159 std::set<std::string> mWrittenFiles;
b1ab9ed8
A
160};
161
162
163} // end namespace CodeSigning
164} // end namespace Security
165
166#endif // !_H_BUNDLEDISKREP