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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
/*
* @file scheme-test.h
* @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
* @version 1.0
*/
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <ckm/ckm-control.h>
#include <ckm/ckm-manager.h>
#include <data-type.h>
namespace CKM {
namespace DB {
class Crypto;
} // DB
} // CKM
struct Item {
Item() : type(CKM::DataType::Type::DB_LAST)
{
}
Item(const CKM::Alias& alias,
const CKM::DataType::Type type,
const CKM::Policy& policy)
: alias(alias), type(type), policy(policy)
{
}
CKM::Alias alias;
CKM::DataType::Type type;
CKM::Policy policy;
};
typedef std::vector<Item> Items;
struct ItemFilter {
ItemFilter() :
typeFrom(CKM::DataType::DB_FIRST),
typeTo(CKM::DataType::DB_LAST),
exportableOnly(false),
noPassword(false)
{}
explicit ItemFilter(CKM::DataType::Type type) :
typeFrom(type),
typeTo(type),
exportableOnly(false),
noPassword(false)
{}
ItemFilter(CKM::DataType::Type typeFrom, CKM::DataType::Type typeTo) :
typeFrom(typeFrom),
typeTo(typeTo),
exportableOnly(false),
noPassword(false)
{}
bool Matches(const Item& item) const {
if(item.type < typeFrom || item.type > typeTo)
return false;
if(exportableOnly && !item.policy.extractable)
return false;
if(noPassword && !item.policy.password.empty())
return false;
return true;
}
CKM::DataType::Type typeFrom;
CKM::DataType::Type typeTo;
bool exportableOnly;
bool noPassword;
};
class SchemeTest {
public:
SchemeTest();
~SchemeTest();
void RemoveUserData();
void FillDb();
void ReadAll(bool useWrongPass = false);
void SignVerify();
void EncryptDecrypt();
void CreateChain();
void RemoveAll();
size_t CountObjects();
void RestoreDb();
void CheckSchemeVersion(const ItemFilter& filter, int version);
private:
void SwitchToUser();
void SwitchToRoot();
void EnableDirectDbAccess();
void SignVerifyItem(const Item& itemPrv, const Item& itemPub);
void EncryptDecryptItem(const Item& item);
void EncryptDecryptItem(const Item& itemPrv, const Item& itemPub);
void CreateChainItem(const Item& leaf, const Items& certs);
CKM::ControlShPtr m_control;
CKM::ManagerShPtr m_mgr;
std::string m_origLabel;
bool m_userChanged;
std::unique_ptr<CKM::DB::Crypto> m_db;
bool m_directAccessEnabled;
};
|