]>
git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/diskrep.h
4442320db2c382608d7d583519037dfa5e345e7f
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 "resources.h"
34 #include "macho++.h" // for class Architecture
35 #include <security_utilities/refcount.h>
36 #include <security_utilities/superblob.h>
37 #include <CoreFoundation/CFData.h>
40 namespace CodeSigning
{
44 // DiskRep is an abstract interface to code somewhere located by
45 // a file system path. It presents the ability to read and write
46 // Code Signing-related information about such code without exposing
47 // the details of the storage locations or formats.
49 class DiskRep
: public RefCount
{
53 virtual DiskRep
*base();
54 virtual CFDataRef
component(CodeDirectory::SpecialSlot slot
) = 0; // fetch component
55 virtual std::string
mainExecutablePath() = 0; // path to main executable
56 virtual CFURLRef
canonicalPath() = 0; // path to whole code
57 virtual std::string
recommendedIdentifier() = 0; // default identifier
58 virtual std::string
resourcesRootPath(); // resource directory if any
59 virtual CFDictionaryRef
defaultResourceRules(); // default resource rules
60 virtual void adjustResources(ResourceBuilder
&builder
); // adjust resource rule set
61 virtual const Requirements
*defaultRequirements(const Architecture
*arch
); // default internal requirements
62 virtual Universal
*mainExecutableImage(); // binary if Mach-O/Universal
63 virtual size_t pageSize(); // default main executable page size
64 virtual size_t signingBase(); // start offset of signed area in main executable
65 virtual size_t signingLimit() = 0; // size of signed area in main executable
66 virtual std::string
format() = 0; // human-readable type string
67 virtual CFArrayRef
modifiedFiles(); // list of files modified by signing
68 virtual UnixPlusPlus::FileDesc
&fd() = 0; // a cached fd for main executable file
69 virtual void flush(); // flush caches (refetch as needed)
71 bool mainExecutableIsMachO() { return mainExecutableImage() != NULL
; }
74 CFDataRef
codeDirectory() { return component(cdCodeDirectorySlot
); }
75 CFDataRef
signature() { return component(cdSignatureSlot
); }
79 virtual Writer
*writer();
82 static DiskRep
*bestGuess(const char *path
); // canonical heuristic, any path
83 static DiskRep
*bestFileGuess(const char *path
); // canonical heuristic, single file only
85 static DiskRep
*bestGuess(const std::string
&path
) { return bestGuess(path
.c_str()); }
86 static DiskRep
*bestFileGuess(const std::string
&path
) { return bestFileGuess(path
.c_str()); }
90 static const size_t segmentedPageSize
= 4096; // default page size for system-paged signatures
91 static const size_t monolithicPageSize
= 0; // default page size for non-Mach-O executables
96 // Write-access objects.
97 // At this layer they are quite abstract, carrying just the functionality needed
98 // for the signing machinery to place data wherever it should go. Each DiskRep subclass
99 // that supports writing signing data to a place inside the code needs to implement
100 // a subclass of Writer and return an instance in the DiskRep::writer() method when asked.
102 class DiskRep::Writer
: public RefCount
{
104 Writer(uint32_t attrs
= 0);
106 virtual void component(CodeDirectory::SpecialSlot slot
, CFDataRef data
) = 0;
107 virtual uint32_t attributes() const;
108 virtual void flush();
110 bool attribute(uint32_t attr
) const { return mAttributes
& attr
; }
112 void signature(CFDataRef data
) { component(cdSignatureSlot
, data
); }
113 void codeDirectory(const CodeDirectory
*cd
)
114 { component(cdCodeDirectorySlot
, CFTempData(cd
->data(), cd
->length())); }
118 uint32_t mAttributes
;
122 // Writer attributes. Defaults should be off-bits.
125 writerLastResort
= 0x0001, // prefers not to store attributes itself
126 writerNoGlobal
= 0x0002, // has only per-architecture storage
130 } // end namespace CodeSigning
131 } // end namespace Security
133 #endif // !_H_DISKREP