check_privrl_entry-test.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. * \file
  18. * \brief CheckPrivRlEntry unit tests.
  19. */
  20. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  21. #include "gtest/gtest.h"
  22. extern "C" {
  23. #include "epid/verifier/api.h"
  24. }
  25. #include "epid/common-testhelper/errors-testhelper.h"
  26. #include "epid/common-testhelper/verifier_wrapper-testhelper.h"
  27. #include "epid/verifier/unittests/verifier-testhelper.h"
  28. namespace {
  29. TEST_F(EpidVerifierTest, CheckPrivRlEntryFailsGivenNullPtr) {
  30. // check ctx, sig, f for NULL
  31. auto& pub_key = this->kGrpXKey;
  32. auto& priv_rl = this->kGrpXPrivRl;
  33. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  34. VerifierCtxObj verifier(pub_key);
  35. FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  36. BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;
  37. EXPECT_EQ(kEpidBadArgErr,
  38. EpidCheckPrivRlEntry(nullptr, &basic_signature, &fp_str));
  39. EXPECT_EQ(kEpidBadArgErr, EpidCheckPrivRlEntry(verifier, nullptr, &fp_str));
  40. EXPECT_EQ(kEpidBadArgErr,
  41. EpidCheckPrivRlEntry(verifier, &basic_signature, nullptr));
  42. }
  43. TEST_F(EpidVerifierTest, CheckPrivRlEntryFailsGivenRevokedPrivKey) {
  44. // test a revoked priv key
  45. // check ctx, sig, f for NULL
  46. auto& pub_key = this->kGrpXKey;
  47. auto& priv_rl = this->kGrpXPrivRl;
  48. // signed using revoked key
  49. auto& sig = this->kSigGrpXRevokedPrivKey000Sha256Bsn0Msg0;
  50. VerifierCtxObj verifier(pub_key);
  51. FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  52. BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;
  53. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  54. EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
  55. }
  56. TEST_F(EpidVerifierTest,
  57. CheckPrivRlEntryFailsGivenRevokedPrivKeyUsingIkgfData) {
  58. // test a revoked priv key
  59. // check ctx, sig, f for NULL
  60. auto& pub_key = this->kPubKeyIkgfStr;
  61. auto& priv_rl = this->kPrivRlIkgf;
  62. // signed using revoked key
  63. auto& sig = this->kSigRevokedPrivKeySha256Bsn0Msg0Ikgf;
  64. VerifierCtxObj verifier(pub_key);
  65. FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[2];
  66. BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;
  67. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  68. EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
  69. }
  70. TEST_F(EpidVerifierTest, CheckPrivRlEntrySucceedsGivenUnRevokedPrivKey) {
  71. // test a non revoked priv key
  72. auto& pub_key = this->kGrpXKey;
  73. auto& priv_rl = this->kGrpXPrivRl;
  74. // signed using un revoked key
  75. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  76. VerifierCtxObj verifier(pub_key);
  77. FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  78. BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;
  79. EXPECT_EQ(kEpidNoErr,
  80. EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
  81. }
  82. TEST_F(EpidVerifierTest,
  83. CheckPrivRlEntrySucceedsGivenUnRevokedPrivKeyUsingIkgfData) {
  84. // test a non revoked priv key
  85. auto& pub_key = this->kPubKeyIkgfStr;
  86. auto& priv_rl = this->kPrivRlIkgf;
  87. // signed using un revoked key
  88. auto& sig = this->kSigMember0Sha256Bsn0Msg0Ikgf;
  89. VerifierCtxObj verifier(pub_key);
  90. FpElemStr fp_str = ((PrivRl const*)priv_rl.data())->f[0];
  91. BasicSignature basic_signature = ((EpidSignature const*)sig.data())->sigma0;
  92. EXPECT_EQ(kEpidNoErr,
  93. EpidCheckPrivRlEntry(verifier, &basic_signature, &fp_str));
  94. }
  95. } // namespace