123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- /*############################################################################
- # Copyright 2017 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 Provision credential unit tests.
- */
- #include <cstring>
- #include <vector>
- #include "gtest/gtest.h"
- extern "C" {
- #include "epid/member/api.h"
- #include "epid/member/src/context.h"
- #include "epid/member/src/storage.h"
- }
- #include "epid/common-testhelper/epid_gtest-testhelper.h"
- #include "epid/common-testhelper/errors-testhelper.h"
- #include "epid/common-testhelper/mem_params-testhelper.h"
- #include "epid/common-testhelper/prng-testhelper.h"
- #include "epid/member/unittests/member-testhelper.h"
- namespace {
- EpidStatus ProvisionCredentialAndStart(MemberCtx* ctx,
- GroupPubKey const* pub_key,
- MembershipCredential const* credential,
- MemberPrecomp const* precomp_str) {
- EpidStatus sts;
- sts = EpidProvisionCredential(ctx, pub_key, credential, precomp_str);
- if (sts != kEpidNoErr) {
- return sts;
- }
- sts = EpidMemberStartup(ctx);
- return sts;
- }
- TEST_F(EpidMemberTest, ProvisionCredentialFailsGivenNullParameters) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- FpElemStr f = this->kGrpXMember9PrivKey.f;
- MembershipCredential credential;
- credential.A = this->kGrpXMember9PrivKey.A;
- credential.gid = this->kGrpXMember9PrivKey.gid;
- credential.x = this->kGrpXMember9PrivKey.x;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCredential(nullptr, &pub_key, &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCredential(member, nullptr, &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCredential(member, &pub_key, nullptr, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCredential(nullptr, &pub_key, &credential, nullptr));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCredential(member, nullptr, &credential, nullptr));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCredential(member, &pub_key, nullptr, nullptr));
- }
- TEST_F(EpidMemberTest, ProvisionCredentialRejectsInvalidCredential) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- FpElemStr f = this->kGrpXMember9PrivKey.f;
- MembershipCredential credential;
- MembershipCredential base_credential;
- base_credential.A = this->kGrpXMember9PrivKey.A;
- base_credential.gid = this->kGrpXMember9PrivKey.gid;
- base_credential.x = this->kGrpXMember9PrivKey.x;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- credential = base_credential;
- credential.A.x.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- credential = base_credential;
- credential.A.y.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- credential = base_credential;
- credential.x.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- }
- TEST_F(EpidMemberTest, ProvisionCredentialRejectsInvalidGroupKey) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- FpElemStr f = this->kGrpXMember9PrivKey.f;
- MembershipCredential credential;
- credential.A = this->kGrpXMember9PrivKey.A;
- credential.gid = this->kGrpXMember9PrivKey.gid;
- credential.x = this->kGrpXMember9PrivKey.x;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- pub_key = this->kGroupPublicKey;
- pub_key.h1.x.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- pub_key = this->kGroupPublicKey;
- pub_key.h1.y.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- pub_key = this->kGroupPublicKey;
- pub_key.h2.x.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- pub_key = this->kGroupPublicKey;
- pub_key.h2.y.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- pub_key = this->kGroupPublicKey;
- pub_key.w.x[0].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- pub_key = this->kGroupPublicKey;
- pub_key.w.x[1].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- pub_key = this->kGroupPublicKey;
- pub_key.w.y[0].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- pub_key = this->kGroupPublicKey;
- pub_key.w.y[1].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- }
- TEST_F(EpidMemberTest, ProvisionCredentialRejectsCredentialNotInGroup) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- FpElemStr f = this->kGrpXMember9PrivKey.f;
- MembershipCredential credential;
- MembershipCredential base_credential;
- base_credential.A = this->kGrpXMember9PrivKey.A;
- base_credential.gid = this->kGrpXMember9PrivKey.gid;
- base_credential.x = this->kGrpXMember9PrivKey.x;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- credential = base_credential;
- credential.gid.data[0] = ~credential.gid.data[0];
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- }
- TEST_F(EpidMemberTest, CanProvisionUsingMembershipCredentialPrecomp) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- FpElemStr f = this->kGrpXMember9PrivKey.f;
- MembershipCredential credential;
- credential.A = this->kGrpXMember9PrivKey.A;
- credential.gid = this->kGrpXMember9PrivKey.gid;
- credential.x = this->kGrpXMember9PrivKey.x;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, &precomp));
- }
- TEST_F(EpidMemberTest, CanProvisionUsingMembershipCredentialNoPrecomp) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- FpElemStr f = this->kGrpXMember9PrivKey.f;
- MembershipCredential credential;
- credential.A = this->kGrpXMember9PrivKey.A;
- credential.gid = this->kGrpXMember9PrivKey.gid;
- credential.x = this->kGrpXMember9PrivKey.x;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key,
- &credential, nullptr));
- }
- // test that create succeeds with valid IKGF given parameters
- TEST_F(EpidMemberTest, CanProvisionUsingIKGFMembershipCredentialPrecomp) {
- Prng prng;
- const GroupPubKey* pub_key = reinterpret_cast<const GroupPubKey*>(
- this->kGroupPublicKeyDataIkgf.data());
- const PrivKey* priv_key =
- reinterpret_cast<const PrivKey*>(this->kMemberPrivateKeyDataIkgf.data());
- FpElemStr f = priv_key->f;
- MembershipCredential credential;
- credential.A = priv_key->A;
- credential.gid = priv_key->gid;
- credential.x = priv_key->x;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, pub_key,
- &credential, &precomp));
- }
- TEST_F(EpidMemberTest, CanProvisionUsingIKGFMembershipCredentialNoPrecomp) {
- Prng prng;
- const GroupPubKey* pub_key = reinterpret_cast<const GroupPubKey*>(
- this->kGroupPublicKeyDataIkgf.data());
- const PrivKey* priv_key =
- reinterpret_cast<const PrivKey*>(this->kMemberPrivateKeyDataIkgf.data());
- FpElemStr f = priv_key->f;
- MembershipCredential credential;
- credential.A = priv_key->A;
- credential.gid = priv_key->gid;
- credential.x = priv_key->x;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidNoErr,
- ProvisionCredentialAndStart(member, pub_key, &credential, nullptr));
- }
- TEST_F(EpidMemberTest,
- ProvisionCredentialCanStoreMembershipCredentialNoPrecomp) {
- Prng prng;
- uint32_t nv_index = 0x01c10100;
- MembershipCredential const orig_credential =
- *(MembershipCredential*)&this->kGrpXMember9PrivKey;
- MembershipCredential credential;
- GroupPubKey pub_key = this->kGrpXKey;
- FpElemStr f = this->kGrpXMember9PrivKey.f;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, &f, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key,
- &orig_credential, nullptr));
- EXPECT_EQ(kEpidNoErr,
- EpidNvReadMembershipCredential(((MemberCtx*)member)->tpm2_ctx,
- nv_index, &pub_key, &credential));
- EXPECT_EQ(orig_credential, credential);
- }
- } // namespace
|