- // decrypt the key using an unwrapping operation
- UnwrapKey unwrap(Server::csp(), CSSM_ALGID_3DES_3KEY_EDE);
- unwrap.key(mEncryptionKey);
- unwrap.mode(CSSM_ALGMODE_CBCPadIV8);
- unwrap.padding(CSSM_PADDING_PKCS1);
- CssmData ivd(blob->iv, sizeof(blob->iv)); unwrap.initVector(ivd);
- unwrap.add(CSSM_ATTRIBUTE_WRAPPED_KEY_FORMAT,
- uint32(CSSM_KEYBLOB_WRAPPED_FORMAT_APPLE_CUSTOM));
- CssmData privAclData;
- wrappedKey.clearAttribute(managedAttributes); //@@@ shouldn't be needed(?)
- unwrap(wrappedKey,
- KeySpec(n2h(blob->header.usage()),
- (n2h(blob->header.attributes()) & ~managedAttributes) | forcedAttributes),
- key, &privAclData);
-
+ CssmData privAclData;
+ if(inTheClear) {
+ /* NULL unwrap */
+ UnwrapKey unwrap(Server::csp(), CSSM_ALGID_NONE);
+ wrappedKey.clearAttribute(managedAttributes); //@@@ shouldn't be needed(?)
+ unwrap(wrappedKey,
+ KeySpec(n2h(blob->header.usage()),
+ (n2h(blob->header.attributes()) & ~managedAttributes) | forcedAttributes),
+ key, &privAclData);
+ }
+ else {
+ // decrypt the key using an unwrapping operation
+ UnwrapKey unwrap(Server::csp(), CSSM_ALGID_3DES_3KEY_EDE);
+ unwrap.key(mEncryptionKey);
+ unwrap.mode(CSSM_ALGMODE_CBCPadIV8);
+ unwrap.padding(CSSM_PADDING_PKCS1);
+ CssmData ivd(blob->iv, sizeof(blob->iv)); unwrap.initVector(ivd);
+ unwrap.add(CSSM_ATTRIBUTE_WRAPPED_KEY_FORMAT,
+ uint32(CSSM_KEYBLOB_WRAPPED_FORMAT_APPLE_CUSTOM));
+ wrappedKey.clearAttribute(managedAttributes); //@@@ shouldn't be needed(?)
+ unwrap(wrappedKey,
+ KeySpec(n2h(blob->header.usage()),
+ (n2h(blob->header.attributes()) & ~managedAttributes) | forcedAttributes),
+ key, &privAclData);
+ }
+