]>
Commit | Line | Data |
---|---|---|
7d31e928 A |
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> | |
d1c1ab47 | 33 | #include <security_utilities/macho++.h> |
7d31e928 A |
34 | |
35 | namespace Security { | |
36 | namespace CodeSigning { | |
37 | ||
38 | ||
39 | // | |
f60086fc A |
40 | // MachORep is a DiskRep class that supports code signatures |
41 | // directly embedded in Mach-O binary files. | |
7d31e928 A |
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: | |
d1c1ab47 | 50 | MachORep(const char *path, const Context *ctx = NULL); |
7d31e928 A |
51 | virtual ~MachORep(); |
52 | ||
53 | CFDataRef component(CodeDirectory::SpecialSlot slot); | |
d1c1ab47 | 54 | CFDataRef identification(); |
7d31e928 | 55 | Universal *mainExecutableImage(); |
7d31e928 A |
56 | size_t signingBase(); |
57 | std::string format(); | |
58 | ||
f60086fc A |
59 | std::string recommendedIdentifier(const SigningContext &ctx); |
60 | const Requirements *defaultRequirements(const Architecture *arch, const SigningContext &ctx); | |
61 | size_t pageSize(const SigningContext &ctx); | |
62 | ||
7d31e928 A |
63 | void flush(); // flush cache |
64 | ||
d1c1ab47 A |
65 | static bool candidate(UnixPlusPlus::FileDesc &fd); |
66 | ||
67 | public: | |
68 | static CFDataRef identificationFor(MachO *macho); | |
7d31e928 A |
69 | |
70 | public: | |
71 | DiskRep::Writer *writer(); | |
72 | class Writer; | |
73 | friend class Writer; | |
74 | ||
75 | protected: | |
76 | CFDataRef embeddedComponent(CodeDirectory::SpecialSlot slot); | |
77 | CFDataRef infoPlist(); | |
f60086fc | 78 | Requirement *libraryRequirements(const Architecture *arch, const SigningContext &ctx); |
7d31e928 A |
79 | |
80 | private: | |
81 | Universal *mExecutable; // cached Mach-O/Universal reference to mainExecutablePath() | |
82 | EmbeddedSignatureBlob *mSigningData; // cached signing data from current architecture | |
83 | }; | |
84 | ||
85 | ||
86 | // | |
f60086fc A |
87 | // The write side of a MachORep. |
88 | // This is purposely dysfunctional; Mach-O signatures are written | |
89 | // by code in signerutils, not by DiskRep::Writers. | |
7d31e928 A |
90 | // |
91 | class MachORep::Writer : public SingleDiskRep::Writer { | |
92 | friend class FileDiskRep; | |
93 | public: | |
94 | Writer(MachORep *r) : SingleDiskRep::Writer(r, writerNoGlobal) { } | |
95 | void component(CodeDirectory::SpecialSlot slot, CFDataRef data); | |
96 | }; | |
97 | ||
98 | ||
99 | } // end namespace CodeSigning | |
100 | } // end namespace Security | |
101 | ||
102 | #endif // !_H_MACHOREP |