]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/machorep.h
4b05cf86ac7eb20570ebb38a27525d3a87020f18
[apple/libsecurity_codesigning.git] / lib / machorep.h
1 /*
2 * Copyright (c) 2006 Apple Computer, 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 // machorep - DiskRep mix-in for handling Mach-O main executables
26 //
27 #ifndef _H_MACHOREP
28 #define _H_MACHOREP
29
30 #include "singlediskrep.h"
31 #include "sigblob.h"
32 #include <security_utilities/unix++.h>
33 #include <security_codesigning/macho++.h>
34
35 namespace Security {
36 namespace CodeSigning {
37
38
39 //
40 // MachORep is a mix-in class that supports reading
41 // Code Signing resources from the main executable.
42 //
43 // It does not have write support (for writing signatures);
44 // writing multi-architecture binaries is complicated enough
45 // that it's driven directly from the signing code, with no
46 // abstractions to get in the way.
47 //
48 class MachORep : public SingleDiskRep {
49 public:
50 MachORep(const char *path);
51 virtual ~MachORep();
52
53 CFDataRef component(CodeDirectory::SpecialSlot slot);
54 std::string recommendedIdentifier();
55 const Requirements *defaultRequirements(const Architecture *arch);
56 Universal *mainExecutableImage();
57 size_t pageSize();
58 size_t signingBase();
59 std::string format();
60
61 void flush(); // flush cache
62
63 static bool candidiate(UnixPlusPlus::FileDesc &fd);
64
65 public:
66 DiskRep::Writer *writer();
67 class Writer;
68 friend class Writer;
69
70 protected:
71 CFDataRef embeddedComponent(CodeDirectory::SpecialSlot slot);
72 CFDataRef infoPlist();
73
74 private:
75 Universal *mExecutable; // cached Mach-O/Universal reference to mainExecutablePath()
76 EmbeddedSignatureBlob *mSigningData; // cached signing data from current architecture
77 };
78
79
80 //
81 // The write side of a FileDiskRep
82 //
83 class MachORep::Writer : public SingleDiskRep::Writer {
84 friend class FileDiskRep;
85 public:
86 Writer(MachORep *r) : SingleDiskRep::Writer(r, writerNoGlobal) { }
87 void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
88 };
89
90
91 } // end namespace CodeSigning
92 } // end namespace Security
93
94 #endif // !_H_MACHOREP