check_privrl_entry-test.cc 3.0 KB

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