]> git.saurik.com Git - apple/securityd.git/blob - src/codesigdb.h
47a3173f11ad54d6088ee02105b89d10f6b7edbc
[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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26
27 //
28 // codesigdb - code-hash equivalence database
29 //
30 #ifndef _H_CODESIGDB
31 #define _H_CODESIGDB
32
33 #include <security_cdsa_utilities/db++.h>
34 #include <security_cdsa_client/osxsigner.h>
35
36
37 class Process;
38 class CodeSignatures;
39
40
41 //
42 // A CodeSignaturse object represents a database of code-signature equivalencies
43 // as (previously) expressed by a user and/or the system.
44 // You'll usually only need one of these.
45 //
46 class CodeSignatures {
47 public:
48 //
49 // Identity is an abstract class modeling a code-identity in the database.
50 // It can represent either an existing or latent code-hash link.
51 // Subclass must provide path and hash source functions.
52 //
53 class Identity {
54 friend class CodeSignatures;
55 public:
56 Identity();
57 virtual ~Identity();
58
59 operator bool () const { return mState == valid; }
60 std::string path() { return getPath(); }
61 std::string name() { return canonicalName(path()); }
62 std::string trustedName() const { return mName; }
63
64 static std::string canonicalName(const std::string &path);
65
66 IFDUMP(void debugDump(const char *how = NULL) const);
67
68 virtual std::string getPath() const = 0;
69 virtual const CssmData getHash(CodeSigning::OSXSigner &signer) const = 0;
70
71 private:
72 enum { untried, valid, invalid } mState;
73 std::string mName; // link db value (canonical name linked to)
74 };
75
76 public:
77 CodeSignatures(const char *path);
78 ~CodeSignatures();
79
80 void open(const char *path);
81
82 public:
83 bool find(Identity &id, uid_t user);
84
85 void makeLink(Identity &id, const std::string &ident, bool forUser = false, uid_t user = 0);
86 void makeApplication(const std::string &name, const std::string &path);
87
88 void addLink(const CssmData &oldHash, const CssmData &newHash,
89 const char *name, bool forSystem);
90 void removeLink(const CssmData &hash, const char *name, bool forSystem);
91
92 IFDUMP(void debugDump(const char *how = NULL) const);
93
94 public:
95 bool verify(Process &process,
96 const CodeSigning::Signature *trustedSignature, const CssmData *comment);
97
98 private:
99 UnixPlusPlus::UnixDb mDb;
100 CodeSigning::OSXSigner mSigner;
101
102 // lock hierarchy: mUILock first, then mDatabaseLock, no back-off
103 Mutex mDatabaseLock; // controls mDb access
104 Mutex mUILock; // serializes user interaction
105 };
106
107
108
109 #endif //_H_CODESIGDB