]> git.saurik.com Git - apple/securityd.git/blob - src/localdatabase.h
74553a47961df3a694fa7b38ba868b6960e760c9
[apple/securityd.git] / src / localdatabase.h
1 /*
2 * Copyright (c) 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 // localdatabase - locally implemented database using internal CSP cryptography
29 //
30 // A LocalDatabase manages keys with a locally resident AppleCSP.
31 // This is an abstract class useful for subclassing.
32 //
33 #ifndef _H_LOCALDATABASE
34 #define _H_LOCALDATABASE
35
36 #include "database.h"
37
38 class LocalKey;
39
40
41 //
42 // A Database object represents an Apple CSP/DL open database (DL/DB) object.
43 // It maintains its protected semantic state (including keys) and provides controlled
44 // access.
45 //
46 class LocalDatabase : public Database {
47 public:
48 LocalDatabase(Process &proc);
49
50 public:
51 //void releaseKey(Key &key);
52 CSSM_KEY_SIZE queryKeySize(Key &key);
53
54 // service calls
55 void generateSignature(const Context &context, Key &key, CSSM_ALGORITHMS signOnlyAlgorithm,
56 const CssmData &data, CssmData &signature);
57 void verifySignature(const Context &context, Key &key, CSSM_ALGORITHMS verifyOnlyAlgorithm,
58 const CssmData &data, const CssmData &signature);
59 void generateMac(const Context &context, Key &key,
60 const CssmData &data, CssmData &mac);
61 void verifyMac(const Context &context, Key &key,
62 const CssmData &data, const CssmData &mac);
63
64 void encrypt(const Context &context, Key &key, const CssmData &clear, CssmData &cipher);
65 void decrypt(const Context &context, Key &key, const CssmData &cipher, CssmData &clear);
66
67 void generateKey(const Context &context,
68 const AccessCredentials *cred, const AclEntryPrototype *owner,
69 uint32 usage, uint32 attrs, RefPointer<Key> &newKey);
70 void generateKey(const Context &context,
71 const AccessCredentials *cred, const AclEntryPrototype *owner,
72 uint32 pubUsage, uint32 pubAttrs, uint32 privUsage, uint32 privAttrs,
73 RefPointer<Key> &publicKey, RefPointer<Key> &privateKey);
74 RefPointer<Key> deriveKey(const Context &context, Key *key,
75 const AccessCredentials *cred, const AclEntryPrototype *owner,
76 CssmData *param, uint32 usage, uint32 attrs);
77
78 void wrapKey(const Context &context, Key *key,
79 Key &keyToBeWrapped, const AccessCredentials *cred,
80 const CssmData &descriptiveData, CssmKey &wrappedKey);
81 RefPointer<Key> unwrapKey(const Context &context, Key *key,
82 const AccessCredentials *cred, const AclEntryPrototype *owner,
83 uint32 usage, uint32 attrs, const CssmKey wrappedKey,
84 Key *publicKey, CssmData *descriptiveData);
85
86 uint32 getOutputSize(const Context &context, Key &key, uint32 inputSize, bool encrypt = true);
87
88 protected:
89 virtual RefPointer<Key> makeKey(const CssmKey &newKey, uint32 moreAttributes,
90 const AclEntryPrototype *owner) = 0;
91
92 public:
93 // encoding/decoding databases
94 void authenticate(const AccessCredentials *cred);
95 };
96
97 #endif //_H_LOCALDATABASE