- CssmClient::KeyAclBearer bearer(cspHand, unwrappedKey, Allocator::standard());
- theAccess->setAccess(bearer, maker);
+ if(secKeyRef != NULL) {
+ // setAccess using the new secKeyRef, not the old unwrappedKey.
+ // At this point, we might have duplicate keys registered with securityd. Use the newest one.
+ theAccess->setAccess(*KeyItem::required(secKeyRef)->key(), maker);
+ } else {
+ CssmClient::KeyAclBearer bearer(cspHand, unwrappedKey, Allocator::standard());
+ theAccess->setAccess(bearer, maker);
+ }