]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/osxsigning.h
Security-29.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / osxsigning.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // osxsigning - MacOS X's standard signable objects.
21 //
22 #ifndef _OSXSIGNING
23 #define _OSXSIGNING
24
25 #include <Security/codesigning.h>
26 #include <Security/cspclient.h>
27 #include <limits.h>
28 #include <string>
29 #include <CoreFoundation/CFBundle.h>
30
31 #ifdef _CPP_OSXSIGNING
32 #pragma export on
33 #endif
34
35
36 namespace Security
37 {
38
39 namespace CodeSigning
40 {
41
42 //
43 // A Signable with OS X support calls added
44 //
45 class OSXCode : public Signable {
46 public:
47 // encoding and decoding as a UTF-8 string
48 virtual string encode() const = 0;
49 static OSXCode *decode(const char *extForm);
50
51 public:
52 // creating OSXCode objects
53 static OSXCode *main();
54 static OSXCode *at(const char *path);
55
56 public:
57 // produce the best approximation of a path that, when handed to at(),
58 // will yield an OSXCode that's the most like this one
59 virtual string canonicalPath() const = 0;
60
61 protected:
62 OSXCode() { } // nonpublic
63 static void scanFile(const char *pathname, Signer::State &state); // scan an entire file
64 static string getPath(CFURLRef url);
65 };
66
67
68 //
69 // A simple executable tool.
70 //
71 class ExecutableTool : public OSXCode {
72 public:
73 ExecutableTool(const char *path) : mPath(path) { }
74 string encode() const;
75
76 string path() const { return mPath; }
77 string canonicalPath() const;
78
79 protected:
80 void scanContents(Signer::State &state) const;
81
82 private:
83 string mPath; // UTF8 pathname to executable
84 };
85
86
87 //
88 // A generic bundle
89 //
90 class GenericBundle : public OSXCode {
91 public:
92 GenericBundle(const char *path);
93 ~GenericBundle();
94
95 string encode() const;
96
97 string canonicalPath() const;
98 string path() const { return mPath; }
99 string executablePath() const { return getPath(CFBundleCopyExecutableURL(mBundle)); }
100
101 virtual void *lookupSymbol(const char *name);
102
103 protected:
104 void scanContents(Signer::State &state) const;
105
106 protected:
107 string mPath; // UTF8 path to bundle directory
108 CFBundleRef mBundle; // CF-style bundle object
109 };
110
111 class ApplicationBundle : public GenericBundle {
112 public:
113 ApplicationBundle(const char *pathname) : GenericBundle(pathname) { }
114 };
115
116 class LoadableBundle : public GenericBundle {
117 public:
118 LoadableBundle(const char *pathname) : GenericBundle(pathname) { }
119
120 virtual bool isLoaded() const;
121 virtual void load();
122 virtual void unload();
123 };
124
125
126 } // end namespace CodeSigning
127
128 } // end namespace Security
129
130 #ifdef _CPP_OSXSIGNING
131 #pragma export off
132 #endif
133
134
135 #endif //_OSXSIGNING