/*############################################################################ # Copyright 2016-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 Issuer material file parsing unit tests. */ #include <cstdint> #include <vector> #include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/common/file_parser.h" } namespace { /// Test fixture class for EpidFileParser class EpidFileParser : public ::testing::Test { public: /// Cert used to sign legitimate test data static const EpidCaCertificate kCert; /// A file with short GroupPublicKey signed with kCert static const std::vector<uint8_t> kGroupPublicKeyFile; /// A file with two Epid11GroupPublicKey signed with kCert static const std::vector<uint8_t> kGroupMultiPublicKeyFile; /// Expected short GroupPublicKey static const std::vector<uint8_t> kGroupPublicKey; /// A file with short privrl signed with cert static const std::vector<uint8_t> kShortPrivRlFile; /// Expected short privrl static const std::vector<uint8_t> kShortPrivRl; /// A file with empty privrl signed with cert static const std::vector<uint8_t> kEmptyPrivRlFile; /// Expected empty privrl static const std::vector<uint8_t> kEmptyPrivRl; /// A file with empty SigRl signed with kCert static const std::vector<uint8_t> kEmptySigRlFile; /// Expected empty SigRl static const std::vector<uint8_t> kEmptySigRl; /// A file with short SigRl signed with kCert static const std::vector<uint8_t> kShortSigRlFile; /// Expected short SigRl static const std::vector<uint8_t> kShortSigRl; /// A file with empty GroupRl signed with kCert static const std::vector<uint8_t> kEmptyGroupRlFile; /// Expected empty GroupRl static const std::vector<uint8_t> kEmptyGroupRl; /// A file with short GroupRl signed with kCert static const std::vector<uint8_t> kShortGroupRlFile; /// Expected short GroupRl static const std::vector<uint8_t> kShortGroupRl; }; const EpidCaCertificate EpidFileParser::kCert = { 0x02, 0x00, 0x00, 0x11, 0x24, 0x42, 0xa5, 0xcc, 0x0e, 0xcd, 0x01, 0x5f, 0xa3, 0xca, 0x31, 0xdc, 0x8e, 0x2b, 0xbc, 0x70, 0xbf, 0x42, 0xd6, 0x0c, 0xbc, 0xa2, 0x00, 0x85, 0xe0, 0x82, 0x2c, 0xb0, 0x42, 0x35, 0xe9, 0x70, 0x6f, 0xc9, 0x8b, 0xd7, 0xe5, 0x02, 0x11, 0xa4, 0xa2, 0x71, 0x02, 0xfa, 0x35, 0x49, 0xdf, 0x79, 0xeb, 0xcb, 0x4b, 0xf2, 0x46, 0xb8, 0x09, 0x45, 0xcd, 0xdf, 0xe7, 0xd5, 0x09, 0xbb, 0xfd, 0x7d, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7, 0xb3, 0xeb, 0xbd, 0x55, 0x76, 0x98, 0x86, 0xbc, 0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53, 0xb0, 0xf6, 0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96, 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84, 0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x94, 0x03, 0x1d, 0x90, 0x6b, 0x6f, 0xcd, 0x99, 0xef, 0x2c, 0xdb, 0x8b, 0xa9, 0x8a, 0xef, 0x7e, 0xf0, 0x77, 0xba, 0xb5, 0x11, 0x43, 0x0d, 0x28, 0x1c, 0x01, 0x5b, 0xc9, 0x08, 0xce, 0x3e, 0x68}; const std::vector<uint8_t> EpidFileParser::kEmptySigRlFile = { 0x02, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x7d, 0x04, 0xa1, 0x29, 0x28, 0xc3, 0x4d, 0x30, 0x8d, 0x67, 0xe4, 0xe8, 0x62, 0x71, 0xe8, 0x4f, 0x0d, 0x45, 0x46, 0xc9, 0xde, 0x67, 0x30, 0x47, 0xb5, 0xfb, 0xb5, 0x66, 0xf5, 0x8f, 0x0d, 0xfb}; const std::vector<uint8_t> EpidFileParser::kEmptySigRl = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; const std::vector<uint8_t> EpidFileParser::kShortSigRlFile = { 0x02, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x92, 0xb0, 0x8b, 0x6d, 0x6b, 0xa4, 0x32, 0x4e, 0xd1, 0x83, 0x26, 0x24, 0x73, 0x70, 0x80, 0xd3, 0x72, 0xe3, 0xab, 0xfe, 0xbc, 0x86, 0x9f, 0x55, 0x9e, 0x56, 0x57, 0xa5, 0x1f, 0x06, 0x6c, 0x1b, 0x2a, 0x55, 0xb6, 0xb2, 0x13, 0xe9, 0xe8, 0x88, 0x6c, 0xbd, 0xe7, 0xca, 0x81, 0xcb, 0x92, 0x10, 0xa7, 0xef, 0xdc, 0x88, 0xf1, 0x7c, 0x91, 0x07, 0xcc, 0xf0, 0x63, 0x39, 0xae, 0x5c, 0xb9, 0x78, 0xcd, 0x54, 0xdd, 0x98, 0x3e, 0xa6, 0xc9, 0x2f, 0x83, 0x78, 0xc8, 0x64, 0xc9, 0x92, 0x41, 0x52, 0xb9, 0xf9, 0x59, 0x91, 0x46, 0x89, 0x78, 0xda,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0x41, 0xd1, 0xcd, 0xa0, 0x4f, 0xb2, 0x8c, 0xb7, 0x76, 0xc2, 0x60, 0xc8, 0xf7, 0x72, 0x98, 0xe1, 0x75, 0x3c, 0xfb, 0xd7, 0x3c, 0x7c, 0x3a, 0x91, 0x92, 0xb8, 0x83, 0x25, 0xf3, 0x3b, 0xa6, 0x64, 0x4f, 0xa7, 0x70, 0x68, 0x7c, 0xcc, 0x47, 0xdb, 0xbc, 0x0f, 0x54, 0x36, 0x2d, 0xea, 0xde, 0x6f, 0x96, 0xdc, 0xa9, 0xca, 0xa1, 0xb0, 0x80, 0x2e, 0xf8, 0x84, 0x12, 0x84, 0xf6, 0xf7, 0x8c, 0xa3, 0x45, 0xee, 0x87, 0x59, 0xd9, 0x88, 0xa4, 0xbd, 0x1f, 0x0a, 0x41, 0xd7, 0x17, 0x42, 0xc2, 0x8f, 0x46, 0x40, 0xa9, 0x3d, 0x00, 0x99, 0xb4, 0x1d, 0x8f, 0xea, 0xac, 0x86, 0xc1, 0x06, 0x03, 0x02, 0x74, 0x85, 0x78, 0xe6, 0xc3, 0x4b, 0xc1, 0x60, 0x1b, 0xf5, 0xb1, 0xda, 0xd6, 0x03, 0x75, 0xad, 0xd1, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0xcb, 0x1d, 0x80, 0xda, 0x3d, 0xd1, 0x68, 0x14, 0x90, 0xa6, 0x4a, 0x33, 0x16, 0x7c, 0x82, 0x86, 0xfb, 0xfa, 0x46, 0x14, 0x51, 0xef, 0xa5, 0x80, 0x1d, 0x97, 0x0a, 0xb6, 0x9d, 0x77, 0x69, 0x6c}; const std::vector<uint8_t> EpidFileParser::kShortSigRl = { 0x00, 0x00, 0x00, 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0xc2, 0x8f, 0x46, 0x40, 0xa9, 0x3d, 0x00, 0x99, 0xb4, 0x1d, 0x8f, 0xea, 0xac, 0x86, 0xc1, 0x06, 0x03, 0x02, 0x74, 0x85, 0x78, 0xe6, 0xc3, 0x4b, 0xc1, 0x60, 0x1b, 0xf5, 0xb1, 0xda, 0xd6, 0x03, 0x75, 0xad, 0xd1}; const std::vector<uint8_t> EpidFileParser::kEmptyPrivRlFile = { 0x02, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x47, 0x18, 0x86, 0x03, 0xfe, 0x8a, 0xb8, 0x4a, 0x9c, 0xb6, 0xcd, 0x8b, 0x1f, 0x68, 0x1c, 0x61, 0x4c, 0xa2, 0x30, 0x95, 0xec, 0x76, 0xc4, 0xa7, 0x00, 0x6c, 0x6e, 0x3c, 0xc6, 0xf9, 0x32, 0xfc}; const std::vector<uint8_t> EpidFileParser::kEmptyPrivRl = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; const std::vector<uint8_t> EpidFileParser::kShortPrivRlFile = { 0x02, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x3a, 0x03, 0xb4, 0x95, 0xd3, 0x86, 0xf7, 0xb9, 0x7e, 0x88, 0x79, 0xd8, 0xce, 0x30, 0x44, 0xf3, 0x35, 0xed, 0x0c, 0xb1, 0x80, 0x67, 0xeb, 0x1b, 0x24, 0x7f, 0xe0, 0x0c, 0xc7, 0xe8, 0xae, 0x54, 0xd1, 0xcd, 0x66, 0x2b, 0x11, 0x4e, 0x04, 0x9c, 0xe9, 0x1f, 0xac, 0xb5, 0xdd, 0x74, 0xa4, 0x9f, 0x8e, 0x66, 0x31, 0x4c, 0xde, 0xb2, 0x11, 0x25, 0xcc, 0x8e, 0xee, 0x1e, 0xa2, 0x89, 0x1a, 0xae, 0x7a, 0x98, 0x8e, 0x0a, 0xd7, 0x01, 0xc4, 0xd3, 0x49, 0xb8, 0x56, 0x9a, 0x7b, 0xf4, 0xab, 0x52, 0xb1, 0x1a, 0x84, 0xbd, 0x96, 0xd9, 0x17, 0xb0, 0xe9, 0x38, 0xff, 0xc7, 0x7a, 0x50, 0x0c, 0x8a, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x1c, 0xfb, 0xad, 0x9f, 0x47, 0x4d, 0x46, 0x53, 0x18, 0x05, 0x51, 0x04, 0x31, 0x90, 0x95, 0x33, 0x57, 0xc0, 0x19, 0x64, 0x80, 0xbf, 0x23, 0x4c, 0x92, 0xb6, 0x52, 0xd2, 0xd0, 0x05, 0xbe, 0x58}; const std::vector<uint8_t> EpidFileParser::kShortPrivRl = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x3a, 0x03, 0xb4, 0x95, 0xd3, 0x86, 0xf7, 0xb9, 0x7e, 0x88, 0x79, 0xd8, 0xce, 0x30, 0x44, 0xf3, 0x35, 0xed, 0x0c, 0xb1, 0x80, 0x67, 0xeb, 0x1b, 0x24, 0x7f, 0xe0, 0x0c, 0xc7, 0xe8, 0xae, 0x54, 0xd1, 0xcd, 0x66, 0x2b, 0x11, 0x4e, 0x04, 0x9c, 0xe9, 0x1f, 0xac, 0xb5, 0xdd, 0x74, 0xa4, 0x9f, 0x8e, 0x66, 0x31, 0x4c, 0xde, 0xb2, 0x11, 0x25, 0xcc, 0x8e, 0xee, 0x1e, 0xa2, 0x89, 0x1a, 0xae, 0x7a, 0x98, 0x8e, 0x0a, 0xd7, 0x01, 0xc4, 0xd3, 0x49, 0xb8, 0x56, 0x9a, 0x7b, 0xf4, 0xab, 0x52, 0xb1, 0x1a, 0x84, 0xbd, 0x96, 0xd9, 0x17, 0xb0, 0xe9, 0x38, 0xff, 0xc7, 0x7a, 0x50, 0x0c, 0x8a}; const std::vector<uint8_t> EpidFileParser::kGroupPublicKeyFile = { 0x02, 0x00, 0x00, 0x0c, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x89, 0x33, 0xa7, 0x86, 0xd7, 0x71, 0xcc, 0x80, 0x46, 0x4b, 0x42, 0xc3, 0xe7, 0xba, 0x1a, 0x54, 0x85, 0x8a, 0x21, 0x8e, 0x29, 0x91, 0xa9, 0x60, 0x41, 0xf9, 0xa5, 0xd9, 0x7b, 0x5f, 0x54, 0x49, 0x2a, 0x89, 0x8c, 0x10, 0x0e, 0x26, 0x0d, 0xe8, 0x36, 0x6a, 0x9e, 0x6f, 0x79, 0xff, 0xf1, 0xcd, 0xa7, 0xcd, 0xac, 0x1f, 0x92, 0x33, 0x3a, 0xd9, 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f1, 0xa9, 0x8f, 0x78, 0x45, 0x9a, 0xef, 0x1c, 0xe4, 0x45, 0x84, 0x3d, 0x8a, 0x27, 0x51, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x58, 0x2a, 0xf6, 0x06, 0xed, 0x55, 0xd6, 0x86, 0x4f, 0x99, 0x57, 0x9e, 0x8c, 0xfc, 0xea, 0x5e, 0x7d, 0xc3, 0x41, 0xa2, 0x51, 0x19, 0x47, 0x4b, 0x56, 0x4e, 0x46, 0x3e, 0xca, 0xd3, 0xb5, 0x89}; const std::vector<uint8_t> EpidFileParser::kGroupPublicKey = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x89, 0x33, 0xa7, 0x86, 0xd7, 0x71, 0xcc, 0x80, 0x46, 0x4b, 0x42, 0xc3, 0xe7, 0xba, 0x1a, 0x54, 0x85, 0x8a, 0x21, 0x8e, 0x29, 0x91, 0xa9, 0x60, 0x41, 0xf9, 0xa5, 0xd9, 0x7b, 0x5f, 0x54, 0x49, 0x2a, 0x89, 0x8c, 0x10, 0x0e, 0x26, 0x0d, 0xe8, 0x36, 0x6a, 0x9e, 0x6f, 0x79, 0xff, 0xf1, 0xcd, 0xa7, 0xcd, 0xac, 0x1f, 0x92, 0x33, 0x3a, 0xd9, 0x7c, 0xf5, 0xcd, 0x38, 0x48, 0x01, 0x4f, 0xc5, 0x6f, 0xea, 0x50, 0x60, 0x59, 0x09, 0xda, 0x44, 0x21, 0xc2, 0xd0, 0x86, 0xe6, 0x00, 0x63, 0x59, 0xa9, 0xfb, 0x35, 0x13, 0x4e, 0x13, 0xb1, 0x47, 0x36, 0xd7, 0xbd, 0xf6, 0x0a, 0x35, 0x74, 0x7d, 0x36, 0xc5, 0x67, 0xa2, 0x03, 0xb7, 0x38, 0x31, 0x16, 0xa8, 0x5d, 0x64, 0x3f, 0xe6, 0xf1, 0x94, 0x37, 0x09, 0x8c, 0x20, 0x17, 0xac, 0x2f, 0x55, 0x9e, 0xed, 0xb3, 0xc7, 0x73, 0xc0, 0x1c, 0xbb, 0xbf, 0xf7, 0x18, 0xce, 0x4f, 0xd4, 0xe3, 0x67, 0x75, 0xe4, 0xd9, 0x51, 0xfb, 0x1b, 0x22, 0xf9, 0x72, 0x2e, 0xc1, 0x76, 0x2a, 0xe1, 0x4a, 0x6e, 0x88, 0xd6, 0x2d, 0x71, 0xf4, 0xc4, 0x6d, 0xac, 0x8c, 0xbd, 0xe7, 0x2b, 0xb1, 0x40, 0x15, 0x93, 0xbd, 0x97, 0xd4, 0x84, 0x90, 0xef, 0x4e, 0xfd, 0x78, 0x25, 0xab, 0xdf, 0x16, 0xf3, 0x46, 0x52, 0x16, 0x96, 0xae, 0x50, 0x88, 0x96, 0x18, 0x73, 0xc1, 0xd1, 0x73, 0xf0, 0x67, 0xc8, 0x8d, 0xbb, 0x4e, 0xbc, 0x6a, 0x40, 0xe6, 0x1e, 0x7d, 0x36, 0x8c, 0xf4, 0xb1, 0xf1, 0x5f, 0x26, 0x4f, 0x43, 0x0a, 0x36, 0xd4, 0x67, 0xd4, 0x79, 0x3f, 0xb8, 0x69, 0x6f, 0x9c, 0x33, 0xd3, 0xdb, 0xc6, 0xce, 0x42, 0xe3, 0x46, 0x87, 0xd6, 0x65, 0xac, 0xc9, 0x71, 0xf1, 0xa9, 0x8f, 0x78, 0x45, 0x9a, 0xef, 0x1c, 0xe4, 0x45, 0x84, 0x3d, 0x8a, 0x27, 0x51}; const std::vector<uint8_t> EpidFileParser::kGroupMultiPublicKeyFile = { // Public key1 0x02, 0x00, 0x00, 0x0c, 0x01, 0x23, 0x45, 0x67,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xef, 0x4e, 0xfd, 0x78, 0x25, 0xab, 0xdf, 0x16, 0xf3, 0x46, 0x52, 0x16, 0x96, 0xae, 0x50, 0x88, 0x96, 0x18, 0x73, 0xc1, 0xd1, 0x73, 0xf0, 0x67, 0xc8, 0x8d, 0xbb, 0x4e, 0xbc, 0x6a, 0x40, 0xe6, 0x1e, 0x7d, 0x36, 0x8c, 0xf4, 0xb1, 0xf1, 0x5f, 0x26, 0x4f, 0x43, 0x0a, 0x36, 0xd4, 0x67, 0xd4, 0x79, 0x3f, 0xb8, 0x69, 0x6f, 0x9c, 0x33, 0xd3, 0xdb, 0xc6, 0xce, 0x42, 0xe3, 0x46, 0x87, 0xd6, 0x65, 0xac, 0xc9, 0x71, 0xf1, 0xa9, 0x8f, 0x78, 0x45, 0x9a, 0xef, 0x1c, 0xe4, 0x45, 0x84, 0x3d, 0x8a, 0x27, 0x51, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x58, 0x2a, 0xf6, 0x06, 0xed, 0x55, 0xd6, 0x86, 0x4f, 0x99, 0x57, 0x9e, 0x8c, 0xfc, 0xea, 0x5e, 0x7d, 0xc3, 0x41, 0xa2, 0x51, 0x19, 0x47, 0x4b, 0x56, 0x4e, 0x46, 0x3e, 0xca, 0xd3, 0xb5, 0x89, // Public key 2 0x02, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x78, 0x8a, 0xb6, 0x0f, 0x9a, 0xf5, 0xe4, 0xd1, 0xe7, 0x39, 0x6a, 0x79, 0x6c, 0xb5, 0xd1, 0xa1, 0x83, 0xec, 0xa1,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x28, 0x4d, 0xbf, 0x95, 0x88, 0x76, 0x6b, 0xb0, 0x18, 0xd8, 0x3f, 0xa6, 0x22, 0x69, 0x13, 0x06, 0xa4, 0x04, 0xbf, 0x52, 0x8e, 0xf0, 0x11, 0x99, 0x65, 0xb9, 0xf8, 0x57, 0x0b, 0xf6, 0xc2, 0xe8, 0xaf, 0xee, 0xd4, 0x6e, 0xa7, 0x49, 0x7b, 0xeb, 0x8f, 0x92, 0x66, 0x45, 0xda, 0xb4, 0x01, 0xa8, 0xee, 0x7c, 0xdf, 0x8e, 0x08, 0xdf, 0x69, 0x19, 0x8c, 0xfa, 0x23, 0x52, 0x71, 0x12, 0x10, 0xfb, 0x13, 0x2f, 0x17, 0x16, 0x9c, 0x7e, 0xc0, 0xe5, 0x22, 0x74, 0x81, 0x38, 0xed, 0x3f, 0xe1, 0x72, 0xc9, 0x46, 0x4c, 0x03, 0x7a, 0x79, 0xe0, 0x84, 0x32, 0x34, 0x59, 0x46, 0x98, 0xe7, 0xc6, 0x5f, 0xd8, 0x5f, 0xf0, 0xee, 0x1b, 0x53, 0x4c, 0xce, 0x61, 0xb7, 0x91, 0xbf, 0x71, 0xb3, 0xeb, 0x73, 0x66, 0x47, 0x28, 0x1d, 0x20}; const std::vector<uint8_t> EpidFileParser::kEmptyGroupRlFile = { 0x02, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x30, 0x9f, 0x8c, 0xae, 0x9b, 0x2a, 0xab, 0xcf, 0xb9, 0x85, 0x6f, 0x16, 0x21, 0x92, 0xb8, 0x9a, 0x31, 0x2c, 0xb8, 0x04, 0x20, 0xc8, 0x2a, 0x98, 0x8f, 0xd5, 0xaf, 0xc7, 0x27, 0xe5, 0x04, 0x0c}; const std::vector<uint8_t> EpidFileParser::kEmptyGroupRl = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; const std::vector<uint8_t> EpidFileParser::kShortGroupRlFile = { 0x02, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0xbc, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x09, 0x15, 0x86, 0xd7, 0x24, 0x47, 0xfc, 0x1e, 0x44, 0xc0, 0xfb, 0x9e, 0x4f, 0xe4, 0x92, 0x85, 0x79, 0x94, 0x9c, 0x80, 0xd1, 0xa1, 0x66, 0x34, 0x79, 0xb6, 0xb3, 0x3b, 0x66, 0xad, 0x2e, 0x40}; const std::vector<uint8_t> EpidFileParser::kShortGroupRl = { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0xbc}; ////////////////////////////////////////////////////////////////////////// // EpidParseGroupPubKeyFile Tests TEST_F(EpidFileParser, GroupPubKeyParseFailsGivenNullParameters) { GroupPubKey pubkey; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile(nullptr, this->kGroupPublicKeyFile.size(), &this->kCert, &pubkey)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), nullptr, &pubkey)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &this->kCert, nullptr)); } TEST_F(EpidFileParser, GroupPubKeyParseFailsGivenUnsupportedCurve) { GroupPubKey pubkey; EpidCaCertificate unsupported_curve1(this->kCert); unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &unsupported_curve1, &pubkey)); EpidCaCertificate unsupported_curve2(this->kCert); unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &unsupported_curve2, &pubkey)); EpidCaCertificate unsupported_curve3(this->kCert); unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &unsupported_curve3, &pubkey)); EpidCaCertificate unsupported_curve4(this->kCert); unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &unsupported_curve4, &pubkey)); EpidCaCertificate unsupported_curve5(this->kCert); unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &unsupported_curve5, &pubkey)); EpidCaCertificate unsupported_curve6(this->kCert); unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &unsupported_curve6, &pubkey)); } TEST_F(EpidFileParser, GroupPubKeyParseFailsGivenInvalidKeyInCertificate) { GroupPubKey pubkey; EpidCaCertificate invalid_key_qx(this->kCert); invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &invalid_key_qx, &pubkey)); EpidCaCertificate invalid_key_qy(this->kCert); invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] = invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &invalid_key_qy, &pubkey)); EpidCaCertificate invalid_key_qx_qy(this->kCert); invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF; invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] = invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &invalid_key_qx_qy, &pubkey)); } TEST_F(EpidFileParser, RejectsGroupPubKeyFileWithInvalidSize) { GroupPubKey pubkey; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), 0, &this->kCert, &pubkey)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size() - 1, &this->kCert, &pubkey)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile( (void*)this->kGroupMultiPublicKeyFile.data(), this->kGroupMultiPublicKeyFile.size() - 1, &this->kCert, &pubkey)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile( (void*)this->kGroupMultiPublicKeyFile.data(), this->kGroupMultiPublicKeyFile.size() + 1, &this->kCert, &pubkey)); } TEST_F(EpidFileParser, RejectsInvalidGroupPubKeyFileType) { GroupPubKey pubkey; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)this->kShortPrivRlFile.data(), this->kGroupPublicKeyFile.size(), &this->kCert, &pubkey)); } TEST_F(EpidFileParser, RejectsGroupPubKeyFileWithUnsupportedEpidVersion) { GroupPubKey pubkey; std::vector<uint8_t> unsupported_epidver_file(this->kGroupPublicKeyFile); unsupported_epidver_file[0] = {0x01}; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile((void*)unsupported_epidver_file.data(), unsupported_epidver_file.size(), &this->kCert, &pubkey)); } TEST_F(EpidFileParser, ParsesValidPubKeyFile) { std::vector<uint8_t> pubkey(sizeof(GroupPubKey), 0); EXPECT_EQ(kEpidNoErr, EpidParseGroupPubKeyFile( (void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size(), &this->kCert, (GroupPubKey*)pubkey.data())); EXPECT_EQ(this->kGroupPublicKey, pubkey); } TEST_F(EpidFileParser, ParsesValidMultiPubKeyFile) { std::vector<uint8_t> pubkey(sizeof(GroupPubKey), 0); EXPECT_EQ(kEpidNoErr, EpidParseGroupPubKeyFile( (void*)this->kGroupMultiPublicKeyFile.data(), this->kGroupMultiPublicKeyFile.size(), &this->kCert, (GroupPubKey*)pubkey.data())); EXPECT_EQ(this->kGroupPublicKey, pubkey); } TEST_F(EpidFileParser, RejectsGroupPubKeyFileWithInvalidSignature) { GroupPubKey pubkey; std::vector<uint8_t> pubkey_inv_sign(this->kGroupPublicKeyFile); pubkey_inv_sign[pubkey_inv_sign.size() - 1] = pubkey_inv_sign[pubkey_inv_sign.size() - 1] ^ 0xFF; EXPECT_EQ( kEpidSigInvalid, EpidParseGroupPubKeyFile((void*)pubkey_inv_sign.data(), pubkey_inv_sign.size(), &this->kCert, &pubkey)); } ////////////////////////////////////////////////////////////////////////// // EpidParsePrivRlFile Tests TEST_F(EpidFileParser, PrivRlParseProvidesRequiredLenWithNullDest) { size_t rl_len = 0; EXPECT_EQ(kEpidNoErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, nullptr, &rl_len)); EXPECT_EQ(this->kShortPrivRl.size(), rl_len); } TEST_F(EpidFileParser, PrivRlParseFailsGivenNullParameters) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); // null input buffer EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile(nullptr, this->kShortPrivRlFile.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); // null cert EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), nullptr, (PrivRl*)rl.data(), &rl_len)); // null rl_length EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, (PrivRl*)rl.data(), nullptr)); // null rl_length with null dest EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, nullptr, nullptr)); } TEST_F(EpidFileParser, PrivRlParseFailsGivenUnsupportedCurve) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); EpidCaCertificate unsupported_curve(kCert); unsupported_curve.a.data[0] = unsupported_curve.a.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &unsupported_curve, (PrivRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve2(kCert); unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &unsupported_curve2, (PrivRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve3(kCert); unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &unsupported_curve3, (PrivRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve4(kCert); unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &unsupported_curve4, (PrivRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve5(kCert); unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &unsupported_curve5, (PrivRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve6(kCert); unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &unsupported_curve6, (PrivRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, PrivRlParseFailsGivenInvalidKeyInCertificate) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); EpidCaCertificate invalid_key_qx(kCert); invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &invalid_key_qx, (PrivRl*)rl.data(), &rl_len)); EpidCaCertificate invalid_key_qy(kCert); invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] = invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &invalid_key_qy, (PrivRl*)rl.data(), &rl_len)); EpidCaCertificate invalid_key_qx_qy(kCert); invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF; invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] = invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &invalid_key_qx_qy, (PrivRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsPrivRlFileWithInvalidSize) { size_t rl_len = this->kEmptyPrivRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(), this->kEmptyPrivRlFile.size() - 1, &this->kCert, (PrivRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(), 0, &this->kCert, (PrivRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsInvalidPrivRlFileType) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsPrivRlFileWithUnsupportedEpidVersion) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); std::vector<uint8_t> unsupported_epidver_file(this->kShortPrivRlFile); unsupported_epidver_file[0] = {0x01}; EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)unsupported_epidver_file.data(), unsupported_epidver_file.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, ParsesEmptyPrivRl) { size_t rl_len = this->kEmptyPrivRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(), this->kEmptyPrivRlFile.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); EXPECT_EQ(this->kEmptyPrivRl, rl); } TEST_F(EpidFileParser, ParsesShortPrivRl) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); EXPECT_EQ(this->kShortPrivRl, rl); } TEST_F(EpidFileParser, ParsesLongPrivRl) { EcdsaSignature signature = { 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x02, 0xd7, 0x14, 0x3e, 0xce, 0x36, 0x24, 0xb2, 0xe5, 0x14, 0x94, 0x17, 0xdf, 0x8d, 0x0f, 0xda, 0xff, 0x8c, 0xb9, 0x7f, 0xb6, 0x05, 0x09, 0x08, 0x80, 0xb0, 0xb8, 0x45, 0x92, 0x15, 0xb6, 0x08, }; std::vector<uint8_t> long_privrl_file = {// Intel(R) EPID Version 0x02, 0x00, // File Type 0x00, 0x0d, // Group ID 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, // Revocation list version number 0x00, 0x00, 0x00, 0x00, // Number of entries 0x00, 0x00, 0x00, 0x32}; const std::vector<uint8_t> FToCreateLongRl = { 0x8a, 0xdc, 0xc0, 0xc8, 0xcd, 0x29, 0x9e, 0x08, 0x9e, 0x4e, 0x0d, 0xa7, 0xf6, 0x46, 0xee, 0x80, 0xca, 0x91, 0x86, 0x54, 0x3c, 0x7f, 0x8d, 0xb5, 0x49, 0xf9, 0x6d, 0x00, 0x39, 0x39, 0x62, 0xc7, }; for (int i = 0; i < 50; ++i) { for (auto it : FToCreateLongRl) { long_privrl_file.push_back(it); } } for (auto it : signature.x.data) { long_privrl_file.push_back(it); } for (auto it : signature.y.data) { long_privrl_file.push_back(it); } size_t rl_len = long_privrl_file.size() - 68; std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParsePrivRlFile((void*)long_privrl_file.data(), long_privrl_file.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); EXPECT_EQ( std::vector<uint8_t>(&long_privrl_file[4], &long_privrl_file[long_privrl_file.size() - 64]), rl); } TEST_F(EpidFileParser, RejectsPrivRlFileWithInvalidSignature) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); std::vector<uint8_t> privrl_inv_sign(kShortPrivRlFile); privrl_inv_sign[privrl_inv_sign.size() - 1] = privrl_inv_sign[privrl_inv_sign.size() - 1] ^ 0xFF; EXPECT_EQ(kEpidSigInvalid, EpidParsePrivRlFile(privrl_inv_sign.data(), privrl_inv_sign.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, PrivRlParseRejectsBufWithInsufficientSize) { size_t rl_len = this->kShortPrivRl.size() - 1; std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, (PrivRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, ReturnsProperSizeGivenOversizedPrivRlBuf) { size_t rl_len = this->kShortPrivRl.size() + 1; std::vector<uint8_t> oversized_rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, (PrivRl*)oversized_rl.data(), &rl_len)); std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1); EXPECT_EQ(this->kShortPrivRl, rl); EXPECT_EQ(this->kShortPrivRl.size(), rl_len); } ////////////////////////////////////////////////////////////////////////// // EpidParseSigRlFile Tests TEST_F(EpidFileParser, SigRlParseProvidesRequiredLenWithNullDest) { size_t rl_len = 0; EXPECT_EQ(kEpidNoErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &kCert, nullptr, &rl_len)); EXPECT_EQ(rl_len, this->kShortSigRl.size()); } TEST_F(EpidFileParser, SigRlParseFailsGivenNullParameters) { size_t rl_len = this->kShortSigRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile(nullptr, this->kShortSigRlFile.size(), &kCert, (SigRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), nullptr, (SigRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &kCert, (SigRl*)rl.data(), nullptr)); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &kCert, nullptr, nullptr)); } TEST_F(EpidFileParser, SigRlParseFailsGivenUnsupportedCurve) { size_t rl_len = this->kShortSigRl.size(); std::vector<uint8_t> rl(rl_len); EpidCaCertificate unsupported_curve1(kCert); unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &unsupported_curve1, (SigRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve2(kCert); unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &unsupported_curve2, (SigRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve3(kCert); unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &unsupported_curve3, (SigRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve4(kCert); unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &unsupported_curve4, (SigRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve5(kCert); unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &unsupported_curve5, (SigRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve6(kCert); unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &unsupported_curve6, (SigRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, SigRlParseFailsGivenInvalidKeyInCertificate) { size_t rl_len = this->kShortSigRl.size(); std::vector<uint8_t> rl(rl_len); EpidCaCertificate invalid_key_qx(kCert); invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &invalid_key_qx, (SigRl*)rl.data(), &rl_len)); EpidCaCertificate invalid_key_qy(kCert); invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] = invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &invalid_key_qy, (SigRl*)rl.data(), &rl_len)); EpidCaCertificate invalid_key_qx_qy(kCert); invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF; invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] = invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &invalid_key_qx_qy, (SigRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsSigRlFileWithInvalidSize) { size_t rl_len = this->kEmptySigRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kEmptySigRlFile.data(), 0, &this->kCert, (SigRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kEmptySigRlFile.data(), this->kEmptySigRlFile.size() - 1, &this->kCert, (SigRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kEmptySigRlFile.size() + 1, &this->kCert, (SigRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, SigRlParseRejectsInvalidSigRlFileType) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, (SigRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsSigRlFileWithUnsupportedEpidVersion) { size_t rl_len = this->kShortSigRl.size(); std::vector<uint8_t> rl(rl_len); std::vector<uint8_t> unsupported_epidver_file(this->kShortSigRlFile); unsupported_epidver_file[0] = {0x01}; EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)unsupported_epidver_file.data(), unsupported_epidver_file.size(), &this->kCert, (SigRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, ParsesEmptySigRl) { size_t rl_len = this->kEmptySigRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseSigRlFile(this->kEmptySigRlFile.data(), this->kEmptySigRlFile.size(), &this->kCert, (SigRl*)rl.data(), &rl_len)); EXPECT_EQ(rl, this->kEmptySigRl); } TEST_F(EpidFileParser, ParsesShortSigRl) { size_t rl_len = this->kShortSigRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseSigRlFile(this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &this->kCert, (SigRl*)rl.data(), &rl_len)); EXPECT_EQ(rl, this->kShortSigRl); } TEST_F(EpidFileParser, ParsesLongSigRl) { std::vector<uint8_t> b = { 0x92, 0xb0, 0x8b, 0x6d, 0x6b, 0xa4, 0x32, 0x4e, 0xd1, 0x83, 0x26, 0x24, 0x73, 0x70, 0x80, 0xd3, 0x72, 0xe3, 0xab, 0xfe, 0xbc, 0x86, 0x9f, 0x55, 0x9e, 0x56, 0x57, 0xa5, 0x1f, 0x06, 0x6c, 0x1b, 0x2a, 0x55, 0xb6, 0xb2, 0x13, 0xe9, 0xe8, 0x88, 0x6c, 0xbd, 0xe7, 0xca, 0x81, 0xcb, 0x92, 0x10, 0xa7, 0xef, 0xdc, 0x88, 0xf1, 0x7c, 0x91, 0x07, 0xcc, 0xf0, 0x63, 0x39, 0xae, 0x5c, 0xb9, 0x78, 0xcd, 0x54, 0xdd, 0x98, 0x3e, 0xa6, 0xc9, 0x2f, 0x83, 0x78, 0xc8, 0x64, 0xc9, 0x92, 0x41, 0x52, 0xb9, 0xf9, 0x59, 0x91, 0x46, 0x89, 0x78, 0xda, 0xc3, 0x26, 0xdd, 0x9d, 0x1f, 0x0c, 0x8e, 0xea, 0xba, 0xa8, 0xde, 0xa5, 0x33, 0x8c, 0x2e, 0xaa, 0x0e, 0x2c, 0x13, 0x36, 0xb3, 0x7b, 0xa6, 0x12, 0x98, 0x0a, 0x13, 0x35, 0xa3, 0x9e, 0x52, 0xaf, 0x43, 0xf4, 0x1c, 0x79, 0xcf, 0x46, 0xc6, 0xcd}; EcdsaSignature signature = { 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x35, 0xb4, 0x20, 0x07, 0x4e, 0xed, 0xc3, 0xb1, 0x60, 0xd8, 0x78, 0x32, 0xb3, 0xa0, 0x8e, 0xc2, 0xab, 0xdb, 0x46, 0x6b, 0x03, 0x94, 0xd7, 0x90, 0xd3, 0xfd, 0xd3, 0x5a, 0x9a, 0xc3, 0x66, 0xab, }; std::vector<uint8_t> long_sigrl_file = { // Intel(R) EPID Version 0x02, 0x00, // File Type 0x00, 0x0e, // Group ID 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, // Revocation list version number 0x00, 0x00, 0x00, 0x03, // Number of revocation list entries N 0x00, 0x00, 0x00, 0x32, }; for (int i = 0; i < 50; ++i) { for (auto it : b) { long_sigrl_file.push_back(it); } } for (auto it : signature.x.data) { long_sigrl_file.push_back(it); } for (auto it : signature.y.data) { long_sigrl_file.push_back(it); } size_t rl_len = long_sigrl_file.size() - sizeof(signature) - 4; std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseSigRlFile(long_sigrl_file.data(), long_sigrl_file.size(), &this->kCert, (SigRl*)rl.data(), &rl_len)); std::vector<uint8_t> expected_long_sig_rl(std::vector<uint8_t>( &long_sigrl_file[4], &long_sigrl_file[long_sigrl_file.size() - sizeof(signature)])); EXPECT_EQ(expected_long_sig_rl, rl); } TEST_F(EpidFileParser, RejectsSigRlFileWithInvalidSignature) { size_t rl_len = this->kShortSigRl.size(); std::vector<uint8_t> rl(rl_len); std::vector<uint8_t> sigrl_inv_sign(kShortSigRlFile); sigrl_inv_sign[sigrl_inv_sign.size() - 1] = sigrl_inv_sign[sigrl_inv_sign.size() - 1] ^ 0xFF; EXPECT_EQ( kEpidSigInvalid, EpidParseSigRlFile((void*)sigrl_inv_sign.data(), sigrl_inv_sign.size(), &this->kCert, (SigRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, SigRlParseRejectsBufWithInsufficientSize) { size_t rl_len = this->kShortSigRl.size() - 1; std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &this->kCert, (SigRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, ReturnsProperSizeGivenOversizedSigRlBuf) { size_t rl_len = this->kShortSigRl.size() + 1; std::vector<uint8_t> oversized_rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(), this->kShortSigRlFile.size(), &this->kCert, (SigRl*)oversized_rl.data(), &rl_len)); std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1); EXPECT_EQ(this->kShortSigRl, rl); EXPECT_EQ(this->kShortSigRl.size(), rl_len); } ////////////////////////////////////////////////////////////////////////// // EpidParseGroupRlFile Tests TEST_F(EpidFileParser, GroupRlParseProvidesRequiredLenWithNullDest) { size_t rl_len = 0; EXPECT_EQ(kEpidNoErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &kCert, nullptr, &rl_len)); EXPECT_EQ(rl_len, this->kShortGroupRl.size()); } TEST_F(EpidFileParser, GroupRlParseFailsGivenNullParameters) { size_t rl_len = this->kShortGroupRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile(nullptr, this->kShortGroupRlFile.size(), &kCert, (GroupRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), nullptr, (GroupRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &kCert, (GroupRl*)rl.data(), nullptr)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &kCert, nullptr, nullptr)); } TEST_F(EpidFileParser, GroupRlParseFailsGivenUnsupportedCurve) { size_t rl_len = this->kShortGroupRl.size(); std::vector<uint8_t> rl(rl_len); EpidCaCertificate unsupported_curve1(kCert); unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &unsupported_curve1, (GroupRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve2(kCert); unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &unsupported_curve2, (GroupRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve3(kCert); unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &unsupported_curve3, (GroupRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve4(kCert); unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &unsupported_curve4, (GroupRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve5(kCert); unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &unsupported_curve5, (GroupRl*)rl.data(), &rl_len)); EpidCaCertificate unsupported_curve6(kCert); unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &unsupported_curve6, (GroupRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, GroupRlParseFailsGivenInvalidKeyInCertificate) { size_t rl_len = this->kShortGroupRl.size(); std::vector<uint8_t> rl(rl_len); EpidCaCertificate invalid_key_qx(kCert); invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile( (void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &invalid_key_qx, (GroupRl*)rl.data(), &rl_len)); EpidCaCertificate invalid_key_qy(kCert); invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] = invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile( (void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &invalid_key_qy, (GroupRl*)rl.data(), &rl_len)); EpidCaCertificate invalid_key_qx_qy(kCert); invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF; invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] = invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^ 0xFF; EXPECT_EQ( kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &invalid_key_qx_qy, (GroupRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsGroupRlFileWithInvalidSize) { size_t rl_len = this->kEmptyGroupRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kEmptyGroupRlFile.data(), 0, &this->kCert, (GroupRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kEmptyGroupRlFile.data(), this->kEmptyGroupRlFile.size() - 1, &this->kCert, (GroupRl*)rl.data(), &rl_len)); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kEmptyGroupRlFile.size() + 1, &this->kCert, (GroupRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsInvalidGroupRlFileType) { size_t rl_len = this->kShortPrivRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortPrivRlFile.data(), this->kShortPrivRlFile.size(), &this->kCert, (GroupRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, RejectsGroupRlFileWithUnsupportedEpidVersion) { size_t rl_len = this->kShortGroupRl.size(); std::vector<uint8_t> rl(rl_len); std::vector<uint8_t> unsupported_epidver_file(this->kShortGroupRlFile); unsupported_epidver_file[0] = {0x01}; EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)unsupported_epidver_file.data(), unsupported_epidver_file.size(), &this->kCert, (GroupRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, ParsesEmptyGroupRl) { size_t rl_len = this->kEmptyGroupRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseGroupRlFile(this->kEmptyGroupRlFile.data(), this->kEmptyGroupRlFile.size(), &this->kCert, (GroupRl*)rl.data(), &rl_len)); EXPECT_EQ(rl, this->kEmptyGroupRl); } TEST_F(EpidFileParser, ParsesShortGroupRl) { size_t rl_len = this->kShortGroupRl.size(); std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseGroupRlFile(this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &this->kCert, (GroupRl*)rl.data(), &rl_len)); EXPECT_EQ(rl, this->kShortGroupRl); } TEST_F(EpidFileParser, ParsesLongGroupRl) { std::vector<uint8_t> gid = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0xbc}; EcdsaSignature signature = { 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0xa4, 0xaa, 0x8c, 0x1c, 0x91, 0xa2, 0x57, 0x07, 0x67, 0x0e, 0x58, 0xae, 0xc7, 0x25, 0x15, 0x36, 0xda, 0xa0, 0xea, 0xc1, 0x15, 0x2b, 0xf2, 0xc2, 0x33, 0x43, 0x3f, 0xc6, 0x56, 0xc1, 0x57, 0xbd, }; std::vector<uint8_t> long_grouprl_file = { /// Intel(R) EPID Version 0x02, 0x00, // File type 0x00, 0x0f, // RLver: revocation list version number 0x00, 0x00, 0x00, 0x01, // n3: number of entries in GroupRL 0x00, 0x00, 0x00, 0x32, }; for (int i = 0; i < 50; ++i) { for (auto it : gid) { long_grouprl_file.push_back(it); } } for (auto it : signature.x.data) { long_grouprl_file.push_back(it); } for (auto it : signature.y.data) { long_grouprl_file.push_back(it); } size_t rl_len = long_grouprl_file.size() - sizeof(signature) - 4; std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseGroupRlFile( long_grouprl_file.data(), long_grouprl_file.size(), &this->kCert, (GroupRl*)rl.data(), &rl_len)); std::vector<uint8_t> expected_long_gr_rl(std::vector<uint8_t>( &long_grouprl_file[4], &long_grouprl_file[long_grouprl_file.size() - sizeof(signature)])); EXPECT_EQ(expected_long_gr_rl, rl); } TEST_F(EpidFileParser, RejectsGroupRlFileWithInvalidSignature) { size_t rl_len = this->kShortGroupRl.size(); std::vector<uint8_t> rl(rl_len); std::vector<uint8_t> grouprl_inv_sign(this->kShortGroupRlFile); grouprl_inv_sign[grouprl_inv_sign.size() - 1] = grouprl_inv_sign[grouprl_inv_sign.size() - 1] ^ 0xFF; EXPECT_EQ(kEpidSigInvalid, EpidParseGroupRlFile((void*)grouprl_inv_sign.data(), grouprl_inv_sign.size(), &this->kCert, (GroupRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, GroupRlParseRejectsBufWithInsufficientSize) { size_t rl_len = this->kShortGroupRl.size() - 1; std::vector<uint8_t> rl(rl_len); EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &this->kCert, (GroupRl*)rl.data(), &rl_len)); } TEST_F(EpidFileParser, ReturnsProperSizeGivenOversizedGroupRlBuf) { size_t rl_len = this->kShortGroupRl.size() + 1; std::vector<uint8_t> oversized_rl(rl_len); EXPECT_EQ(kEpidNoErr, EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(), this->kShortGroupRlFile.size(), &this->kCert, (GroupRl*)oversized_rl.data(), &rl_len)); std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1); EXPECT_EQ(this->kShortGroupRl, rl); EXPECT_EQ(this->kShortGroupRl.size(), rl_len); } ////////////////////////////////////////////////////////////////////////// // EpidParseFileHeader Tests TEST_F(EpidFileParser, ParseFileHeaderFailsGivenNullInParameters) { EpidVersion epid_version = kNumEpidVersions; EpidFileType file_type = kNumFileTypes; EXPECT_EQ(kEpidBadArgErr, EpidParseFileHeader(nullptr, sizeof(EpidFileHeader), &epid_version, &file_type)); } TEST_F(EpidFileParser, ParseFileHeaderFailsGivenInvalidSize) { EpidVersion epid_version = kNumEpidVersions; EpidFileType file_type = kNumFileTypes; EpidFileHeader epid_header = this->kCert.header; EXPECT_EQ(kEpidBadArgErr, EpidParseFileHeader((void*)&epid_header, sizeof(epid_header) - 1, &epid_version, &file_type)); } TEST_F(EpidFileParser, ParseFileHeaderReportsUnknownEpidVersion) { // Since this variable must contain kNumEpidVersions after the function call, // assign something different from kNumEpidVersions EpidVersion epid_version = kEpid1x; EpidFileType file_type = kNumFileTypes; EpidFileHeader epid_header = this->kCert.header; epid_header.epid_version.data[0] = 0x00; EXPECT_EQ(kEpidNoErr, EpidParseFileHeader((void*)&epid_header, sizeof(epid_header), &epid_version, &file_type)); EXPECT_EQ(kNumEpidVersions, epid_version); EXPECT_EQ(kIssuingCaPubKeyFile, file_type); } TEST_F(EpidFileParser, ParseFileHeaderReportsUnknownFileType) { EpidVersion epid_version = kNumEpidVersions; // Since this variable must contain kNumFileTypes after the function call, // assign something not kNumFileTypes EpidFileType file_type = kIssuingCaPubKeyFile; EpidFileHeader epid_header = this->kCert.header; epid_header.file_type.data[1] = 0x00; EXPECT_EQ(kEpidNoErr, EpidParseFileHeader((void*)&epid_header, sizeof(epid_header), &epid_version, &file_type)); EXPECT_EQ(kEpid2x, epid_version); EXPECT_EQ(kNumFileTypes, file_type); } TEST_F(EpidFileParser, ParseFileHeaderCanSkipExtractingSomeValues) { EpidVersion epid_version = kNumEpidVersions; EpidFileType file_type = kNumFileTypes; EpidFileHeader epid_header = this->kCert.header; EXPECT_EQ(kEpidNoErr, EpidParseFileHeader((void*)&epid_header, sizeof(epid_header), nullptr, &file_type)); EXPECT_EQ(kIssuingCaPubKeyFile, file_type); EXPECT_EQ(kEpidNoErr, EpidParseFileHeader((void*)&epid_header, sizeof(epid_header), &epid_version, nullptr)); EXPECT_EQ(kEpid2x, epid_version); EXPECT_EQ(kEpidNoErr, EpidParseFileHeader((void*)&epid_header, sizeof(epid_header), nullptr, nullptr)); } TEST_F(EpidFileParser, ParseFileHeaderParsesCorrectly) { EpidVersion epid_version = kNumEpidVersions; EpidFileType file_type = kNumFileTypes; EpidFileHeader epid_header = this->kCert.header; EXPECT_EQ(kEpidNoErr, EpidParseFileHeader((void*)&epid_header, sizeof(epid_header), &epid_version, &file_type)); EXPECT_EQ(kEpid2x, epid_version); EXPECT_EQ(kIssuingCaPubKeyFile, file_type); EpidFileHeader epid_header2 = {0x01, 0x00, 0x00, 0x0B}; EXPECT_EQ(kEpidNoErr, EpidParseFileHeader((void*)&epid_header2, sizeof(epid_header2), &epid_version, &file_type)); EXPECT_EQ(kEpid1x, epid_version); EXPECT_EQ(kSigRlRequestFile, file_type); } } // namespace