2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // wrapkey - client interface for wrapping and unwrapping keys
22 #include <Security/wrapkey.h>
24 using namespace CssmClient
;
28 WrapKey::operator () (Key
&keyToBeWrapped
, const CssmData
*descriptiveData
)
32 check(CSSM_WrapKey(handle(), mCred
, keyToBeWrapped
, descriptiveData
,
33 wrappedKey
.makeNewKey(attachment())));
34 wrappedKey
->activate();
40 WrapKey::operator () (const CssmKey
&keyToBeWrapped
, CssmKey
&wrappedKey
,
41 const CssmData
*descriptiveData
)
43 check(CSSM_WrapKey(handle(), mCred
, &keyToBeWrapped
, descriptiveData
, &wrappedKey
));
52 if (mWrappedKeyFormat
!= CSSM_KEYBLOB_WRAPPED_FORMAT_NONE
);
53 set(CSSM_ATTRIBUTE_WRAPPED_KEY_FORMAT
, mWrappedKeyFormat
);
58 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
)
62 const ResourceControlContext resourceControlContext
63 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
64 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
66 check(CSSM_UnwrapKey(handle(), NULL
,
67 &keyToBeUnwrapped
, spec
.usage
, spec
.attributes
,
68 spec
.label
, &resourceControlContext
,
69 unwrappedKey
.makeNewKey(attachment()), &data
));
70 unwrappedKey
->activate();
76 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
77 CssmKey
&unwrappedKey
)
79 const ResourceControlContext resourceControlContext
80 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
81 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
83 check(CSSM_UnwrapKey(handle(), NULL
, &keyToBeUnwrapped
, spec
.usage
,
84 spec
.attributes
, spec
.label
, &resourceControlContext
,
85 &unwrappedKey
, &data
));
89 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
90 Key
&optionalPublicKey
)
94 const ResourceControlContext resourceControlContext
95 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
96 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
98 check(CSSM_UnwrapKey(handle(), optionalPublicKey
,
99 &keyToBeUnwrapped
, spec
.usage
, spec
.attributes
,
100 spec
.label
, &resourceControlContext
,
101 unwrappedKey
.makeNewKey(attachment()), &data
));
103 unwrappedKey
->activate();
109 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
110 CssmKey
&unwrappedKey
,
111 const CssmKey
*optionalPublicKey
)
113 const ResourceControlContext resourceControlContext
114 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
115 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
117 check(CSSM_UnwrapKey(handle(), optionalPublicKey
, &keyToBeUnwrapped
,
118 spec
.usage
, spec
.attributes
, spec
.label
,
119 &resourceControlContext
, &unwrappedKey
, &data
));
124 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
125 CssmData
*descriptiveData
)
129 const ResourceControlContext resourceControlContext
130 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
132 check(CSSM_UnwrapKey(handle(), NULL
, &keyToBeUnwrapped
, spec
.usage
,
133 spec
.attributes
, spec
.label
, &resourceControlContext
,
134 unwrappedKey
.makeNewKey(attachment()),
136 unwrappedKey
->activate();
142 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
143 CssmKey
&unwrappedKey
, CssmData
*descriptiveData
)
145 const ResourceControlContext resourceControlContext
146 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
148 check(CSSM_UnwrapKey(handle(), NULL
, &keyToBeUnwrapped
, spec
.usage
,
149 spec
.attributes
, spec
.label
, &resourceControlContext
,
150 &unwrappedKey
, descriptiveData
));
154 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
155 Key
&optionalPublicKey
, CssmData
*descriptiveData
)
159 const ResourceControlContext resourceControlContext
160 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
162 check(CSSM_UnwrapKey(handle(), optionalPublicKey
, &keyToBeUnwrapped
,
163 spec
.usage
, spec
.attributes
, spec
.label
,
164 &resourceControlContext
,
165 unwrappedKey
.makeNewKey(attachment()),
167 unwrappedKey
->activate();
173 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
174 CssmKey
&unwrappedKey
, CssmData
*descriptiveData
,
175 const CssmKey
*optionalPublicKey
)
177 const ResourceControlContext resourceControlContext
178 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
180 check(CSSM_UnwrapKey(handle(), optionalPublicKey
, &keyToBeUnwrapped
,
181 spec
.usage
, spec
.attributes
, spec
.label
,
182 &resourceControlContext
, &unwrappedKey
,
187 void DeriveKey::activate()
191 check(CSSM_CSP_CreateDeriveKeyContext(attachment()->handle(), mAlgorithm
,
192 mTargetType
, mKeySize
, mCred
, mKey
, mIterationCount
, mSalt
, mSeed
, &mHandle
));
199 DeriveKey::operator () (CssmData
*param
, const KeySpec
&spec
)
203 const ResourceControlContext resourceControlContext
204 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
206 check(CSSM_DeriveKey(handle(), param
, spec
.usage
, spec
.attributes
,
207 spec
.label
, &resourceControlContext
,
208 derivedKey
.makeNewKey(attachment())));
209 derivedKey
->activate();
215 DeriveKey::operator () (CssmData
*param
, const KeySpec
&spec
,
218 const ResourceControlContext resourceControlContext
219 (mAclEntry
, const_cast<AccessCredentials
*>(mCred
));
221 check(CSSM_DeriveKey(handle(), param
, spec
.usage
, spec
.attributes
,
222 spec
.label
, &resourceControlContext
, &derivedKey
));