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