1 /*############################################################################
2   # Copyright 2016-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 Epid11CheckPrivRlEntry unit tests.
20  */
21 
22 #include "epid/common-testhelper/epid_gtest-testhelper.h"
23 #include "gtest/gtest.h"
24 
25 extern "C" {
26 #include "epid/verifier/1.1/api.h"
27 }
28 
29 #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h"
30 #include "epid/verifier/1.1/unittests/verifier-testhelper.h"
31 
32 namespace {
33 
TEST_F(Epid11VerifierTest,CheckPrivRlEntryFailsGivenNullPtr)34 TEST_F(Epid11VerifierTest, CheckPrivRlEntryFailsGivenNullPtr) {
35   // check ctx, sig, f for NULL
36   auto& pub_key = this->kPubKeyStr;
37   auto& priv_rl = this->kGrpXPrivRl;
38   auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
39 
40   Epid11VerifierCtxObj verifier(pub_key);
41   FpElemStr fp_str = ((Epid11PrivRl const*)priv_rl.data())->f[0];
42   Epid11BasicSignature basic_signature =
43       ((Epid11Signature const*)sig.data())->sigma0;
44 
45   EXPECT_EQ(kEpidBadArgErr,
46             Epid11CheckPrivRlEntry(nullptr, &basic_signature, &fp_str));
47   EXPECT_EQ(kEpidBadArgErr, Epid11CheckPrivRlEntry(verifier, nullptr, &fp_str));
48   EXPECT_EQ(kEpidBadArgErr,
49             Epid11CheckPrivRlEntry(verifier, &basic_signature, nullptr));
50 }
51 
TEST_F(Epid11VerifierTest,CheckPrivRlEntryFailsGivenRevokedPrivKey)52 TEST_F(Epid11VerifierTest, CheckPrivRlEntryFailsGivenRevokedPrivKey) {
53   // test a revoked priv key
54   // check ctx, sig, f for NULL
55   auto& pub_key = this->kPubKeyStr;
56   auto& priv_rl = this->kGrpXPrivRl;
57   // signed using revoked key
58   auto& sig = this->kSigGrpXRevokedPrivKey000Sha256Bsn0Msg0;
59 
60   Epid11VerifierCtxObj verifier(pub_key);
61   FpElemStr fp_str = ((Epid11PrivRl const*)priv_rl.data())->f[0];
62   Epid11BasicSignature basic_signature =
63       ((Epid11Signature const*)sig.data())->sigma0;
64 
65   EXPECT_EQ(kEpidSigRevokedInPrivRl,
66             Epid11CheckPrivRlEntry(verifier, &basic_signature, &fp_str));
67 }
68 
TEST_F(Epid11VerifierTest,CheckPrivRlEntrySucceedsGivenUnRevokedPrivKey)69 TEST_F(Epid11VerifierTest, CheckPrivRlEntrySucceedsGivenUnRevokedPrivKey) {
70   // test a non revoked priv key
71   auto& pub_key = this->kPubKeyStr;
72   auto& priv_rl = this->kGrpXPrivRl;
73   // signed using un revoked key
74   auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
75 
76   Epid11VerifierCtxObj verifier(pub_key);
77   FpElemStr fp_str = ((Epid11PrivRl const*)priv_rl.data())->f[0];
78   Epid11BasicSignature basic_signature =
79       ((Epid11Signature const*)sig.data())->sigma0;
80 
81   EXPECT_EQ(kEpidNoErr,
82             Epid11CheckPrivRlEntry(verifier, &basic_signature, &fp_str));
83 }
84 }  // namespace
85