check_privrl_entry-test.cc 4.0 KB

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