aboutsummaryrefslogtreecommitdiff
path: root/epid/verifier/unittests/check_privrl_entry-test.cc
blob: 7ec5275e2a07364a816d043f50bdb095d970cb15 (plain)
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
/*############################################################################
  # Copyright 2016 Intel Corporation
  #
  # 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
 * \brief CheckPrivRlEntry unit tests.
 */

#include "gtest/gtest.h"

extern "C" {
#include "epid/verifier/api.h"
}

#include "epid/verifier/unittests/verifier-testhelper.h"
#include "epid/common-testhelper/verifier_wrapper-testhelper.h"
#include "epid/common-testhelper/errors-testhelper.h"

namespace {

TEST_F(EpidVerifierTest, CheckPrivRlEntryFailsGivenNullPtr) {
  // check ctx, sig, f for NULL
  auto& pub_key = this->kGrpXKey;
  auto& priv_rl = this->kGrpXPrivRl;
  auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;

  VerifierCtxObj verifier(pub_key);
  FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;

  EXPECT_EQ(kEpidBadArgErr,
            EpidCheckPrivRlEntry(nullptr, &basic_signature, &fp_str));
  EXPECT_EQ(kEpidBadArgErr, EpidCheckPrivRlEntry(verifier, nullptr, &fp_str));
  EXPECT_EQ(kEpidBadArgErr,
            EpidCheckPrivRlEntry(verifier, &basic_signature, nullptr));
}

TEST_F(EpidVerifierTest, CheckPrivRlEntryFailsGivenRevokedPrivKey) {
  // test a revoked priv key
  // check ctx, sig, f for NULL
  auto& pub_key = this->kGrpXKey;
  auto& priv_rl = this->kGrpXPrivRl;
  // signed using revoked key
  auto& sig = this->kSigGrpXRevokedPrivKey000Sha256Bsn0Msg0;

  VerifierCtxObj verifier(pub_key);
  FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;

  EXPECT_EQ(kEpidSigRevokedinPrivRl,
            EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
}

TEST_F(EpidVerifierTest,
       CheckPrivRlEntryFailsGivenRevokedPrivKeyUsingIkgfData) {
  // test a revoked priv key
  // check ctx, sig, f for NULL
  auto& pub_key = this->pub_key_ikgf_str;
  auto& priv_rl = this->kPrivRlIkgf;
  // signed using revoked key
  auto& sig = this->kSigRevokedPrivKeySha256Bsn0Msg0Ikgf;

  VerifierCtxObj verifier(pub_key);

  FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[2];
  BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;

  EXPECT_EQ(kEpidSigRevokedinPrivRl,
            EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
}

TEST_F(EpidVerifierTest, CheckPrivRlEntrySucceedsGivenUnRevokedPrivKey) {
  // test a non revoked priv key
  auto& pub_key = this->kGrpXKey;
  auto& priv_rl = this->kGrpXPrivRl;
  // signed using un revoked key
  auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;

  VerifierCtxObj verifier(pub_key);
  FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;

  EXPECT_EQ(kEpidNoErr,
            EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
}

TEST_F(EpidVerifierTest,
       CheckPrivRlEntrySucceedsGivenUnRevokedPrivKeyUsingIkgfData) {
  // test a non revoked priv key
  auto& pub_key = this->pub_key_ikgf_str;
  auto& priv_rl = this->kPrivRlIkgf;
  // signed using un revoked key
  auto& sig = this->kSigMember0Sha256Bsn0Msg0Ikgf;

  VerifierCtxObj verifier(pub_key);
  FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;

  EXPECT_EQ(kEpidNoErr,
            EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
}

}  // namespace