1 /*############################################################################
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ############################################################################*/
16
17 /*!
18 * \file
19 * \brief Provision compressed unit tests.
20 */
21 #include <cstring>
22 #include <vector>
23
24 #include "epid/common-testhelper/epid_gtest-testhelper.h"
25 #include "gtest/gtest.h"
26
27 #include "epid/common-testhelper/errors-testhelper.h"
28 #include "epid/common-testhelper/mem_params-testhelper.h"
29 #include "epid/common-testhelper/prng-testhelper.h"
30 #include "epid/member/tiny/unittests/member-testhelper.h"
31
32 extern "C" {
33 #include "epid/member/api.h"
34 }
35
36 namespace {
37
ProvisionCompressedAndStart(MemberCtx * ctx,GroupPubKey const * pub_key,CompressedPrivKey const * compressed_privkey,MemberPrecomp const * precomp_str)38 EpidStatus ProvisionCompressedAndStart(
39 MemberCtx* ctx, GroupPubKey const* pub_key,
40 CompressedPrivKey const* compressed_privkey,
41 MemberPrecomp const* precomp_str) {
42 EpidStatus sts;
43 sts = EpidProvisionCompressed(ctx, pub_key, compressed_privkey, precomp_str);
44 if (sts != kEpidNoErr) {
45 return sts;
46 }
47 sts = EpidMemberStartup(ctx);
48 return sts;
49 }
50
TEST_F(EpidMemberTest,DISABLED_ProvisionCompressedFailsGivenNullParameters)51 TEST_F(EpidMemberTest, DISABLED_ProvisionCompressedFailsGivenNullParameters) {
52 Prng prng;
53 GroupPubKey pub_key = this->kGrpXKey;
54 CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
55 // Note: this MemberPrecomp is for the wrong group, however it should not
56 // be checked in Provision because doing so would negate the performance
57 // boost of using the precomp.
58 MemberPrecomp precomp = this->kMemberPrecomp;
59 MemberParams params = {0};
60 SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
61 MemberCtxObj member(¶ms);
62 EXPECT_EQ(kEpidBadArgErr,
63 EpidProvisionCompressed(nullptr, &pub_key, &priv_key, &precomp));
64 EXPECT_EQ(kEpidBadArgErr,
65 EpidProvisionCompressed(member, nullptr, &priv_key, &precomp));
66 EXPECT_EQ(kEpidBadArgErr,
67 EpidProvisionCompressed(member, &pub_key, nullptr, &precomp));
68 EXPECT_EQ(kEpidBadArgErr,
69 EpidProvisionCompressed(nullptr, &pub_key, &priv_key, nullptr));
70 EXPECT_EQ(kEpidBadArgErr,
71 EpidProvisionCompressed(member, nullptr, &priv_key, nullptr));
72 EXPECT_EQ(kEpidBadArgErr,
73 EpidProvisionCompressed(member, &pub_key, nullptr, nullptr));
74 }
75
TEST_F(EpidMemberTest,DISABLED_ProvisionCompressedSucceedsGivenValidParameters)76 TEST_F(EpidMemberTest,
77 DISABLED_ProvisionCompressedSucceedsGivenValidParameters) {
78 Prng prng;
79 GroupPubKey pub_key = this->kGrpXKey;
80 CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
81 // Note: this MemberPrecomp is for the wrong group, however it should not
82 // be checked in Provision because doing so would negate the performance
83 // boost of using the precomp.
84 MemberPrecomp precomp = this->kMemberPrecomp;
85 MemberParams params = {0};
86 SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
87 MemberCtxObj member(¶ms);
88 EXPECT_EQ(kEpidNoErr,
89 EpidProvisionCompressed(member, &pub_key, &priv_key, &precomp));
90 EXPECT_EQ(kEpidNoErr,
91 EpidProvisionCompressed(member, &pub_key, &priv_key, nullptr));
92 }
93
TEST_F(EpidMemberTest,DISABLED_ProvisionCompressedFailsForInvalidGroupPubKey)94 TEST_F(EpidMemberTest, DISABLED_ProvisionCompressedFailsForInvalidGroupPubKey) {
95 Prng prng;
96 GroupPubKey pub_key = this->kGrpXKey;
97 CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
98 // Note: this MemberPrecomp is for the wrong group, however it should not
99 // be checked in Provision because doing so would negate the performance
100 // boost of using the precomp.
101 MemberPrecomp precomp = this->kMemberPrecomp;
102 MemberParams params = {0};
103 SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
104 MemberCtxObj member(¶ms);
105
106 pub_key = this->kGrpXKey;
107 pub_key.h1.x.data.data[0]++;
108 EXPECT_EQ(kEpidBadArgErr,
109 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
110 EXPECT_EQ(kEpidBadArgErr,
111 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
112
113 pub_key = this->kGrpXKey;
114 pub_key.h1.y.data.data[0]++;
115 EXPECT_EQ(kEpidBadArgErr,
116 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
117 EXPECT_EQ(kEpidBadArgErr,
118 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
119
120 pub_key = this->kGrpXKey;
121 pub_key.w.x[0].data.data[0]++;
122 EXPECT_EQ(kEpidBadArgErr,
123 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
124 EXPECT_EQ(kEpidBadArgErr,
125 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
126
127 pub_key = this->kGrpXKey;
128 pub_key.w.x[1].data.data[0]++;
129 EXPECT_EQ(kEpidBadArgErr,
130 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
131 EXPECT_EQ(kEpidBadArgErr,
132 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
133
134 pub_key = this->kGrpXKey;
135 pub_key.w.y[0].data.data[0]++;
136 EXPECT_EQ(kEpidBadArgErr,
137 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
138 EXPECT_EQ(kEpidBadArgErr,
139 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
140
141 pub_key = this->kGrpXKey;
142 pub_key.w.y[1].data.data[0]++;
143 EXPECT_EQ(kEpidBadArgErr,
144 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
145 EXPECT_EQ(kEpidBadArgErr,
146 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
147 }
148
TEST_F(EpidMemberTest,DISABLED_ProvisionCompressedFailsForInvalidPrivateKey)149 TEST_F(EpidMemberTest, DISABLED_ProvisionCompressedFailsForInvalidPrivateKey) {
150 Prng prng;
151 GroupPubKey pub_key = this->kGrpXKey;
152 CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
153 // Note: this MemberPrecomp is for the wrong group, however it should not
154 // be checked in Provision because doing so would negate the performance
155 // boost of using the precomp.
156 MemberPrecomp precomp = this->kMemberPrecomp;
157 MemberParams params = {0};
158 SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
159 MemberCtxObj member(¶ms);
160
161 priv_key = this->kGrpXMember9CompressedKey;
162 priv_key.ax.data.data[0]++;
163 EXPECT_EQ(kEpidBadArgErr,
164 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
165 EXPECT_EQ(kEpidBadArgErr,
166 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
167
168 priv_key = this->kGrpXMember9CompressedKey;
169 priv_key.seed.data[0]++;
170 EXPECT_EQ(kEpidBadArgErr,
171 ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
172 EXPECT_EQ(kEpidBadArgErr,
173 ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
174 }
175
176 } // namespace
177