• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /// TPM Context unit tests.
17 /*! \file */
18 #include "epid/common-testhelper/epid_gtest-testhelper.h"
19 #include "gtest/gtest.h"
20 
21 #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
22 #include "epid/common-testhelper/errors-testhelper.h"
23 #include "epid/common-testhelper/mem_params-testhelper.h"
24 #include "epid/common-testhelper/prng-testhelper.h"
25 #include "epid/member/tpm2/unittests/tpm2-testhelper.h"
26 
27 extern "C" {
28 #include "epid/common/src/epid2params.h"
29 #include "epid/member/tpm2/context.h"
30 #include "epid/member/tpm2/load_external.h"
31 }
32 
33 namespace {
34 //////////////////////////////////////////////////////////////////////////
35 // Tpm2CreateContext Tests
TEST_F(EpidTpm2Test,CreateFailsGivenNullParameters)36 TEST_F(EpidTpm2Test, CreateFailsGivenNullParameters) {
37   Tpm2Ctx* ctx = nullptr;
38   Prng my_prng;
39   BitSupplier rnd_func = NULL;
40   void* rnd_param = NULL;
41   const FpElemStr* f = NULL;
42   MemberParams mem_params = {0};
43   Epid2ParamsObj epid_params;
44   SetMemberParams(&Prng::Generate, &my_prng, nullptr, &mem_params);
45 
46   EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(nullptr, epid_params, &rnd_func,
47                                               &rnd_param, &f, &ctx));
48   EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(&mem_params, nullptr, &rnd_func,
49                                               &rnd_param, &f, &ctx));
50   EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(&mem_params, epid_params, nullptr,
51                                               &rnd_param, &f, &ctx));
52   EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(&mem_params, epid_params,
53                                               &rnd_func, nullptr, &f, &ctx));
54   EXPECT_EQ(kEpidBadArgErr,
55             Tpm2CreateContext(&mem_params, epid_params, &rnd_func, &rnd_param,
56                               nullptr, &ctx));
57   EXPECT_EQ(kEpidBadArgErr,
58             Tpm2CreateContext(&mem_params, epid_params, &rnd_func, &rnd_param,
59                               &f, nullptr));
60 }
61 
TEST_F(EpidTpm2Test,CreateSucceedsGivenValidParameters)62 TEST_F(EpidTpm2Test, CreateSucceedsGivenValidParameters) {
63   Tpm2Ctx* ctx = nullptr;
64   Prng my_prng;
65   BitSupplier rnd_func = NULL;
66   void* rnd_param = NULL;
67   const FpElemStr* f = NULL;
68   MemberParams mem_params = {0};
69   Epid2ParamsObj epid_params;
70   SetMemberParams(&Prng::Generate, &my_prng, nullptr, &mem_params);
71 
72   EXPECT_EQ(kEpidNoErr, Tpm2CreateContext(&mem_params, epid_params, &rnd_func,
73                                           &rnd_param, &f, &ctx));
74   Tpm2DeleteContext(&ctx);
75 }
76 
77 //////////////////////////////////////////////////////////////////////////
78 // Tpm2DeleteContext Tests
TEST_F(EpidTpm2Test,DeleteWorksGivenNullTpm2Ctx)79 TEST_F(EpidTpm2Test, DeleteWorksGivenNullTpm2Ctx) {
80   Tpm2DeleteContext(nullptr);
81   Tpm2Ctx* ctx = nullptr;
82   Tpm2DeleteContext(&ctx);
83 }
84 
TEST_F(EpidTpm2Test,DeleteNullsTpm2Ctx)85 TEST_F(EpidTpm2Test, DeleteNullsTpm2Ctx) {
86   Tpm2Ctx* ctx = nullptr;
87   Prng my_prng;
88   BitSupplier rnd_func = NULL;
89   void* rnd_param = NULL;
90   const FpElemStr* f = NULL;
91   MemberParams mem_params = {0};
92   Epid2ParamsObj epid_params;
93   SetMemberParams(&Prng::Generate, &my_prng, nullptr, &mem_params);
94   Tpm2CreateContext(&mem_params, epid_params, &rnd_func, &rnd_param, &f, &ctx);
95   Tpm2DeleteContext(&ctx);
96   EXPECT_EQ(nullptr, ctx);
97 }
98 
TEST_F(EpidTpm2Test,PROTECTED_SampleTest)99 TEST_F(EpidTpm2Test, PROTECTED_SampleTest) { SUCCEED(); }
100 
TEST_F(EpidTpm2Test,PROTECTED_EPS1_SampleTest)101 TEST_F(EpidTpm2Test, PROTECTED_EPS1_SampleTest) { SUCCEED(); }
102 
TEST_F(EpidTpm2Test,PROTECTED_EPSOther_SampleTest)103 TEST_F(EpidTpm2Test, PROTECTED_EPSOther_SampleTest) { SUCCEED(); }
104 
105 }  // namespace
106