2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
28 // tokendatabase - software database container implementation.
30 #include "tokendatabase.h"
35 class TokenKey
: public Key
{
41 // Construct a TokenDatabase
43 TokenDatabase::TokenDatabase(Process
&proc
)
46 proc
.addReference(*this);
51 // Basic Database virtual implementations
53 TokenDbCommon
&TokenDatabase::common() const
55 return parent
<TokenDbCommon
>();
58 const char *TokenDatabase::dbName() const
60 return "<<whatever>>";
64 static inline TokenKey
&myKey(Key
&key
)
66 return safer_cast
<TokenKey
&>(key
);
75 CSSM_KEY_SIZE
TokenDatabase::queryKeySize(Key
&key
)
77 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
82 // Signatures and MACs
84 void TokenDatabase::generateSignature(const Context
&context
, Key
&key
,
85 CSSM_ALGORITHMS signOnlyAlgorithm
, const CssmData
&data
, CssmData
&signature
)
87 key
.validate(CSSM_ACL_AUTHORIZATION_SIGN
, context
);
88 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
91 void TokenDatabase::verifySignature(const Context
&context
, Key
&key
,
92 CSSM_ALGORITHMS verifyOnlyAlgorithm
, const CssmData
&data
, const CssmData
&signature
)
94 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
97 void TokenDatabase::generateMac(const Context
&context
, Key
&key
,
98 const CssmData
&data
, CssmData
&mac
)
100 key
.validate(CSSM_ACL_AUTHORIZATION_MAC
, context
);
101 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
104 void TokenDatabase::verifyMac(const Context
&context
, Key
&key
,
105 const CssmData
&data
, const CssmData
&mac
)
107 key
.validate(CSSM_ACL_AUTHORIZATION_MAC
, context
);
108 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
113 // Encryption/decryption
115 void TokenDatabase::encrypt(const Context
&context
, Key
&key
,
116 const CssmData
&clear
, CssmData
&cipher
)
118 key
.validate(CSSM_ACL_AUTHORIZATION_ENCRYPT
, context
);
119 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
122 void TokenDatabase::decrypt(const Context
&context
, Key
&key
,
123 const CssmData
&cipher
, CssmData
&clear
)
125 key
.validate(CSSM_ACL_AUTHORIZATION_DECRYPT
, context
);
126 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
131 // Key generation and derivation.
132 // Currently, we consider symmetric key generation to be fast, but
133 // asymmetric key generation to be (potentially) slow.
135 void TokenDatabase::generateKey(const Context
&context
,
136 const AccessCredentials
*cred
, const AclEntryPrototype
*owner
,
137 uint32 usage
, uint32 attrs
, RefPointer
<Key
> &newKey
)
139 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
142 void TokenDatabase::generateKey(const Context
&context
,
143 const AccessCredentials
*cred
, const AclEntryPrototype
*owner
,
144 uint32 pubUsage
, uint32 pubAttrs
, uint32 privUsage
, uint32 privAttrs
,
145 RefPointer
<Key
> &publicKey
, RefPointer
<Key
> &privateKey
)
147 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
150 RefPointer
<Key
> TokenDatabase::deriveKey(const Context
&context
, Key
*baseKey
,
151 const AccessCredentials
*cred
, const AclEntryPrototype
*owner
,
152 CssmData
*param
, uint32 usage
, uint32 attrs
)
154 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
159 // Key wrapping and unwrapping.
160 // Note that the key argument (the key in the context) is optional because of the special
161 // case of "cleartext" (null algorithm) wrapping for import/export.
164 void TokenDatabase::wrapKey(const Context
&context
, Key
*key
,
165 Key
&keyToBeWrapped
, const AccessCredentials
*cred
,
166 const CssmData
&descriptiveData
, CssmKey
&wrappedKey
)
168 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
171 RefPointer
<Key
> TokenDatabase::unwrapKey(const Context
&context
, Key
*key
,
172 const AccessCredentials
*cred
, const AclEntryPrototype
*owner
,
173 uint32 usage
, uint32 attrs
, const CssmKey wrappedKey
,
174 Key
*publicKey
, CssmData
*descriptiveData
)
176 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
181 // Miscellaneous CSSM functions
183 uint32
TokenDatabase::getOutputSize(const Context
&context
, Key
&key
, uint32 inputSize
, bool encrypt
)
185 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);
190 // (Re-)Authenticate the database. This changes the stored credentials.
192 void TokenDatabase::authenticate(const AccessCredentials
*cred
)
194 CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
);