]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/cfmdiskrep.h
libsecurity_codesigning-55037.15.tar.gz
[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 size_t signingLimit();
59 std::string format();
60 void flush();
61
62 const Requirements *defaultRequirements(const Architecture *arch, const SigningContext &ctx);
63 size_t pageSize(const SigningContext &ctx);
64
65 static bool candidate(UnixPlusPlus::FileDesc &fd); // could this reasonably be a CFM code?
66
67 public:
68 //
69 // Signing sticks this structure at the very end of the file
70 //
71 struct Sentinel {
72 Endian<uint32_t> magic; // EmbeddedSignatureBlob::magic()
73 Endian<uint32_t> offset; // file absolute offset of EmbeddedSignatureBlob
74 };
75
76 public:
77 DiskRep::Writer *writer();
78 class Writer;
79 friend class Writer;
80
81 protected:
82 void readSigningData(); // read and cache signing data
83
84 private:
85 bool mTriedRead; // tried to get signing data
86 size_t mSigningOffset; // where we found the signing data
87 EmbeddedSignatureBlob *mSigningData; // cached signing data
88 };
89
90
91 //
92 // The write side of a FileDiskRep
93 //
94 class CFMDiskRep::Writer : public DiskRep::Writer, private EmbeddedSignatureBlob::Maker {
95 friend class CFMDiskRep;
96 public:
97 Writer(CFMDiskRep *r) : rep(r), mSigningData(NULL) { }
98 ~Writer();
99
100 void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
101 virtual void flush();
102
103 protected:
104 RefPointer<CFMDiskRep> rep;
105 EmbeddedSignatureBlob *mSigningData;
106 };
107
108
109 } // end namespace CodeSigning
110 } // end namespace Security
111
112 #endif // !_H_CFMDISKREP