This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_policy_key.cc
51 lines (43 loc) · 1.8 KB
/
object_policy_key.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "object_policy_key.h"
#include <base/macros.h>
namespace p11net {
// Read policy list as follows:
// {attribute, sensitive, read-only {create, copy, modify}, required}
// sensitive - True if attribute cannot be read.
// read-only.create - True if attribute cannot be set with C_CreateObject.
// read-only.copy - True if attribute cannot be set with C_CopyObject.
// read-only.modify - True if attribute cannot be set with C_SetAttributeValue.
// required - True if attribute is required for a valid object.
static const AttributePolicy kKeyPolicies[] = {
{CKA_KEY_TYPE, false, {false, false, true}, true},
{CKA_LOCAL, false, {true, true, true}, false},
{CKA_KEY_GEN_MECHANISM, false, {true, true, true}, false},
{CKA_ALLOWED_MECHANISMS, false, {false, false, true}, false},
};
ObjectPolicyKey::ObjectPolicyKey() {
AddPolicies(kKeyPolicies, arraysize(kKeyPolicies));
}
ObjectPolicyKey::~ObjectPolicyKey() {}
void ObjectPolicyKey::SetDefaultAttributes() {
ObjectPolicyCommon::SetDefaultAttributes();
CK_ATTRIBUTE_TYPE empty[] = {
CKA_ID,
CKA_START_DATE,
CKA_END_DATE
};
for (size_t i = 0; i < arraysize(empty); ++i) {
if (!object_->IsAttributePresent(empty[i]))
object_->SetAttributeString(empty[i], "");
}
if (!object_->IsAttributePresent(CKA_DERIVE))
object_->SetAttributeBool(CKA_DERIVE, false);
if (!object_->IsAttributePresent(CKA_LOCAL))
object_->SetAttributeBool(CKA_LOCAL, false);
if (!object_->IsAttributePresent(CKA_KEY_GEN_MECHANISM))
object_->SetAttributeInt(CKA_KEY_GEN_MECHANISM,
static_cast<int>(CK_UNAVAILABLE_INFORMATION));
}
} // namespace p11net