]> git.saurik.com Git - apple/securityd.git/blob - src/codesigdb.h
securityd-27887.tar.gz
[apple/securityd.git] / src / codesigdb.h
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, 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 //
26 // codesigdb - code-hash equivalence database
27 //
28 #ifndef _H_CODESIGDB
29 #define _H_CODESIGDB
30
31 #include <security_cdsa_utilities/db++.h>
32 #include <security_cdsa_client/osxsigner.h>
33
34
35 class Process;
36 class CodeSignatures;
37
38
39 //
40 // A CodeSignaturse object represents a database of code-signature equivalencies
41 // as (previously) expressed by a user and/or the system.
42 // You'll usually only need one of these.
43 //
44 class CodeSignatures {
45 public:
46 //
47 // Identity is an abstract class modeling a code-identity in the database.
48 // It can represent either an existing or latent code-hash link.
49 // Subclass must provide path and hash source functions.
50 //
51 class Identity {
52 friend class CodeSignatures;
53 public:
54 Identity();
55 virtual ~Identity();
56
57 operator bool () const { return mState == valid; }
58 std::string path() { return getPath(); }
59 std::string name() { return canonicalName(path()); }
60 std::string trustedName() const { return mName; }
61
62 static std::string canonicalName(const std::string &path);
63
64 IFDUMP(void debugDump(const char *how = NULL) const);
65
66 virtual std::string getPath() const = 0;
67 virtual const CssmData getHash(CodeSigning::OSXSigner &signer) const = 0;
68
69 private:
70 enum { untried, valid, invalid } mState;
71 std::string mName; // link db value (canonical name linked to)
72 };
73
74 public:
75 CodeSignatures(const char *path);
76 ~CodeSignatures();
77
78 void open(const char *path);
79
80 public:
81 bool find(Identity &id, uid_t user);
82
83 void makeLink(Identity &id, const std::string &ident, bool forUser = false, uid_t user = 0);
84 void makeApplication(const std::string &name, const std::string &path);
85
86 void addLink(const CssmData &oldHash, const CssmData &newHash,
87 const char *name, bool forSystem);
88 void removeLink(const CssmData &hash, const char *name, bool forSystem);
89
90 IFDUMP(void debugDump(const char *how = NULL) const);
91
92 public:
93 bool verify(Process &process,
94 const CodeSigning::Signature *trustedSignature, const CssmData *comment);
95
96 private:
97 UnixPlusPlus::UnixDb mDb;
98 CodeSigning::OSXSigner mSigner;
99
100 // lock hierarchy: mUILock first, then mDatabaseLock, no back-off
101 Mutex mDatabaseLock; // controls mDb access
102 Mutex mUILock; // serializes user interaction
103 };
104
105
106
107 #endif //_H_CODESIGDB