]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/cfmdiskrep.h
23d3a8ad0a2b51ad2ec9cbcd6cb92b3e01043247
[apple/libsecurity_codesigning.git] / lib / cfmdiskrep.h
1 /*
2 * Copyright (c) 2007 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 // cfmdiskrep - single-file CFM (PEF) executable disk representation
26 //
27 #ifndef _H_CFMDISKREP
28 #define _H_CFMDISKREP
29
30 #include "singlediskrep.h"
31 #include "sigblob.h"
32 #include "signerutils.h"
33 #include <security_utilities/unix++.h>
34 #include <security_utilities/cfutilities.h>
35
36 namespace Security {
37 namespace CodeSigning {
38
39
40 //
41 // A CFMDiskRep represents a single code file on disk containing a CFM (PEF)
42 // binary. It is considered self-contained, and does not depend on any other
43 // files in the system (even if it may be part of a larger bundle etc.)
44 //
45 // CFM is considered a legacy format that is not generated by Apple, but still
46 // supported for backward compatibility. This DiskRep supports writing signing
47 // data into the executable, using a simple back-of-file frame. It does not
48 // support embedded Info.plists or any other fancy stuff.
49 //
50 // This DiskRep does not support resource sealing.
51 //
52 class CFMDiskRep : public SingleDiskRep {
53 public:
54 CFMDiskRep(const char *path);
55 ~CFMDiskRep();
56
57 CFDataRef component(CodeDirectory::SpecialSlot slot);
58 const Requirements *defaultRequirements(const Architecture *arch);
59 size_t pageSize();
60 size_t signingLimit();
61 std::string format();
62 void flush();
63
64 static bool candidate(UnixPlusPlus::FileDesc &fd); // could this reasonably be a CFM code?
65
66 public:
67 //
68 // Signing sticks this structure at the very end of the file
69 //
70 struct Sentinel {
71 Endian<uint32_t> magic; // EmbeddedSignatureBlob::magic()
72 Endian<uint32_t> offset; // file absolute offset of EmbeddedSignatureBlob
73 };
74
75 public:
76 DiskRep::Writer *writer();
77 class Writer;
78 friend class Writer;
79
80 protected:
81 void readSigningData(); // read and cache signing data
82
83 private:
84 bool mTriedRead; // tried to get signing data
85 size_t mSigningOffset; // where we found the signing data
86 EmbeddedSignatureBlob *mSigningData; // cached signing data
87 };
88
89
90 //
91 // The write side of a FileDiskRep
92 //
93 class CFMDiskRep::Writer : public DiskRep::Writer, private EmbeddedSignatureBlob::Maker {
94 friend class CFMDiskRep;
95 public:
96 Writer(CFMDiskRep *r) : rep(r), mSigningData(NULL) { }
97 ~Writer();
98
99 void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
100 virtual void flush();
101
102 protected:
103 RefPointer<CFMDiskRep> rep;
104 EmbeddedSignatureBlob *mSigningData;
105 };
106
107
108 } // end namespace CodeSigning
109 } // end namespace Security
110
111 #endif // !_H_CFMDISKREP