]>
git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/diskrep.h
001d1a559bab21ad26301e197ee2b35f86e603cb
2 * Copyright (c) 2006-2007 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 // diskrep - disk representations of code
31 #include "codedirectory.h"
32 #include "requirement.h"
33 #include "macho++.h" // for class Architecture
34 #include <security_utilities/refcount.h>
35 #include <security_utilities/superblob.h>
36 #include <CoreFoundation/CFData.h>
39 namespace CodeSigning
{
43 // DiskRep is an abstract interface to code somewhere located by
44 // a file system path. It presents the ability to read and write
45 // Code Signing-related information about such code without exposing
46 // the details of the storage locations or formats.
48 class DiskRep
: public RefCount
{
52 virtual DiskRep
*base();
53 virtual CFDataRef
component(CodeDirectory::SpecialSlot slot
) = 0; // fetch component
54 virtual std::string
mainExecutablePath() = 0; // path to main executable
55 virtual CFURLRef
canonicalPath() = 0; // path to whole code
56 virtual std::string
recommendedIdentifier() = 0; // default identifier
57 virtual std::string
resourcesRootPath(); // resource directory if any
58 virtual CFDictionaryRef
defaultResourceRules(); // default resource rules
59 virtual const Requirements
*defaultRequirements(const Architecture
*arch
); // default internal requirements
60 virtual Universal
*mainExecutableImage(); // binary if Mach-O/Universal
61 virtual size_t pageSize(); // default main executable page size
62 virtual size_t signingBase(); // start offset of signed area in main executable
63 virtual size_t signingLimit() = 0; // size of signed area in main executable
64 virtual std::string
format() = 0; // human-readable type string
65 virtual CFArrayRef
modifiedFiles(); // list of files modified by signing
66 virtual UnixPlusPlus::FileDesc
&fd() = 0; // a cached fd for main executable file
67 virtual void flush(); // flush caches (refetch as needed)
69 bool mainExecutableIsMachO() { return mainExecutableImage() != NULL
; }
72 CFDataRef
codeDirectory() { return component(cdCodeDirectorySlot
); }
73 CFDataRef
signature() { return component(cdSignatureSlot
); }
77 virtual Writer
*writer();
80 static DiskRep
*bestGuess(const char *path
); // canonical heuristic, any path
81 static DiskRep
*bestFileGuess(const char *path
); // canonical heuristic, single file only
83 static DiskRep
*bestGuess(const std::string
&path
) { return bestGuess(path
.c_str()); }
84 static DiskRep
*bestFileGuess(const std::string
&path
) { return bestFileGuess(path
.c_str()); }
88 static const size_t segmentedPageSize
= 4096; // default page size for system-paged signatures
89 static const size_t monolithicPageSize
= 0; // default page size for non-Mach-O executables
94 // Write-access objects.
95 // At this layer they are quite abstract, carrying just the functionality needed
96 // for the signing machinery to place data wherever it should go. Each DiskRep subclass
97 // that supports writing signing data to a place inside the code needs to implement
98 // a subclass of Writer and return an instance in the DiskRep::writer() method when asked.
100 class DiskRep::Writer
: public RefCount
{
102 Writer(uint32_t attrs
= 0);
104 virtual void component(CodeDirectory::SpecialSlot slot
, CFDataRef data
) = 0;
105 virtual uint32_t attributes() const;
106 virtual void flush();
108 bool attribute(uint32_t attr
) const { return mAttributes
& attr
; }
110 void signature(CFDataRef data
) { component(cdSignatureSlot
, data
); }
111 void codeDirectory(const CodeDirectory
*cd
)
112 { component(cdCodeDirectorySlot
, CFTempData(cd
->data(), cd
->length())); }
116 uint32_t mAttributes
;
120 // Writer attributes. Defaults should be off-bits.
123 writerLastResort
= 0x0001, // prefers not to store attributes itself
124 writerNoGlobal
= 0x0002, // has only per-architecture storage
128 } // end namespace CodeSigning
129 } // end namespace Security
131 #endif // !_H_DISKREP