file_parser-test.cc 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  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 Issuer material file parsing unit tests.
  19. */
  20. #include <cstdint>
  21. #include <vector>
  22. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  23. #include "gtest/gtest.h"
  24. extern "C" {
  25. #include "epid/common/file_parser.h"
  26. }
  27. namespace {
  28. /// Test fixture class for EpidFileParser
  29. class EpidFileParser : public ::testing::Test {
  30. public:
  31. /// Cert used to sign legitimate test data
  32. static const EpidCaCertificate kCert;
  33. /// A file with short GroupPublicKey signed with kCert
  34. static const std::vector<uint8_t> kGroupPublicKeyFile;
  35. /// A file with two Epid11GroupPublicKey signed with kCert
  36. static const std::vector<uint8_t> kGroupMultiPublicKeyFile;
  37. /// Expected short GroupPublicKey
  38. static const std::vector<uint8_t> kGroupPublicKey;
  39. /// A file with short privrl signed with cert
  40. static const std::vector<uint8_t> kShortPrivRlFile;
  41. /// Expected short privrl
  42. static const std::vector<uint8_t> kShortPrivRl;
  43. /// A file with empty privrl signed with cert
  44. static const std::vector<uint8_t> kEmptyPrivRlFile;
  45. /// Expected empty privrl
  46. static const std::vector<uint8_t> kEmptyPrivRl;
  47. /// A file with empty SigRl signed with kCert
  48. static const std::vector<uint8_t> kEmptySigRlFile;
  49. /// Expected empty SigRl
  50. static const std::vector<uint8_t> kEmptySigRl;
  51. /// A file with short SigRl signed with kCert
  52. static const std::vector<uint8_t> kShortSigRlFile;
  53. /// Expected short SigRl
  54. static const std::vector<uint8_t> kShortSigRl;
  55. /// A file with empty GroupRl signed with kCert
  56. static const std::vector<uint8_t> kEmptyGroupRlFile;
  57. /// Expected empty GroupRl
  58. static const std::vector<uint8_t> kEmptyGroupRl;
  59. /// A file with short GroupRl signed with kCert
  60. static const std::vector<uint8_t> kShortGroupRlFile;
  61. /// Expected short GroupRl
  62. static const std::vector<uint8_t> kShortGroupRl;
  63. };
  64. const EpidCaCertificate EpidFileParser::kCert = {
  65. 0x02, 0x00, 0x00, 0x11, 0x24, 0x42, 0xa5, 0xcc, 0x0e, 0xcd, 0x01, 0x5f,
  66. 0xa3, 0xca, 0x31, 0xdc, 0x8e, 0x2b, 0xbc, 0x70, 0xbf, 0x42, 0xd6, 0x0c,
  67. 0xbc, 0xa2, 0x00, 0x85, 0xe0, 0x82, 0x2c, 0xb0, 0x42, 0x35, 0xe9, 0x70,
  68. 0x6f, 0xc9, 0x8b, 0xd7, 0xe5, 0x02, 0x11, 0xa4, 0xa2, 0x71, 0x02, 0xfa,
  69. 0x35, 0x49, 0xdf, 0x79, 0xeb, 0xcb, 0x4b, 0xf2, 0x46, 0xb8, 0x09, 0x45,
  70. 0xcd, 0xdf, 0xe7, 0xd5, 0x09, 0xbb, 0xfd, 0x7d, 0xff, 0xff, 0xff, 0xff,
  71. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  73. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01,
  74. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
  76. 0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7, 0xb3, 0xeb, 0xbd, 0x55,
  77. 0x76, 0x98, 0x86, 0xbc, 0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53, 0xb0, 0xf6,
  78. 0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b, 0x6b, 0x17, 0xd1, 0xf2,
  79. 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
  80. 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45,
  81. 0xd8, 0x98, 0xc2, 0x96, 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
  82. 0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57,
  83. 0x6b, 0x31, 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  84. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  85. 0xff, 0xff, 0xff, 0xff, 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84,
  86. 0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51, 0xfb, 0x57, 0x6f, 0x15,
  87. 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b,
  88. 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32,
  89. 0xb9, 0x3a, 0x76, 0xe7, 0x94, 0x03, 0x1d, 0x90, 0x6b, 0x6f, 0xcd, 0x99,
  90. 0xef, 0x2c, 0xdb, 0x8b, 0xa9, 0x8a, 0xef, 0x7e, 0xf0, 0x77, 0xba, 0xb5,
  91. 0x11, 0x43, 0x0d, 0x28, 0x1c, 0x01, 0x5b, 0xc9, 0x08, 0xce, 0x3e, 0x68};
  92. const std::vector<uint8_t> EpidFileParser::kEmptySigRlFile = {
  93. 0x02, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00,
  95. 0x00, 0x00, 0x00, 0x00, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47,
  96. 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9,
  97. 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7,
  98. 0x7d, 0x04, 0xa1, 0x29, 0x28, 0xc3, 0x4d, 0x30, 0x8d, 0x67, 0xe4, 0xe8,
  99. 0x62, 0x71, 0xe8, 0x4f, 0x0d, 0x45, 0x46, 0xc9, 0xde, 0x67, 0x30, 0x47,
  100. 0xb5, 0xfb, 0xb5, 0x66, 0xf5, 0x8f, 0x0d, 0xfb};
  101. const std::vector<uint8_t> EpidFileParser::kEmptySigRl = {
  102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  103. 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  104. const std::vector<uint8_t> EpidFileParser::kShortSigRlFile = {
  105. 0x02, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x03,
  107. 0x00, 0x00, 0x00, 0x03, 0x92, 0xb0, 0x8b, 0x6d, 0x6b, 0xa4, 0x32, 0x4e,
  108. 0xd1, 0x83, 0x26, 0x24, 0x73, 0x70, 0x80, 0xd3, 0x72, 0xe3, 0xab, 0xfe,
  109. 0xbc, 0x86, 0x9f, 0x55, 0x9e, 0x56, 0x57, 0xa5, 0x1f, 0x06, 0x6c, 0x1b,
  110. 0x2a, 0x55, 0xb6, 0xb2, 0x13, 0xe9, 0xe8, 0x88, 0x6c, 0xbd, 0xe7, 0xca,
  111. 0x81, 0xcb, 0x92, 0x10, 0xa7, 0xef, 0xdc, 0x88, 0xf1, 0x7c, 0x91, 0x07,
  112. 0xcc, 0xf0, 0x63, 0x39, 0xae, 0x5c, 0xb9, 0x78, 0xcd, 0x54, 0xdd, 0x98,
  113. 0x3e, 0xa6, 0xc9, 0x2f, 0x83, 0x78, 0xc8, 0x64, 0xc9, 0x92, 0x41, 0x52,
  114. 0xb9, 0xf9, 0x59, 0x91, 0x46, 0x89, 0x78, 0xda, 0xc3, 0x26, 0xdd, 0x9d,
  115. 0x1f, 0x0c, 0x8e, 0xea, 0xba, 0xa8, 0xde, 0xa5, 0x33, 0x8c, 0x2e, 0xaa,
  116. 0x0e, 0x2c, 0x13, 0x36, 0xb3, 0x7b, 0xa6, 0x12, 0x98, 0x0a, 0x13, 0x35,
  117. 0xa3, 0x9e, 0x52, 0xaf, 0x43, 0xf4, 0x1c, 0x79, 0xcf, 0x46, 0xc6, 0xcd,
  118. 0xc4, 0xc4, 0x0d, 0x19, 0xac, 0x77, 0xc7, 0x12, 0xcb, 0x22, 0x4a, 0x65,
  119. 0xdb, 0x26, 0xcb, 0x1b, 0x27, 0xbf, 0x25, 0x6f, 0x47, 0xff, 0x2e, 0x59,
  120. 0x11, 0x72, 0x0f, 0x42, 0x70, 0x64, 0xd0, 0x78, 0x6c, 0x09, 0xe6, 0xce,
  121. 0xd4, 0xd9, 0x7b, 0x80, 0x9a, 0xe9, 0x3e, 0x8f, 0x73, 0x77, 0x84, 0x67,
  122. 0x1f, 0xf2, 0x74, 0xbc, 0xcf, 0x9c, 0xb4, 0x58, 0xaa, 0xe2, 0x7b, 0x6f,
  123. 0xb6, 0xfe, 0x9a, 0x40, 0x1e, 0x84, 0xab, 0x5f, 0xe8, 0x73, 0xc6, 0x87,
  124. 0xcc, 0x9b, 0xb4, 0xf4, 0xd9, 0x5a, 0x9c, 0x2d, 0xea, 0xf3, 0x04, 0x9f,
  125. 0xc3, 0xbf, 0x2a, 0xf2, 0x9d, 0xe5, 0x38, 0x2c, 0xf2, 0xcc, 0x46, 0xd9,
  126. 0x3e, 0x52, 0xb2, 0x3e, 0x49, 0xf4, 0x08, 0x14, 0x10, 0x31, 0x9c, 0xeb,
  127. 0x10, 0xe5, 0x26, 0xaa, 0x4d, 0x76, 0x12, 0xb2, 0xc3, 0x8e, 0x15, 0x4b,
  128. 0x28, 0x51, 0xe9, 0x30, 0x00, 0x2c, 0x74, 0xb1, 0x33, 0x71, 0x1c, 0x19,
  129. 0xb8, 0x6b, 0x5c, 0xde, 0x30, 0x4f, 0x36, 0x29, 0x29, 0xaf, 0x1d, 0x41,
  130. 0xd1, 0xcd, 0xa0, 0x4f, 0xb2, 0x8c, 0xb7, 0x76, 0xc2, 0x60, 0xc8, 0xf7,
  131. 0x72, 0x98, 0xe1, 0x75, 0x3c, 0xfb, 0xd7, 0x3c, 0x7c, 0x3a, 0x91, 0x92,
  132. 0xb8, 0x83, 0x25, 0xf3, 0x3b, 0xa6, 0x64, 0x4f, 0xa7, 0x70, 0x68, 0x7c,
  133. 0xcc, 0x47, 0xdb, 0xbc, 0x0f, 0x54, 0x36, 0x2d, 0xea, 0xde, 0x6f, 0x96,
  134. 0xdc, 0xa9, 0xca, 0xa1, 0xb0, 0x80, 0x2e, 0xf8, 0x84, 0x12, 0x84, 0xf6,
  135. 0xf7, 0x8c, 0xa3, 0x45, 0xee, 0x87, 0x59, 0xd9, 0x88, 0xa4, 0xbd, 0x1f,
  136. 0x0a, 0x41, 0xd7, 0x17, 0x42, 0xc2, 0x8f, 0x46, 0x40, 0xa9, 0x3d, 0x00,
  137. 0x99, 0xb4, 0x1d, 0x8f, 0xea, 0xac, 0x86, 0xc1, 0x06, 0x03, 0x02, 0x74,
  138. 0x85, 0x78, 0xe6, 0xc3, 0x4b, 0xc1, 0x60, 0x1b, 0xf5, 0xb1, 0xda, 0xd6,
  139. 0x03, 0x75, 0xad, 0xd1, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47,
  140. 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9,
  141. 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7,
  142. 0xcb, 0x1d, 0x80, 0xda, 0x3d, 0xd1, 0x68, 0x14, 0x90, 0xa6, 0x4a, 0x33,
  143. 0x16, 0x7c, 0x82, 0x86, 0xfb, 0xfa, 0x46, 0x14, 0x51, 0xef, 0xa5, 0x80,
  144. 0x1d, 0x97, 0x0a, 0xb6, 0x9d, 0x77, 0x69, 0x6c};
  145. const std::vector<uint8_t> EpidFileParser::kShortSigRl = {
  146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  147. 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03,
  148. 0x92, 0xb0, 0x8b, 0x6d, 0x6b, 0xa4, 0x32, 0x4e, 0xd1, 0x83, 0x26, 0x24,
  149. 0x73, 0x70, 0x80, 0xd3, 0x72, 0xe3, 0xab, 0xfe, 0xbc, 0x86, 0x9f, 0x55,
  150. 0x9e, 0x56, 0x57, 0xa5, 0x1f, 0x06, 0x6c, 0x1b, 0x2a, 0x55, 0xb6, 0xb2,
  151. 0x13, 0xe9, 0xe8, 0x88, 0x6c, 0xbd, 0xe7, 0xca, 0x81, 0xcb, 0x92, 0x10,
  152. 0xa7, 0xef, 0xdc, 0x88, 0xf1, 0x7c, 0x91, 0x07, 0xcc, 0xf0, 0x63, 0x39,
  153. 0xae, 0x5c, 0xb9, 0x78, 0xcd, 0x54, 0xdd, 0x98, 0x3e, 0xa6, 0xc9, 0x2f,
  154. 0x83, 0x78, 0xc8, 0x64, 0xc9, 0x92, 0x41, 0x52, 0xb9, 0xf9, 0x59, 0x91,
  155. 0x46, 0x89, 0x78, 0xda, 0xc3, 0x26, 0xdd, 0x9d, 0x1f, 0x0c, 0x8e, 0xea,
  156. 0xba, 0xa8, 0xde, 0xa5, 0x33, 0x8c, 0x2e, 0xaa, 0x0e, 0x2c, 0x13, 0x36,
  157. 0xb3, 0x7b, 0xa6, 0x12, 0x98, 0x0a, 0x13, 0x35, 0xa3, 0x9e, 0x52, 0xaf,
  158. 0x43, 0xf4, 0x1c, 0x79, 0xcf, 0x46, 0xc6, 0xcd, 0xc4, 0xc4, 0x0d, 0x19,
  159. 0xac, 0x77, 0xc7, 0x12, 0xcb, 0x22, 0x4a, 0x65, 0xdb, 0x26, 0xcb, 0x1b,
  160. 0x27, 0xbf, 0x25, 0x6f, 0x47, 0xff, 0x2e, 0x59, 0x11, 0x72, 0x0f, 0x42,
  161. 0x70, 0x64, 0xd0, 0x78, 0x6c, 0x09, 0xe6, 0xce, 0xd4, 0xd9, 0x7b, 0x80,
  162. 0x9a, 0xe9, 0x3e, 0x8f, 0x73, 0x77, 0x84, 0x67, 0x1f, 0xf2, 0x74, 0xbc,
  163. 0xcf, 0x9c, 0xb4, 0x58, 0xaa, 0xe2, 0x7b, 0x6f, 0xb6, 0xfe, 0x9a, 0x40,
  164. 0x1e, 0x84, 0xab, 0x5f, 0xe8, 0x73, 0xc6, 0x87, 0xcc, 0x9b, 0xb4, 0xf4,
  165. 0xd9, 0x5a, 0x9c, 0x2d, 0xea, 0xf3, 0x04, 0x9f, 0xc3, 0xbf, 0x2a, 0xf2,
  166. 0x9d, 0xe5, 0x38, 0x2c, 0xf2, 0xcc, 0x46, 0xd9, 0x3e, 0x52, 0xb2, 0x3e,
  167. 0x49, 0xf4, 0x08, 0x14, 0x10, 0x31, 0x9c, 0xeb, 0x10, 0xe5, 0x26, 0xaa,
  168. 0x4d, 0x76, 0x12, 0xb2, 0xc3, 0x8e, 0x15, 0x4b, 0x28, 0x51, 0xe9, 0x30,
  169. 0x00, 0x2c, 0x74, 0xb1, 0x33, 0x71, 0x1c, 0x19, 0xb8, 0x6b, 0x5c, 0xde,
  170. 0x30, 0x4f, 0x36, 0x29, 0x29, 0xaf, 0x1d, 0x41, 0xd1, 0xcd, 0xa0, 0x4f,
  171. 0xb2, 0x8c, 0xb7, 0x76, 0xc2, 0x60, 0xc8, 0xf7, 0x72, 0x98, 0xe1, 0x75,
  172. 0x3c, 0xfb, 0xd7, 0x3c, 0x7c, 0x3a, 0x91, 0x92, 0xb8, 0x83, 0x25, 0xf3,
  173. 0x3b, 0xa6, 0x64, 0x4f, 0xa7, 0x70, 0x68, 0x7c, 0xcc, 0x47, 0xdb, 0xbc,
  174. 0x0f, 0x54, 0x36, 0x2d, 0xea, 0xde, 0x6f, 0x96, 0xdc, 0xa9, 0xca, 0xa1,
  175. 0xb0, 0x80, 0x2e, 0xf8, 0x84, 0x12, 0x84, 0xf6, 0xf7, 0x8c, 0xa3, 0x45,
  176. 0xee, 0x87, 0x59, 0xd9, 0x88, 0xa4, 0xbd, 0x1f, 0x0a, 0x41, 0xd7, 0x17,
  177. 0x42, 0xc2, 0x8f, 0x46, 0x40, 0xa9, 0x3d, 0x00, 0x99, 0xb4, 0x1d, 0x8f,
  178. 0xea, 0xac, 0x86, 0xc1, 0x06, 0x03, 0x02, 0x74, 0x85, 0x78, 0xe6, 0xc3,
  179. 0x4b, 0xc1, 0x60, 0x1b, 0xf5, 0xb1, 0xda, 0xd6, 0x03, 0x75, 0xad, 0xd1};
  180. const std::vector<uint8_t> EpidFileParser::kEmptyPrivRlFile = {
  181. 0x02, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  182. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00,
  183. 0x00, 0x00, 0x00, 0x00, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47,
  184. 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9,
  185. 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7,
  186. 0x47, 0x18, 0x86, 0x03, 0xfe, 0x8a, 0xb8, 0x4a, 0x9c, 0xb6, 0xcd, 0x8b,
  187. 0x1f, 0x68, 0x1c, 0x61, 0x4c, 0xa2, 0x30, 0x95, 0xec, 0x76, 0xc4, 0xa7,
  188. 0x00, 0x6c, 0x6e, 0x3c, 0xc6, 0xf9, 0x32, 0xfc};
  189. const std::vector<uint8_t> EpidFileParser::kEmptyPrivRl = {
  190. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  191. 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  192. const std::vector<uint8_t> EpidFileParser::kShortPrivRlFile = {
  193. 0x02, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  194. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x03,
  195. 0x00, 0x00, 0x00, 0x03, 0x3a, 0x03, 0xb4, 0x95, 0xd3, 0x86, 0xf7, 0xb9,
  196. 0x7e, 0x88, 0x79, 0xd8, 0xce, 0x30, 0x44, 0xf3, 0x35, 0xed, 0x0c, 0xb1,
  197. 0x80, 0x67, 0xeb, 0x1b, 0x24, 0x7f, 0xe0, 0x0c, 0xc7, 0xe8, 0xae, 0x54,
  198. 0xd1, 0xcd, 0x66, 0x2b, 0x11, 0x4e, 0x04, 0x9c, 0xe9, 0x1f, 0xac, 0xb5,
  199. 0xdd, 0x74, 0xa4, 0x9f, 0x8e, 0x66, 0x31, 0x4c, 0xde, 0xb2, 0x11, 0x25,
  200. 0xcc, 0x8e, 0xee, 0x1e, 0xa2, 0x89, 0x1a, 0xae, 0x7a, 0x98, 0x8e, 0x0a,
  201. 0xd7, 0x01, 0xc4, 0xd3, 0x49, 0xb8, 0x56, 0x9a, 0x7b, 0xf4, 0xab, 0x52,
  202. 0xb1, 0x1a, 0x84, 0xbd, 0x96, 0xd9, 0x17, 0xb0, 0xe9, 0x38, 0xff, 0xc7,
  203. 0x7a, 0x50, 0x0c, 0x8a, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47,
  204. 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9,
  205. 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7,
  206. 0x1c, 0xfb, 0xad, 0x9f, 0x47, 0x4d, 0x46, 0x53, 0x18, 0x05, 0x51, 0x04,
  207. 0x31, 0x90, 0x95, 0x33, 0x57, 0xc0, 0x19, 0x64, 0x80, 0xbf, 0x23, 0x4c,
  208. 0x92, 0xb6, 0x52, 0xd2, 0xd0, 0x05, 0xbe, 0x58};
  209. const std::vector<uint8_t> EpidFileParser::kShortPrivRl = {
  210. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  211. 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03,
  212. 0x3a, 0x03, 0xb4, 0x95, 0xd3, 0x86, 0xf7, 0xb9, 0x7e, 0x88, 0x79, 0xd8,
  213. 0xce, 0x30, 0x44, 0xf3, 0x35, 0xed, 0x0c, 0xb1, 0x80, 0x67, 0xeb, 0x1b,
  214. 0x24, 0x7f, 0xe0, 0x0c, 0xc7, 0xe8, 0xae, 0x54, 0xd1, 0xcd, 0x66, 0x2b,
  215. 0x11, 0x4e, 0x04, 0x9c, 0xe9, 0x1f, 0xac, 0xb5, 0xdd, 0x74, 0xa4, 0x9f,
  216. 0x8e, 0x66, 0x31, 0x4c, 0xde, 0xb2, 0x11, 0x25, 0xcc, 0x8e, 0xee, 0x1e,
  217. 0xa2, 0x89, 0x1a, 0xae, 0x7a, 0x98, 0x8e, 0x0a, 0xd7, 0x01, 0xc4, 0xd3,
  218. 0x49, 0xb8, 0x56, 0x9a, 0x7b, 0xf4, 0xab, 0x52, 0xb1, 0x1a, 0x84, 0xbd,
  219. 0x96, 0xd9, 0x17, 0xb0, 0xe9, 0x38, 0xff, 0xc7, 0x7a, 0x50, 0x0c, 0x8a};
  220. const std::vector<uint8_t> EpidFileParser::kGroupPublicKeyFile = {
  221. 0x02, 0x00, 0x00, 0x0c, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  222. 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x89, 0x33, 0xa7, 0x86,
  223. 0xd7, 0x71, 0xcc, 0x80, 0x46, 0x4b, 0x42, 0xc3, 0xe7, 0xba, 0x1a, 0x54,
  224. 0x85, 0x8a, 0x21, 0x8e, 0x29, 0x91, 0xa9, 0x60, 0x41, 0xf9, 0xa5, 0xd9,
  225. 0x7b, 0x5f, 0x54, 0x49, 0x2a, 0x89, 0x8c, 0x10, 0x0e, 0x26, 0x0d, 0xe8,
  226. 0x36, 0x6a, 0x9e, 0x6f, 0x79, 0xff, 0xf1, 0xcd, 0xa7, 0xcd, 0xac, 0x1f,
  227. 0x92, 0x33, 0x3a, 0xd9, 0x7c, 0xf5, 0xcd, 0x38, 0x48, 0x01, 0x4f, 0xc5,
  228. 0x6f, 0xea, 0x50, 0x60, 0x59, 0x09, 0xda, 0x44, 0x21, 0xc2, 0xd0, 0x86,
  229. 0xe6, 0x00, 0x63, 0x59, 0xa9, 0xfb, 0x35, 0x13, 0x4e, 0x13, 0xb1, 0x47,
  230. 0x36, 0xd7, 0xbd, 0xf6, 0x0a, 0x35, 0x74, 0x7d, 0x36, 0xc5, 0x67, 0xa2,
  231. 0x03, 0xb7, 0x38, 0x31, 0x16, 0xa8, 0x5d, 0x64, 0x3f, 0xe6, 0xf1, 0x94,
  232. 0x37, 0x09, 0x8c, 0x20, 0x17, 0xac, 0x2f, 0x55, 0x9e, 0xed, 0xb3, 0xc7,
  233. 0x73, 0xc0, 0x1c, 0xbb, 0xbf, 0xf7, 0x18, 0xce, 0x4f, 0xd4, 0xe3, 0x67,
  234. 0x75, 0xe4, 0xd9, 0x51, 0xfb, 0x1b, 0x22, 0xf9, 0x72, 0x2e, 0xc1, 0x76,
  235. 0x2a, 0xe1, 0x4a, 0x6e, 0x88, 0xd6, 0x2d, 0x71, 0xf4, 0xc4, 0x6d, 0xac,
  236. 0x8c, 0xbd, 0xe7, 0x2b, 0xb1, 0x40, 0x15, 0x93, 0xbd, 0x97, 0xd4, 0x84,
  237. 0x90, 0xef, 0x4e, 0xfd, 0x78, 0x25, 0xab, 0xdf, 0x16, 0xf3, 0x46, 0x52,
  238. 0x16, 0x96, 0xae, 0x50, 0x88, 0x96, 0x18, 0x73, 0xc1, 0xd1, 0x73, 0xf0,
  239. 0x67, 0xc8, 0x8d, 0xbb, 0x4e, 0xbc, 0x6a, 0x40, 0xe6, 0x1e, 0x7d, 0x36,
  240. 0x8c, 0xf4, 0xb1, 0xf1, 0x5f, 0x26, 0x4f, 0x43, 0x0a, 0x36, 0xd4, 0x67,
  241. 0xd4, 0x79, 0x3f, 0xb8, 0x69, 0x6f, 0x9c, 0x33, 0xd3, 0xdb, 0xc6, 0xce,
  242. 0x42, 0xe3, 0x46, 0x87, 0xd6, 0x65, 0xac, 0xc9, 0x71, 0xf1, 0xa9, 0x8f,
  243. 0x78, 0x45, 0x9a, 0xef, 0x1c, 0xe4, 0x45, 0x84, 0x3d, 0x8a, 0x27, 0x51,
  244. 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
  245. 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
  246. 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x58, 0x2a, 0xf6, 0x06,
  247. 0xed, 0x55, 0xd6, 0x86, 0x4f, 0x99, 0x57, 0x9e, 0x8c, 0xfc, 0xea, 0x5e,
  248. 0x7d, 0xc3, 0x41, 0xa2, 0x51, 0x19, 0x47, 0x4b, 0x56, 0x4e, 0x46, 0x3e,
  249. 0xca, 0xd3, 0xb5, 0x89};
  250. const std::vector<uint8_t> EpidFileParser::kGroupPublicKey = {
  251. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff, 0xee, 0xdd, 0xcc,
  252. 0xbb, 0xaa, 0x99, 0x88, 0x89, 0x33, 0xa7, 0x86, 0xd7, 0x71, 0xcc, 0x80,
  253. 0x46, 0x4b, 0x42, 0xc3, 0xe7, 0xba, 0x1a, 0x54, 0x85, 0x8a, 0x21, 0x8e,
  254. 0x29, 0x91, 0xa9, 0x60, 0x41, 0xf9, 0xa5, 0xd9, 0x7b, 0x5f, 0x54, 0x49,
  255. 0x2a, 0x89, 0x8c, 0x10, 0x0e, 0x26, 0x0d, 0xe8, 0x36, 0x6a, 0x9e, 0x6f,
  256. 0x79, 0xff, 0xf1, 0xcd, 0xa7, 0xcd, 0xac, 0x1f, 0x92, 0x33, 0x3a, 0xd9,
  257. 0x7c, 0xf5, 0xcd, 0x38, 0x48, 0x01, 0x4f, 0xc5, 0x6f, 0xea, 0x50, 0x60,
  258. 0x59, 0x09, 0xda, 0x44, 0x21, 0xc2, 0xd0, 0x86, 0xe6, 0x00, 0x63, 0x59,
  259. 0xa9, 0xfb, 0x35, 0x13, 0x4e, 0x13, 0xb1, 0x47, 0x36, 0xd7, 0xbd, 0xf6,
  260. 0x0a, 0x35, 0x74, 0x7d, 0x36, 0xc5, 0x67, 0xa2, 0x03, 0xb7, 0x38, 0x31,
  261. 0x16, 0xa8, 0x5d, 0x64, 0x3f, 0xe6, 0xf1, 0x94, 0x37, 0x09, 0x8c, 0x20,
  262. 0x17, 0xac, 0x2f, 0x55, 0x9e, 0xed, 0xb3, 0xc7, 0x73, 0xc0, 0x1c, 0xbb,
  263. 0xbf, 0xf7, 0x18, 0xce, 0x4f, 0xd4, 0xe3, 0x67, 0x75, 0xe4, 0xd9, 0x51,
  264. 0xfb, 0x1b, 0x22, 0xf9, 0x72, 0x2e, 0xc1, 0x76, 0x2a, 0xe1, 0x4a, 0x6e,
  265. 0x88, 0xd6, 0x2d, 0x71, 0xf4, 0xc4, 0x6d, 0xac, 0x8c, 0xbd, 0xe7, 0x2b,
  266. 0xb1, 0x40, 0x15, 0x93, 0xbd, 0x97, 0xd4, 0x84, 0x90, 0xef, 0x4e, 0xfd,
  267. 0x78, 0x25, 0xab, 0xdf, 0x16, 0xf3, 0x46, 0x52, 0x16, 0x96, 0xae, 0x50,
  268. 0x88, 0x96, 0x18, 0x73, 0xc1, 0xd1, 0x73, 0xf0, 0x67, 0xc8, 0x8d, 0xbb,
  269. 0x4e, 0xbc, 0x6a, 0x40, 0xe6, 0x1e, 0x7d, 0x36, 0x8c, 0xf4, 0xb1, 0xf1,
  270. 0x5f, 0x26, 0x4f, 0x43, 0x0a, 0x36, 0xd4, 0x67, 0xd4, 0x79, 0x3f, 0xb8,
  271. 0x69, 0x6f, 0x9c, 0x33, 0xd3, 0xdb, 0xc6, 0xce, 0x42, 0xe3, 0x46, 0x87,
  272. 0xd6, 0x65, 0xac, 0xc9, 0x71, 0xf1, 0xa9, 0x8f, 0x78, 0x45, 0x9a, 0xef,
  273. 0x1c, 0xe4, 0x45, 0x84, 0x3d, 0x8a, 0x27, 0x51};
  274. const std::vector<uint8_t> EpidFileParser::kGroupMultiPublicKeyFile = {
  275. // Public key1
  276. 0x02, 0x00, 0x00, 0x0c, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  277. 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x89, 0x33, 0xa7, 0x86,
  278. 0xd7, 0x71, 0xcc, 0x80, 0x46, 0x4b, 0x42, 0xc3, 0xe7, 0xba, 0x1a, 0x54,
  279. 0x85, 0x8a, 0x21, 0x8e, 0x29, 0x91, 0xa9, 0x60, 0x41, 0xf9, 0xa5, 0xd9,
  280. 0x7b, 0x5f, 0x54, 0x49, 0x2a, 0x89, 0x8c, 0x10, 0x0e, 0x26, 0x0d, 0xe8,
  281. 0x36, 0x6a, 0x9e, 0x6f, 0x79, 0xff, 0xf1, 0xcd, 0xa7, 0xcd, 0xac, 0x1f,
  282. 0x92, 0x33, 0x3a, 0xd9, 0x7c, 0xf5, 0xcd, 0x38, 0x48, 0x01, 0x4f, 0xc5,
  283. 0x6f, 0xea, 0x50, 0x60, 0x59, 0x09, 0xda, 0x44, 0x21, 0xc2, 0xd0, 0x86,
  284. 0xe6, 0x00, 0x63, 0x59, 0xa9, 0xfb, 0x35, 0x13, 0x4e, 0x13, 0xb1, 0x47,
  285. 0x36, 0xd7, 0xbd, 0xf6, 0x0a, 0x35, 0x74, 0x7d, 0x36, 0xc5, 0x67, 0xa2,
  286. 0x03, 0xb7, 0x38, 0x31, 0x16, 0xa8, 0x5d, 0x64, 0x3f, 0xe6, 0xf1, 0x94,
  287. 0x37, 0x09, 0x8c, 0x20, 0x17, 0xac, 0x2f, 0x55, 0x9e, 0xed, 0xb3, 0xc7,
  288. 0x73, 0xc0, 0x1c, 0xbb, 0xbf, 0xf7, 0x18, 0xce, 0x4f, 0xd4, 0xe3, 0x67,
  289. 0x75, 0xe4, 0xd9, 0x51, 0xfb, 0x1b, 0x22, 0xf9, 0x72, 0x2e, 0xc1, 0x76,
  290. 0x2a, 0xe1, 0x4a, 0x6e, 0x88, 0xd6, 0x2d, 0x71, 0xf4, 0xc4, 0x6d, 0xac,
  291. 0x8c, 0xbd, 0xe7, 0x2b, 0xb1, 0x40, 0x15, 0x93, 0xbd, 0x97, 0xd4, 0x84,
  292. 0x90, 0xef, 0x4e, 0xfd, 0x78, 0x25, 0xab, 0xdf, 0x16, 0xf3, 0x46, 0x52,
  293. 0x16, 0x96, 0xae, 0x50, 0x88, 0x96, 0x18, 0x73, 0xc1, 0xd1, 0x73, 0xf0,
  294. 0x67, 0xc8, 0x8d, 0xbb, 0x4e, 0xbc, 0x6a, 0x40, 0xe6, 0x1e, 0x7d, 0x36,
  295. 0x8c, 0xf4, 0xb1, 0xf1, 0x5f, 0x26, 0x4f, 0x43, 0x0a, 0x36, 0xd4, 0x67,
  296. 0xd4, 0x79, 0x3f, 0xb8, 0x69, 0x6f, 0x9c, 0x33, 0xd3, 0xdb, 0xc6, 0xce,
  297. 0x42, 0xe3, 0x46, 0x87, 0xd6, 0x65, 0xac, 0xc9, 0x71, 0xf1, 0xa9, 0x8f,
  298. 0x78, 0x45, 0x9a, 0xef, 0x1c, 0xe4, 0x45, 0x84, 0x3d, 0x8a, 0x27, 0x51,
  299. 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
  300. 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
  301. 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x58, 0x2a, 0xf6, 0x06,
  302. 0xed, 0x55, 0xd6, 0x86, 0x4f, 0x99, 0x57, 0x9e, 0x8c, 0xfc, 0xea, 0x5e,
  303. 0x7d, 0xc3, 0x41, 0xa2, 0x51, 0x19, 0x47, 0x4b, 0x56, 0x4e, 0x46, 0x3e,
  304. 0xca, 0xd3, 0xb5, 0x89,
  305. // Public key 2
  306. 0x02, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  307. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x78, 0x8a, 0xb6, 0x0f,
  308. 0x9a, 0xf5, 0xe4, 0xd1, 0xe7, 0x39, 0x6a, 0x79, 0x6c, 0xb5, 0xd1, 0xa1,
  309. 0x83, 0xec, 0xa1, 0x01, 0xfe, 0xe8, 0x72, 0xce, 0xce, 0x05, 0x9a, 0x4f,
  310. 0xa5, 0x17, 0x1b, 0xed, 0x30, 0xc5, 0x00, 0xc0, 0xb4, 0xdb, 0x5e, 0xa6,
  311. 0xe2, 0x24, 0x23, 0xab, 0xf5, 0x09, 0xf2, 0x4a, 0x7e, 0x72, 0xfa, 0xc3,
  312. 0xbf, 0x33, 0x93, 0x23, 0x48, 0x89, 0xd2, 0x98, 0x08, 0xe1, 0x01, 0xba,
  313. 0x9d, 0xa9, 0xe5, 0x41, 0x46, 0x2e, 0xbb, 0x9e, 0x6a, 0xfd, 0x28, 0x85,
  314. 0x94, 0xd5, 0x6e, 0x5a, 0xfa, 0x42, 0x71, 0x6e, 0xdc, 0x7e, 0xdb, 0xd1,
  315. 0xf2, 0x84, 0x11, 0x08, 0x4f, 0x0f, 0x22, 0x1f, 0x32, 0xbe, 0xd7, 0x6f,
  316. 0x55, 0x17, 0x17, 0x4a, 0xa7, 0x46, 0xeb, 0xca, 0x02, 0x65, 0x53, 0xca,
  317. 0xd7, 0x93, 0x03, 0x01, 0xe1, 0x54, 0xfc, 0xdd, 0xb4, 0x95, 0x5a, 0x5c,
  318. 0x0c, 0x8c, 0x13, 0x65, 0x02, 0x16, 0xf0, 0xfc, 0xbb, 0x02, 0x5f, 0x87,
  319. 0x83, 0x8c, 0xd0, 0x3e, 0x69, 0xc8, 0xf5, 0x7c, 0x09, 0xdd, 0x48, 0x65,
  320. 0x82, 0x48, 0x6f, 0xb5, 0x35, 0x0c, 0xc4, 0x04, 0x2d, 0x83, 0x0a, 0x3e,
  321. 0xa0, 0x0f, 0x5f, 0x8e, 0x61, 0xf7, 0xc3, 0xb5, 0x5c, 0x66, 0xf8, 0xf8,
  322. 0xa3, 0x0a, 0xc1, 0x50, 0xcd, 0xb0, 0x44, 0x19, 0x14, 0x07, 0xf1, 0xad,
  323. 0x7a, 0xec, 0x73, 0xac, 0x55, 0x01, 0x8a, 0xa6, 0x62, 0x9b, 0x30, 0xf3,
  324. 0xf9, 0xc5, 0xd1, 0x3d, 0xf2, 0x36, 0x13, 0x28, 0x4d, 0xbf, 0x95, 0x88,
  325. 0x76, 0x6b, 0xb0, 0x18, 0xd8, 0x3f, 0xa6, 0x22, 0x69, 0x13, 0x06, 0xa4,
  326. 0x04, 0xbf, 0x52, 0x8e, 0xf0, 0x11, 0x99, 0x65, 0xb9, 0xf8, 0x57, 0x0b,
  327. 0xf6, 0xc2, 0xe8, 0xaf, 0xee, 0xd4, 0x6e, 0xa7, 0x49, 0x7b, 0xeb, 0x8f,
  328. 0x92, 0x66, 0x45, 0xda, 0xb4, 0x01, 0xa8, 0xee, 0x7c, 0xdf, 0x8e, 0x08,
  329. 0xdf, 0x69, 0x19, 0x8c, 0xfa, 0x23, 0x52, 0x71, 0x12, 0x10, 0xfb, 0x13,
  330. 0x2f, 0x17, 0x16, 0x9c, 0x7e, 0xc0, 0xe5, 0x22, 0x74, 0x81, 0x38, 0xed,
  331. 0x3f, 0xe1, 0x72, 0xc9, 0x46, 0x4c, 0x03, 0x7a, 0x79, 0xe0, 0x84, 0x32,
  332. 0x34, 0x59, 0x46, 0x98, 0xe7, 0xc6, 0x5f, 0xd8, 0x5f, 0xf0, 0xee, 0x1b,
  333. 0x53, 0x4c, 0xce, 0x61, 0xb7, 0x91, 0xbf, 0x71, 0xb3, 0xeb, 0x73, 0x66,
  334. 0x47, 0x28, 0x1d, 0x20};
  335. const std::vector<uint8_t> EpidFileParser::kEmptyGroupRlFile = {
  336. 0x02, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  337. 0x00, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71,
  338. 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70,
  339. 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7,
  340. 0x30, 0x9f, 0x8c, 0xae, 0x9b, 0x2a, 0xab, 0xcf, 0xb9, 0x85, 0x6f,
  341. 0x16, 0x21, 0x92, 0xb8, 0x9a, 0x31, 0x2c, 0xb8, 0x04, 0x20, 0xc8,
  342. 0x2a, 0x98, 0x8f, 0xd5, 0xaf, 0xc7, 0x27, 0xe5, 0x04, 0x0c};
  343. const std::vector<uint8_t> EpidFileParser::kEmptyGroupRl = {
  344. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  345. const std::vector<uint8_t> EpidFileParser::kShortGroupRlFile = {
  346. 0x02, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  347. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  348. 0x00, 0x00, 0x9a, 0xbc, 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47,
  349. 0x51, 0x71, 0xed, 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9,
  350. 0x70, 0x2a, 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7,
  351. 0x09, 0x15, 0x86, 0xd7, 0x24, 0x47, 0xfc, 0x1e, 0x44, 0xc0, 0xfb, 0x9e,
  352. 0x4f, 0xe4, 0x92, 0x85, 0x79, 0x94, 0x9c, 0x80, 0xd1, 0xa1, 0x66, 0x34,
  353. 0x79, 0xb6, 0xb3, 0x3b, 0x66, 0xad, 0x2e, 0x40};
  354. const std::vector<uint8_t> EpidFileParser::kShortGroupRl = {
  355. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  356. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0xbc};
  357. //////////////////////////////////////////////////////////////////////////
  358. // EpidParseGroupPubKeyFile Tests
  359. TEST_F(EpidFileParser, GroupPubKeyParseFailsGivenNullParameters) {
  360. GroupPubKey pubkey;
  361. EXPECT_EQ(kEpidBadArgErr,
  362. EpidParseGroupPubKeyFile(nullptr, this->kGroupPublicKeyFile.size(),
  363. &this->kCert, &pubkey));
  364. EXPECT_EQ(kEpidBadArgErr,
  365. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  366. this->kGroupPublicKeyFile.size(), nullptr,
  367. &pubkey));
  368. EXPECT_EQ(kEpidBadArgErr,
  369. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  370. this->kGroupPublicKeyFile.size(),
  371. &this->kCert, nullptr));
  372. }
  373. TEST_F(EpidFileParser, GroupPubKeyParseFailsGivenUnsupportedCurve) {
  374. GroupPubKey pubkey;
  375. EpidCaCertificate unsupported_curve1(this->kCert);
  376. unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF;
  377. EXPECT_EQ(kEpidBadArgErr,
  378. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  379. this->kGroupPublicKeyFile.size(),
  380. &unsupported_curve1, &pubkey));
  381. EpidCaCertificate unsupported_curve2(this->kCert);
  382. unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;
  383. EXPECT_EQ(kEpidBadArgErr,
  384. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  385. this->kGroupPublicKeyFile.size(),
  386. &unsupported_curve2, &pubkey));
  387. EpidCaCertificate unsupported_curve3(this->kCert);
  388. unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;
  389. EXPECT_EQ(kEpidBadArgErr,
  390. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  391. this->kGroupPublicKeyFile.size(),
  392. &unsupported_curve3, &pubkey));
  393. EpidCaCertificate unsupported_curve4(this->kCert);
  394. unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;
  395. EXPECT_EQ(kEpidBadArgErr,
  396. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  397. this->kGroupPublicKeyFile.size(),
  398. &unsupported_curve4, &pubkey));
  399. EpidCaCertificate unsupported_curve5(this->kCert);
  400. unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;
  401. EXPECT_EQ(kEpidBadArgErr,
  402. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  403. this->kGroupPublicKeyFile.size(),
  404. &unsupported_curve5, &pubkey));
  405. EpidCaCertificate unsupported_curve6(this->kCert);
  406. unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;
  407. EXPECT_EQ(kEpidBadArgErr,
  408. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  409. this->kGroupPublicKeyFile.size(),
  410. &unsupported_curve6, &pubkey));
  411. }
  412. TEST_F(EpidFileParser, GroupPubKeyParseFailsGivenInvalidKeyInCertificate) {
  413. GroupPubKey pubkey;
  414. EpidCaCertificate invalid_key_qx(this->kCert);
  415. invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;
  416. EXPECT_EQ(kEpidBadArgErr,
  417. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  418. this->kGroupPublicKeyFile.size(),
  419. &invalid_key_qx, &pubkey));
  420. EpidCaCertificate invalid_key_qy(this->kCert);
  421. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
  422. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  423. EXPECT_EQ(kEpidBadArgErr,
  424. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  425. this->kGroupPublicKeyFile.size(),
  426. &invalid_key_qy, &pubkey));
  427. EpidCaCertificate invalid_key_qx_qy(this->kCert);
  428. invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  429. invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] =
  430. invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^
  431. 0xFF;
  432. EXPECT_EQ(kEpidBadArgErr,
  433. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  434. this->kGroupPublicKeyFile.size(),
  435. &invalid_key_qx_qy, &pubkey));
  436. }
  437. TEST_F(EpidFileParser, RejectsGroupPubKeyFileWithInvalidSize) {
  438. GroupPubKey pubkey;
  439. EXPECT_EQ(kEpidBadArgErr,
  440. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), 0,
  441. &this->kCert, &pubkey));
  442. EXPECT_EQ(kEpidBadArgErr,
  443. EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
  444. this->kGroupPublicKeyFile.size() - 1,
  445. &this->kCert, &pubkey));
  446. EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile(
  447. (void*)this->kGroupMultiPublicKeyFile.data(),
  448. this->kGroupMultiPublicKeyFile.size() - 1,
  449. &this->kCert, &pubkey));
  450. EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile(
  451. (void*)this->kGroupMultiPublicKeyFile.data(),
  452. this->kGroupMultiPublicKeyFile.size() + 1,
  453. &this->kCert, &pubkey));
  454. }
  455. TEST_F(EpidFileParser, RejectsInvalidGroupPubKeyFileType) {
  456. GroupPubKey pubkey;
  457. EXPECT_EQ(kEpidBadArgErr,
  458. EpidParseGroupPubKeyFile((void*)this->kShortPrivRlFile.data(),
  459. this->kGroupPublicKeyFile.size(),
  460. &this->kCert, &pubkey));
  461. }
  462. TEST_F(EpidFileParser, RejectsGroupPubKeyFileWithUnsupportedEpidVersion) {
  463. GroupPubKey pubkey;
  464. std::vector<uint8_t> unsupported_epidver_file(this->kGroupPublicKeyFile);
  465. unsupported_epidver_file[0] = {0x01};
  466. EXPECT_EQ(kEpidBadArgErr,
  467. EpidParseGroupPubKeyFile((void*)unsupported_epidver_file.data(),
  468. unsupported_epidver_file.size(),
  469. &this->kCert, &pubkey));
  470. }
  471. TEST_F(EpidFileParser, ParsesValidPubKeyFile) {
  472. std::vector<uint8_t> pubkey(sizeof(GroupPubKey), 0);
  473. EXPECT_EQ(kEpidNoErr, EpidParseGroupPubKeyFile(
  474. (void*)this->kGroupPublicKeyFile.data(),
  475. this->kGroupPublicKeyFile.size(), &this->kCert,
  476. (GroupPubKey*)pubkey.data()));
  477. EXPECT_EQ(this->kGroupPublicKey, pubkey);
  478. }
  479. TEST_F(EpidFileParser, ParsesValidMultiPubKeyFile) {
  480. std::vector<uint8_t> pubkey(sizeof(GroupPubKey), 0);
  481. EXPECT_EQ(kEpidNoErr, EpidParseGroupPubKeyFile(
  482. (void*)this->kGroupMultiPublicKeyFile.data(),
  483. this->kGroupMultiPublicKeyFile.size(), &this->kCert,
  484. (GroupPubKey*)pubkey.data()));
  485. EXPECT_EQ(this->kGroupPublicKey, pubkey);
  486. }
  487. TEST_F(EpidFileParser, RejectsGroupPubKeyFileWithInvalidSignature) {
  488. GroupPubKey pubkey;
  489. std::vector<uint8_t> pubkey_inv_sign(this->kGroupPublicKeyFile);
  490. pubkey_inv_sign[pubkey_inv_sign.size() - 1] =
  491. pubkey_inv_sign[pubkey_inv_sign.size() - 1] ^ 0xFF;
  492. EXPECT_EQ(
  493. kEpidSigInvalid,
  494. EpidParseGroupPubKeyFile((void*)pubkey_inv_sign.data(),
  495. pubkey_inv_sign.size(), &this->kCert, &pubkey));
  496. }
  497. //////////////////////////////////////////////////////////////////////////
  498. // EpidParsePrivRlFile Tests
  499. TEST_F(EpidFileParser, PrivRlParseProvidesRequiredLenWithNullDest) {
  500. size_t rl_len = 0;
  501. EXPECT_EQ(kEpidNoErr,
  502. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  503. this->kShortPrivRlFile.size(), &this->kCert,
  504. nullptr, &rl_len));
  505. EXPECT_EQ(this->kShortPrivRl.size(), rl_len);
  506. }
  507. TEST_F(EpidFileParser, PrivRlParseFailsGivenNullParameters) {
  508. size_t rl_len = this->kShortPrivRl.size();
  509. std::vector<uint8_t> rl(rl_len);
  510. // null input buffer
  511. EXPECT_EQ(kEpidBadArgErr,
  512. EpidParsePrivRlFile(nullptr, this->kShortPrivRlFile.size(),
  513. &this->kCert, (PrivRl*)rl.data(), &rl_len));
  514. // null cert
  515. EXPECT_EQ(kEpidBadArgErr,
  516. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  517. this->kShortPrivRlFile.size(), nullptr,
  518. (PrivRl*)rl.data(), &rl_len));
  519. // null rl_length
  520. EXPECT_EQ(kEpidBadArgErr,
  521. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  522. this->kShortPrivRlFile.size(), &this->kCert,
  523. (PrivRl*)rl.data(), nullptr));
  524. // null rl_length with null dest
  525. EXPECT_EQ(kEpidBadArgErr,
  526. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  527. this->kShortPrivRlFile.size(), &this->kCert,
  528. nullptr, nullptr));
  529. }
  530. TEST_F(EpidFileParser, PrivRlParseFailsGivenUnsupportedCurve) {
  531. size_t rl_len = this->kShortPrivRl.size();
  532. std::vector<uint8_t> rl(rl_len);
  533. EpidCaCertificate unsupported_curve(kCert);
  534. unsupported_curve.a.data[0] = unsupported_curve.a.data[0] ^ 0xFF;
  535. EXPECT_EQ(
  536. kEpidBadArgErr,
  537. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  538. this->kShortPrivRlFile.size(), &unsupported_curve,
  539. (PrivRl*)rl.data(), &rl_len));
  540. EpidCaCertificate unsupported_curve2(kCert);
  541. unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;
  542. EXPECT_EQ(
  543. kEpidBadArgErr,
  544. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  545. this->kShortPrivRlFile.size(), &unsupported_curve2,
  546. (PrivRl*)rl.data(), &rl_len));
  547. EpidCaCertificate unsupported_curve3(kCert);
  548. unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;
  549. EXPECT_EQ(
  550. kEpidBadArgErr,
  551. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  552. this->kShortPrivRlFile.size(), &unsupported_curve3,
  553. (PrivRl*)rl.data(), &rl_len));
  554. EpidCaCertificate unsupported_curve4(kCert);
  555. unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;
  556. EXPECT_EQ(
  557. kEpidBadArgErr,
  558. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  559. this->kShortPrivRlFile.size(), &unsupported_curve4,
  560. (PrivRl*)rl.data(), &rl_len));
  561. EpidCaCertificate unsupported_curve5(kCert);
  562. unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;
  563. EXPECT_EQ(
  564. kEpidBadArgErr,
  565. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  566. this->kShortPrivRlFile.size(), &unsupported_curve5,
  567. (PrivRl*)rl.data(), &rl_len));
  568. EpidCaCertificate unsupported_curve6(kCert);
  569. unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;
  570. EXPECT_EQ(
  571. kEpidBadArgErr,
  572. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  573. this->kShortPrivRlFile.size(), &unsupported_curve6,
  574. (PrivRl*)rl.data(), &rl_len));
  575. }
  576. TEST_F(EpidFileParser, PrivRlParseFailsGivenInvalidKeyInCertificate) {
  577. size_t rl_len = this->kShortPrivRl.size();
  578. std::vector<uint8_t> rl(rl_len);
  579. EpidCaCertificate invalid_key_qx(kCert);
  580. invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;
  581. EXPECT_EQ(kEpidBadArgErr,
  582. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  583. this->kShortPrivRlFile.size(), &invalid_key_qx,
  584. (PrivRl*)rl.data(), &rl_len));
  585. EpidCaCertificate invalid_key_qy(kCert);
  586. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
  587. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  588. EXPECT_EQ(kEpidBadArgErr,
  589. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  590. this->kShortPrivRlFile.size(), &invalid_key_qy,
  591. (PrivRl*)rl.data(), &rl_len));
  592. EpidCaCertificate invalid_key_qx_qy(kCert);
  593. invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  594. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
  595. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  596. EXPECT_EQ(
  597. kEpidBadArgErr,
  598. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  599. this->kShortPrivRlFile.size(), &invalid_key_qx_qy,
  600. (PrivRl*)rl.data(), &rl_len));
  601. }
  602. TEST_F(EpidFileParser, RejectsPrivRlFileWithInvalidSize) {
  603. size_t rl_len = this->kEmptyPrivRl.size();
  604. std::vector<uint8_t> rl(rl_len);
  605. EXPECT_EQ(kEpidBadArgErr,
  606. EpidParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(),
  607. this->kEmptyPrivRlFile.size() - 1, &this->kCert,
  608. (PrivRl*)rl.data(), &rl_len));
  609. EXPECT_EQ(kEpidBadArgErr,
  610. EpidParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(), 0,
  611. &this->kCert, (PrivRl*)rl.data(), &rl_len));
  612. }
  613. TEST_F(EpidFileParser, RejectsInvalidPrivRlFileType) {
  614. size_t rl_len = this->kShortPrivRl.size();
  615. std::vector<uint8_t> rl(rl_len);
  616. EXPECT_EQ(kEpidBadArgErr,
  617. EpidParsePrivRlFile((void*)this->kShortGroupRlFile.data(),
  618. this->kShortGroupRlFile.size(), &this->kCert,
  619. (PrivRl*)rl.data(), &rl_len));
  620. }
  621. TEST_F(EpidFileParser, RejectsPrivRlFileWithUnsupportedEpidVersion) {
  622. size_t rl_len = this->kShortPrivRl.size();
  623. std::vector<uint8_t> rl(rl_len);
  624. std::vector<uint8_t> unsupported_epidver_file(this->kShortPrivRlFile);
  625. unsupported_epidver_file[0] = {0x01};
  626. EXPECT_EQ(kEpidBadArgErr,
  627. EpidParsePrivRlFile((void*)unsupported_epidver_file.data(),
  628. unsupported_epidver_file.size(), &this->kCert,
  629. (PrivRl*)rl.data(), &rl_len));
  630. }
  631. TEST_F(EpidFileParser, ParsesEmptyPrivRl) {
  632. size_t rl_len = this->kEmptyPrivRl.size();
  633. std::vector<uint8_t> rl(rl_len);
  634. EXPECT_EQ(kEpidNoErr,
  635. EpidParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(),
  636. this->kEmptyPrivRlFile.size(), &this->kCert,
  637. (PrivRl*)rl.data(), &rl_len));
  638. EXPECT_EQ(this->kEmptyPrivRl, rl);
  639. }
  640. TEST_F(EpidFileParser, ParsesShortPrivRl) {
  641. size_t rl_len = this->kShortPrivRl.size();
  642. std::vector<uint8_t> rl(rl_len);
  643. EXPECT_EQ(kEpidNoErr,
  644. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  645. this->kShortPrivRlFile.size(), &this->kCert,
  646. (PrivRl*)rl.data(), &rl_len));
  647. EXPECT_EQ(this->kShortPrivRl, rl);
  648. }
  649. TEST_F(EpidFileParser, ParsesLongPrivRl) {
  650. EcdsaSignature signature = {
  651. 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed,
  652. 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a,
  653. 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x02,
  654. 0xd7, 0x14, 0x3e, 0xce, 0x36, 0x24, 0xb2, 0xe5, 0x14, 0x94, 0x17,
  655. 0xdf, 0x8d, 0x0f, 0xda, 0xff, 0x8c, 0xb9, 0x7f, 0xb6, 0x05, 0x09,
  656. 0x08, 0x80, 0xb0, 0xb8, 0x45, 0x92, 0x15, 0xb6, 0x08,
  657. };
  658. std::vector<uint8_t> long_privrl_file = {// Intel(R) EPID Version
  659. 0x02, 0x00,
  660. // File Type
  661. 0x00, 0x0d,
  662. // Group ID
  663. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  664. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  665. 0x00, 0x00, 0x00, 0x2a,
  666. // Revocation list version number
  667. 0x00, 0x00, 0x00, 0x00,
  668. // Number of entries
  669. 0x00, 0x00, 0x00, 0x32};
  670. const std::vector<uint8_t> FToCreateLongRl = {
  671. 0x8a, 0xdc, 0xc0, 0xc8, 0xcd, 0x29, 0x9e, 0x08, 0x9e, 0x4e, 0x0d,
  672. 0xa7, 0xf6, 0x46, 0xee, 0x80, 0xca, 0x91, 0x86, 0x54, 0x3c, 0x7f,
  673. 0x8d, 0xb5, 0x49, 0xf9, 0x6d, 0x00, 0x39, 0x39, 0x62, 0xc7,
  674. };
  675. for (int i = 0; i < 50; ++i) {
  676. for (auto it : FToCreateLongRl) {
  677. long_privrl_file.push_back(it);
  678. }
  679. }
  680. for (auto it : signature.x.data) {
  681. long_privrl_file.push_back(it);
  682. }
  683. for (auto it : signature.y.data) {
  684. long_privrl_file.push_back(it);
  685. }
  686. size_t rl_len = long_privrl_file.size() - 68;
  687. std::vector<uint8_t> rl(rl_len);
  688. EXPECT_EQ(kEpidNoErr,
  689. EpidParsePrivRlFile((void*)long_privrl_file.data(),
  690. long_privrl_file.size(), &this->kCert,
  691. (PrivRl*)rl.data(), &rl_len));
  692. EXPECT_EQ(
  693. std::vector<uint8_t>(&long_privrl_file[4],
  694. &long_privrl_file[long_privrl_file.size() - 64]),
  695. rl);
  696. }
  697. TEST_F(EpidFileParser, RejectsPrivRlFileWithInvalidSignature) {
  698. size_t rl_len = this->kShortPrivRl.size();
  699. std::vector<uint8_t> rl(rl_len);
  700. std::vector<uint8_t> privrl_inv_sign(kShortPrivRlFile);
  701. privrl_inv_sign[privrl_inv_sign.size() - 1] =
  702. privrl_inv_sign[privrl_inv_sign.size() - 1] ^ 0xFF;
  703. EXPECT_EQ(kEpidSigInvalid,
  704. EpidParsePrivRlFile(privrl_inv_sign.data(), privrl_inv_sign.size(),
  705. &this->kCert, (PrivRl*)rl.data(), &rl_len));
  706. }
  707. TEST_F(EpidFileParser, PrivRlParseRejectsBufWithInsufficientSize) {
  708. size_t rl_len = this->kShortPrivRl.size() - 1;
  709. std::vector<uint8_t> rl(rl_len);
  710. EXPECT_EQ(kEpidBadArgErr,
  711. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  712. this->kShortPrivRlFile.size(), &this->kCert,
  713. (PrivRl*)rl.data(), &rl_len));
  714. }
  715. TEST_F(EpidFileParser, ReturnsProperSizeGivenOversizedPrivRlBuf) {
  716. size_t rl_len = this->kShortPrivRl.size() + 1;
  717. std::vector<uint8_t> oversized_rl(rl_len);
  718. EXPECT_EQ(kEpidNoErr,
  719. EpidParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
  720. this->kShortPrivRlFile.size(), &this->kCert,
  721. (PrivRl*)oversized_rl.data(), &rl_len));
  722. std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1);
  723. EXPECT_EQ(this->kShortPrivRl, rl);
  724. EXPECT_EQ(this->kShortPrivRl.size(), rl_len);
  725. }
  726. //////////////////////////////////////////////////////////////////////////
  727. // EpidParseSigRlFile Tests
  728. TEST_F(EpidFileParser, SigRlParseProvidesRequiredLenWithNullDest) {
  729. size_t rl_len = 0;
  730. EXPECT_EQ(kEpidNoErr, EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  731. this->kShortSigRlFile.size(), &kCert,
  732. nullptr, &rl_len));
  733. EXPECT_EQ(rl_len, this->kShortSigRl.size());
  734. }
  735. TEST_F(EpidFileParser, SigRlParseFailsGivenNullParameters) {
  736. size_t rl_len = this->kShortSigRl.size();
  737. std::vector<uint8_t> rl(rl_len);
  738. EXPECT_EQ(kEpidBadArgErr,
  739. EpidParseSigRlFile(nullptr, this->kShortSigRlFile.size(), &kCert,
  740. (SigRl*)rl.data(), &rl_len));
  741. EXPECT_EQ(kEpidBadArgErr,
  742. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  743. this->kShortSigRlFile.size(), nullptr,
  744. (SigRl*)rl.data(), &rl_len));
  745. EXPECT_EQ(kEpidBadArgErr,
  746. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  747. this->kShortSigRlFile.size(), &kCert,
  748. (SigRl*)rl.data(), nullptr));
  749. EXPECT_EQ(kEpidBadArgErr,
  750. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  751. this->kShortSigRlFile.size(), &kCert, nullptr,
  752. nullptr));
  753. }
  754. TEST_F(EpidFileParser, SigRlParseFailsGivenUnsupportedCurve) {
  755. size_t rl_len = this->kShortSigRl.size();
  756. std::vector<uint8_t> rl(rl_len);
  757. EpidCaCertificate unsupported_curve1(kCert);
  758. unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF;
  759. EXPECT_EQ(
  760. kEpidBadArgErr,
  761. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  762. this->kShortSigRlFile.size(), &unsupported_curve1,
  763. (SigRl*)rl.data(), &rl_len));
  764. EpidCaCertificate unsupported_curve2(kCert);
  765. unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;
  766. EXPECT_EQ(
  767. kEpidBadArgErr,
  768. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  769. this->kShortSigRlFile.size(), &unsupported_curve2,
  770. (SigRl*)rl.data(), &rl_len));
  771. EpidCaCertificate unsupported_curve3(kCert);
  772. unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;
  773. EXPECT_EQ(
  774. kEpidBadArgErr,
  775. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  776. this->kShortSigRlFile.size(), &unsupported_curve3,
  777. (SigRl*)rl.data(), &rl_len));
  778. EpidCaCertificate unsupported_curve4(kCert);
  779. unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;
  780. EXPECT_EQ(
  781. kEpidBadArgErr,
  782. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  783. this->kShortSigRlFile.size(), &unsupported_curve4,
  784. (SigRl*)rl.data(), &rl_len));
  785. EpidCaCertificate unsupported_curve5(kCert);
  786. unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;
  787. EXPECT_EQ(
  788. kEpidBadArgErr,
  789. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  790. this->kShortSigRlFile.size(), &unsupported_curve5,
  791. (SigRl*)rl.data(), &rl_len));
  792. EpidCaCertificate unsupported_curve6(kCert);
  793. unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;
  794. EXPECT_EQ(
  795. kEpidBadArgErr,
  796. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  797. this->kShortSigRlFile.size(), &unsupported_curve6,
  798. (SigRl*)rl.data(), &rl_len));
  799. }
  800. TEST_F(EpidFileParser, SigRlParseFailsGivenInvalidKeyInCertificate) {
  801. size_t rl_len = this->kShortSigRl.size();
  802. std::vector<uint8_t> rl(rl_len);
  803. EpidCaCertificate invalid_key_qx(kCert);
  804. invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;
  805. EXPECT_EQ(kEpidBadArgErr,
  806. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  807. this->kShortSigRlFile.size(), &invalid_key_qx,
  808. (SigRl*)rl.data(), &rl_len));
  809. EpidCaCertificate invalid_key_qy(kCert);
  810. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
  811. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  812. EXPECT_EQ(kEpidBadArgErr,
  813. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  814. this->kShortSigRlFile.size(), &invalid_key_qy,
  815. (SigRl*)rl.data(), &rl_len));
  816. EpidCaCertificate invalid_key_qx_qy(kCert);
  817. invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  818. invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] =
  819. invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^
  820. 0xFF;
  821. EXPECT_EQ(kEpidBadArgErr,
  822. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  823. this->kShortSigRlFile.size(), &invalid_key_qx_qy,
  824. (SigRl*)rl.data(), &rl_len));
  825. }
  826. TEST_F(EpidFileParser, RejectsSigRlFileWithInvalidSize) {
  827. size_t rl_len = this->kEmptySigRl.size();
  828. std::vector<uint8_t> rl(rl_len);
  829. EXPECT_EQ(kEpidBadArgErr,
  830. EpidParseSigRlFile((void*)this->kEmptySigRlFile.data(), 0,
  831. &this->kCert, (SigRl*)rl.data(), &rl_len));
  832. EXPECT_EQ(kEpidBadArgErr,
  833. EpidParseSigRlFile((void*)this->kEmptySigRlFile.data(),
  834. this->kEmptySigRlFile.size() - 1, &this->kCert,
  835. (SigRl*)rl.data(), &rl_len));
  836. EXPECT_EQ(kEpidBadArgErr,
  837. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  838. this->kEmptySigRlFile.size() + 1, &this->kCert,
  839. (SigRl*)rl.data(), &rl_len));
  840. }
  841. TEST_F(EpidFileParser, SigRlParseRejectsInvalidSigRlFileType) {
  842. size_t rl_len = this->kShortPrivRl.size();
  843. std::vector<uint8_t> rl(rl_len);
  844. EXPECT_EQ(kEpidBadArgErr,
  845. EpidParseSigRlFile((void*)this->kShortPrivRlFile.data(),
  846. this->kShortPrivRlFile.size(), &this->kCert,
  847. (SigRl*)rl.data(), &rl_len));
  848. }
  849. TEST_F(EpidFileParser, RejectsSigRlFileWithUnsupportedEpidVersion) {
  850. size_t rl_len = this->kShortSigRl.size();
  851. std::vector<uint8_t> rl(rl_len);
  852. std::vector<uint8_t> unsupported_epidver_file(this->kShortSigRlFile);
  853. unsupported_epidver_file[0] = {0x01};
  854. EXPECT_EQ(kEpidBadArgErr,
  855. EpidParseSigRlFile((void*)unsupported_epidver_file.data(),
  856. unsupported_epidver_file.size(), &this->kCert,
  857. (SigRl*)rl.data(), &rl_len));
  858. }
  859. TEST_F(EpidFileParser, ParsesEmptySigRl) {
  860. size_t rl_len = this->kEmptySigRl.size();
  861. std::vector<uint8_t> rl(rl_len);
  862. EXPECT_EQ(kEpidNoErr,
  863. EpidParseSigRlFile(this->kEmptySigRlFile.data(),
  864. this->kEmptySigRlFile.size(), &this->kCert,
  865. (SigRl*)rl.data(), &rl_len));
  866. EXPECT_EQ(rl, this->kEmptySigRl);
  867. }
  868. TEST_F(EpidFileParser, ParsesShortSigRl) {
  869. size_t rl_len = this->kShortSigRl.size();
  870. std::vector<uint8_t> rl(rl_len);
  871. EXPECT_EQ(kEpidNoErr,
  872. EpidParseSigRlFile(this->kShortSigRlFile.data(),
  873. this->kShortSigRlFile.size(), &this->kCert,
  874. (SigRl*)rl.data(), &rl_len));
  875. EXPECT_EQ(rl, this->kShortSigRl);
  876. }
  877. TEST_F(EpidFileParser, ParsesLongSigRl) {
  878. std::vector<uint8_t> b = {
  879. 0x92, 0xb0, 0x8b, 0x6d, 0x6b, 0xa4, 0x32, 0x4e, 0xd1, 0x83, 0x26, 0x24,
  880. 0x73, 0x70, 0x80, 0xd3, 0x72, 0xe3, 0xab, 0xfe, 0xbc, 0x86, 0x9f, 0x55,
  881. 0x9e, 0x56, 0x57, 0xa5, 0x1f, 0x06, 0x6c, 0x1b, 0x2a, 0x55, 0xb6, 0xb2,
  882. 0x13, 0xe9, 0xe8, 0x88, 0x6c, 0xbd, 0xe7, 0xca, 0x81, 0xcb, 0x92, 0x10,
  883. 0xa7, 0xef, 0xdc, 0x88, 0xf1, 0x7c, 0x91, 0x07, 0xcc, 0xf0, 0x63, 0x39,
  884. 0xae, 0x5c, 0xb9, 0x78, 0xcd, 0x54, 0xdd, 0x98, 0x3e, 0xa6, 0xc9, 0x2f,
  885. 0x83, 0x78, 0xc8, 0x64, 0xc9, 0x92, 0x41, 0x52, 0xb9, 0xf9, 0x59, 0x91,
  886. 0x46, 0x89, 0x78, 0xda, 0xc3, 0x26, 0xdd, 0x9d, 0x1f, 0x0c, 0x8e, 0xea,
  887. 0xba, 0xa8, 0xde, 0xa5, 0x33, 0x8c, 0x2e, 0xaa, 0x0e, 0x2c, 0x13, 0x36,
  888. 0xb3, 0x7b, 0xa6, 0x12, 0x98, 0x0a, 0x13, 0x35, 0xa3, 0x9e, 0x52, 0xaf,
  889. 0x43, 0xf4, 0x1c, 0x79, 0xcf, 0x46, 0xc6, 0xcd};
  890. EcdsaSignature signature = {
  891. 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed,
  892. 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a,
  893. 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x35,
  894. 0xb4, 0x20, 0x07, 0x4e, 0xed, 0xc3, 0xb1, 0x60, 0xd8, 0x78, 0x32,
  895. 0xb3, 0xa0, 0x8e, 0xc2, 0xab, 0xdb, 0x46, 0x6b, 0x03, 0x94, 0xd7,
  896. 0x90, 0xd3, 0xfd, 0xd3, 0x5a, 0x9a, 0xc3, 0x66, 0xab,
  897. };
  898. std::vector<uint8_t> long_sigrl_file = {
  899. // Intel(R) EPID Version
  900. 0x02, 0x00,
  901. // File Type
  902. 0x00, 0x0e,
  903. // Group ID
  904. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  905. 0x00, 0x00, 0x12, 0x34,
  906. // Revocation list version number
  907. 0x00, 0x00, 0x00, 0x03,
  908. // Number of revocation list entries N
  909. 0x00, 0x00, 0x00, 0x32,
  910. };
  911. for (int i = 0; i < 50; ++i) {
  912. for (auto it : b) {
  913. long_sigrl_file.push_back(it);
  914. }
  915. }
  916. for (auto it : signature.x.data) {
  917. long_sigrl_file.push_back(it);
  918. }
  919. for (auto it : signature.y.data) {
  920. long_sigrl_file.push_back(it);
  921. }
  922. size_t rl_len = long_sigrl_file.size() - sizeof(signature) - 4;
  923. std::vector<uint8_t> rl(rl_len);
  924. EXPECT_EQ(kEpidNoErr,
  925. EpidParseSigRlFile(long_sigrl_file.data(), long_sigrl_file.size(),
  926. &this->kCert, (SigRl*)rl.data(), &rl_len));
  927. std::vector<uint8_t> expected_long_sig_rl(std::vector<uint8_t>(
  928. &long_sigrl_file[4],
  929. &long_sigrl_file[long_sigrl_file.size() - sizeof(signature)]));
  930. EXPECT_EQ(expected_long_sig_rl, rl);
  931. }
  932. TEST_F(EpidFileParser, RejectsSigRlFileWithInvalidSignature) {
  933. size_t rl_len = this->kShortSigRl.size();
  934. std::vector<uint8_t> rl(rl_len);
  935. std::vector<uint8_t> sigrl_inv_sign(kShortSigRlFile);
  936. sigrl_inv_sign[sigrl_inv_sign.size() - 1] =
  937. sigrl_inv_sign[sigrl_inv_sign.size() - 1] ^ 0xFF;
  938. EXPECT_EQ(
  939. kEpidSigInvalid,
  940. EpidParseSigRlFile((void*)sigrl_inv_sign.data(), sigrl_inv_sign.size(),
  941. &this->kCert, (SigRl*)rl.data(), &rl_len));
  942. }
  943. TEST_F(EpidFileParser, SigRlParseRejectsBufWithInsufficientSize) {
  944. size_t rl_len = this->kShortSigRl.size() - 1;
  945. std::vector<uint8_t> rl(rl_len);
  946. EXPECT_EQ(kEpidBadArgErr,
  947. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  948. this->kShortSigRlFile.size(), &this->kCert,
  949. (SigRl*)rl.data(), &rl_len));
  950. }
  951. TEST_F(EpidFileParser, ReturnsProperSizeGivenOversizedSigRlBuf) {
  952. size_t rl_len = this->kShortSigRl.size() + 1;
  953. std::vector<uint8_t> oversized_rl(rl_len);
  954. EXPECT_EQ(kEpidNoErr,
  955. EpidParseSigRlFile((void*)this->kShortSigRlFile.data(),
  956. this->kShortSigRlFile.size(), &this->kCert,
  957. (SigRl*)oversized_rl.data(), &rl_len));
  958. std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1);
  959. EXPECT_EQ(this->kShortSigRl, rl);
  960. EXPECT_EQ(this->kShortSigRl.size(), rl_len);
  961. }
  962. //////////////////////////////////////////////////////////////////////////
  963. // EpidParseGroupRlFile Tests
  964. TEST_F(EpidFileParser, GroupRlParseProvidesRequiredLenWithNullDest) {
  965. size_t rl_len = 0;
  966. EXPECT_EQ(kEpidNoErr,
  967. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  968. this->kShortGroupRlFile.size(), &kCert,
  969. nullptr, &rl_len));
  970. EXPECT_EQ(rl_len, this->kShortGroupRl.size());
  971. }
  972. TEST_F(EpidFileParser, GroupRlParseFailsGivenNullParameters) {
  973. size_t rl_len = this->kShortGroupRl.size();
  974. std::vector<uint8_t> rl(rl_len);
  975. EXPECT_EQ(kEpidBadArgErr,
  976. EpidParseGroupRlFile(nullptr, this->kShortGroupRlFile.size(),
  977. &kCert, (GroupRl*)rl.data(), &rl_len));
  978. EXPECT_EQ(kEpidBadArgErr,
  979. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  980. this->kShortGroupRlFile.size(), nullptr,
  981. (GroupRl*)rl.data(), &rl_len));
  982. EXPECT_EQ(kEpidBadArgErr,
  983. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  984. this->kShortGroupRlFile.size(), &kCert,
  985. (GroupRl*)rl.data(), nullptr));
  986. EXPECT_EQ(kEpidBadArgErr,
  987. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  988. this->kShortGroupRlFile.size(), &kCert,
  989. nullptr, nullptr));
  990. }
  991. TEST_F(EpidFileParser, GroupRlParseFailsGivenUnsupportedCurve) {
  992. size_t rl_len = this->kShortGroupRl.size();
  993. std::vector<uint8_t> rl(rl_len);
  994. EpidCaCertificate unsupported_curve1(kCert);
  995. unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF;
  996. EXPECT_EQ(
  997. kEpidBadArgErr,
  998. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  999. this->kShortGroupRlFile.size(), &unsupported_curve1,
  1000. (GroupRl*)rl.data(), &rl_len));
  1001. EpidCaCertificate unsupported_curve2(kCert);
  1002. unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;
  1003. EXPECT_EQ(
  1004. kEpidBadArgErr,
  1005. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1006. this->kShortGroupRlFile.size(), &unsupported_curve2,
  1007. (GroupRl*)rl.data(), &rl_len));
  1008. EpidCaCertificate unsupported_curve3(kCert);
  1009. unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;
  1010. EXPECT_EQ(
  1011. kEpidBadArgErr,
  1012. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1013. this->kShortGroupRlFile.size(), &unsupported_curve3,
  1014. (GroupRl*)rl.data(), &rl_len));
  1015. EpidCaCertificate unsupported_curve4(kCert);
  1016. unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;
  1017. EXPECT_EQ(
  1018. kEpidBadArgErr,
  1019. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1020. this->kShortGroupRlFile.size(), &unsupported_curve4,
  1021. (GroupRl*)rl.data(), &rl_len));
  1022. EpidCaCertificate unsupported_curve5(kCert);
  1023. unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;
  1024. EXPECT_EQ(
  1025. kEpidBadArgErr,
  1026. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1027. this->kShortGroupRlFile.size(), &unsupported_curve5,
  1028. (GroupRl*)rl.data(), &rl_len));
  1029. EpidCaCertificate unsupported_curve6(kCert);
  1030. unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;
  1031. EXPECT_EQ(
  1032. kEpidBadArgErr,
  1033. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1034. this->kShortGroupRlFile.size(), &unsupported_curve6,
  1035. (GroupRl*)rl.data(), &rl_len));
  1036. }
  1037. TEST_F(EpidFileParser, GroupRlParseFailsGivenInvalidKeyInCertificate) {
  1038. size_t rl_len = this->kShortGroupRl.size();
  1039. std::vector<uint8_t> rl(rl_len);
  1040. EpidCaCertificate invalid_key_qx(kCert);
  1041. invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;
  1042. EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile(
  1043. (void*)this->kShortGroupRlFile.data(),
  1044. this->kShortGroupRlFile.size(), &invalid_key_qx,
  1045. (GroupRl*)rl.data(), &rl_len));
  1046. EpidCaCertificate invalid_key_qy(kCert);
  1047. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
  1048. invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  1049. EXPECT_EQ(kEpidBadArgErr, EpidParseGroupRlFile(
  1050. (void*)this->kShortGroupRlFile.data(),
  1051. this->kShortGroupRlFile.size(), &invalid_key_qy,
  1052. (GroupRl*)rl.data(), &rl_len));
  1053. EpidCaCertificate invalid_key_qx_qy(kCert);
  1054. invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  1055. invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] =
  1056. invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^
  1057. 0xFF;
  1058. EXPECT_EQ(
  1059. kEpidBadArgErr,
  1060. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1061. this->kShortGroupRlFile.size(), &invalid_key_qx_qy,
  1062. (GroupRl*)rl.data(), &rl_len));
  1063. }
  1064. TEST_F(EpidFileParser, RejectsGroupRlFileWithInvalidSize) {
  1065. size_t rl_len = this->kEmptyGroupRl.size();
  1066. std::vector<uint8_t> rl(rl_len);
  1067. EXPECT_EQ(kEpidBadArgErr,
  1068. EpidParseGroupRlFile((void*)this->kEmptyGroupRlFile.data(), 0,
  1069. &this->kCert, (GroupRl*)rl.data(), &rl_len));
  1070. EXPECT_EQ(kEpidBadArgErr,
  1071. EpidParseGroupRlFile((void*)this->kEmptyGroupRlFile.data(),
  1072. this->kEmptyGroupRlFile.size() - 1,
  1073. &this->kCert, (GroupRl*)rl.data(), &rl_len));
  1074. EXPECT_EQ(kEpidBadArgErr,
  1075. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1076. this->kEmptyGroupRlFile.size() + 1,
  1077. &this->kCert, (GroupRl*)rl.data(), &rl_len));
  1078. }
  1079. TEST_F(EpidFileParser, RejectsInvalidGroupRlFileType) {
  1080. size_t rl_len = this->kShortPrivRl.size();
  1081. std::vector<uint8_t> rl(rl_len);
  1082. EXPECT_EQ(kEpidBadArgErr,
  1083. EpidParseGroupRlFile((void*)this->kShortPrivRlFile.data(),
  1084. this->kShortPrivRlFile.size(), &this->kCert,
  1085. (GroupRl*)rl.data(), &rl_len));
  1086. }
  1087. TEST_F(EpidFileParser, RejectsGroupRlFileWithUnsupportedEpidVersion) {
  1088. size_t rl_len = this->kShortGroupRl.size();
  1089. std::vector<uint8_t> rl(rl_len);
  1090. std::vector<uint8_t> unsupported_epidver_file(this->kShortGroupRlFile);
  1091. unsupported_epidver_file[0] = {0x01};
  1092. EXPECT_EQ(kEpidBadArgErr,
  1093. EpidParseGroupRlFile((void*)unsupported_epidver_file.data(),
  1094. unsupported_epidver_file.size(), &this->kCert,
  1095. (GroupRl*)rl.data(), &rl_len));
  1096. }
  1097. TEST_F(EpidFileParser, ParsesEmptyGroupRl) {
  1098. size_t rl_len = this->kEmptyGroupRl.size();
  1099. std::vector<uint8_t> rl(rl_len);
  1100. EXPECT_EQ(kEpidNoErr,
  1101. EpidParseGroupRlFile(this->kEmptyGroupRlFile.data(),
  1102. this->kEmptyGroupRlFile.size(), &this->kCert,
  1103. (GroupRl*)rl.data(), &rl_len));
  1104. EXPECT_EQ(rl, this->kEmptyGroupRl);
  1105. }
  1106. TEST_F(EpidFileParser, ParsesShortGroupRl) {
  1107. size_t rl_len = this->kShortGroupRl.size();
  1108. std::vector<uint8_t> rl(rl_len);
  1109. EXPECT_EQ(kEpidNoErr,
  1110. EpidParseGroupRlFile(this->kShortGroupRlFile.data(),
  1111. this->kShortGroupRlFile.size(), &this->kCert,
  1112. (GroupRl*)rl.data(), &rl_len));
  1113. EXPECT_EQ(rl, this->kShortGroupRl);
  1114. }
  1115. TEST_F(EpidFileParser, ParsesLongGroupRl) {
  1116. std::vector<uint8_t> gid = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1117. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0xbc};
  1118. EcdsaSignature signature = {
  1119. 0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed,
  1120. 0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a,
  1121. 0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0xa4,
  1122. 0xaa, 0x8c, 0x1c, 0x91, 0xa2, 0x57, 0x07, 0x67, 0x0e, 0x58, 0xae,
  1123. 0xc7, 0x25, 0x15, 0x36, 0xda, 0xa0, 0xea, 0xc1, 0x15, 0x2b, 0xf2,
  1124. 0xc2, 0x33, 0x43, 0x3f, 0xc6, 0x56, 0xc1, 0x57, 0xbd,
  1125. };
  1126. std::vector<uint8_t> long_grouprl_file = {
  1127. /// Intel(R) EPID Version
  1128. 0x02, 0x00,
  1129. // File type
  1130. 0x00, 0x0f,
  1131. // RLver: revocation list version number
  1132. 0x00, 0x00, 0x00, 0x01,
  1133. // n3: number of entries in GroupRL
  1134. 0x00, 0x00, 0x00, 0x32,
  1135. };
  1136. for (int i = 0; i < 50; ++i) {
  1137. for (auto it : gid) {
  1138. long_grouprl_file.push_back(it);
  1139. }
  1140. }
  1141. for (auto it : signature.x.data) {
  1142. long_grouprl_file.push_back(it);
  1143. }
  1144. for (auto it : signature.y.data) {
  1145. long_grouprl_file.push_back(it);
  1146. }
  1147. size_t rl_len = long_grouprl_file.size() - sizeof(signature) - 4;
  1148. std::vector<uint8_t> rl(rl_len);
  1149. EXPECT_EQ(kEpidNoErr, EpidParseGroupRlFile(
  1150. long_grouprl_file.data(), long_grouprl_file.size(),
  1151. &this->kCert, (GroupRl*)rl.data(), &rl_len));
  1152. std::vector<uint8_t> expected_long_gr_rl(std::vector<uint8_t>(
  1153. &long_grouprl_file[4],
  1154. &long_grouprl_file[long_grouprl_file.size() - sizeof(signature)]));
  1155. EXPECT_EQ(expected_long_gr_rl, rl);
  1156. }
  1157. TEST_F(EpidFileParser, RejectsGroupRlFileWithInvalidSignature) {
  1158. size_t rl_len = this->kShortGroupRl.size();
  1159. std::vector<uint8_t> rl(rl_len);
  1160. std::vector<uint8_t> grouprl_inv_sign(this->kShortGroupRlFile);
  1161. grouprl_inv_sign[grouprl_inv_sign.size() - 1] =
  1162. grouprl_inv_sign[grouprl_inv_sign.size() - 1] ^ 0xFF;
  1163. EXPECT_EQ(kEpidSigInvalid,
  1164. EpidParseGroupRlFile((void*)grouprl_inv_sign.data(),
  1165. grouprl_inv_sign.size(), &this->kCert,
  1166. (GroupRl*)rl.data(), &rl_len));
  1167. }
  1168. TEST_F(EpidFileParser, GroupRlParseRejectsBufWithInsufficientSize) {
  1169. size_t rl_len = this->kShortGroupRl.size() - 1;
  1170. std::vector<uint8_t> rl(rl_len);
  1171. EXPECT_EQ(kEpidBadArgErr,
  1172. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1173. this->kShortGroupRlFile.size(), &this->kCert,
  1174. (GroupRl*)rl.data(), &rl_len));
  1175. }
  1176. TEST_F(EpidFileParser, ReturnsProperSizeGivenOversizedGroupRlBuf) {
  1177. size_t rl_len = this->kShortGroupRl.size() + 1;
  1178. std::vector<uint8_t> oversized_rl(rl_len);
  1179. EXPECT_EQ(kEpidNoErr,
  1180. EpidParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
  1181. this->kShortGroupRlFile.size(), &this->kCert,
  1182. (GroupRl*)oversized_rl.data(), &rl_len));
  1183. std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1);
  1184. EXPECT_EQ(this->kShortGroupRl, rl);
  1185. EXPECT_EQ(this->kShortGroupRl.size(), rl_len);
  1186. }
  1187. //////////////////////////////////////////////////////////////////////////
  1188. // EpidParseFileHeader Tests
  1189. TEST_F(EpidFileParser, ParseFileHeaderFailsGivenNullInParameters) {
  1190. EpidVersion epid_version = kNumEpidVersions;
  1191. EpidFileType file_type = kNumFileTypes;
  1192. EXPECT_EQ(kEpidBadArgErr, EpidParseFileHeader(nullptr, sizeof(EpidFileHeader),
  1193. &epid_version, &file_type));
  1194. }
  1195. TEST_F(EpidFileParser, ParseFileHeaderFailsGivenInvalidSize) {
  1196. EpidVersion epid_version = kNumEpidVersions;
  1197. EpidFileType file_type = kNumFileTypes;
  1198. EpidFileHeader epid_header = this->kCert.header;
  1199. EXPECT_EQ(kEpidBadArgErr,
  1200. EpidParseFileHeader((void*)&epid_header, sizeof(epid_header) - 1,
  1201. &epid_version, &file_type));
  1202. }
  1203. TEST_F(EpidFileParser, ParseFileHeaderReportsUnknownEpidVersion) {
  1204. // Since this variable must contain kNumEpidVersions after the function call,
  1205. // assign something different from kNumEpidVersions
  1206. EpidVersion epid_version = kEpid1x;
  1207. EpidFileType file_type = kNumFileTypes;
  1208. EpidFileHeader epid_header = this->kCert.header;
  1209. epid_header.epid_version.data[0] = 0x00;
  1210. EXPECT_EQ(kEpidNoErr,
  1211. EpidParseFileHeader((void*)&epid_header, sizeof(epid_header),
  1212. &epid_version, &file_type));
  1213. EXPECT_EQ(kNumEpidVersions, epid_version);
  1214. EXPECT_EQ(kIssuingCaPubKeyFile, file_type);
  1215. }
  1216. TEST_F(EpidFileParser, ParseFileHeaderReportsUnknownFileType) {
  1217. EpidVersion epid_version = kNumEpidVersions;
  1218. // Since this variable must contain kNumFileTypes after the function call,
  1219. // assign something not kNumFileTypes
  1220. EpidFileType file_type = kIssuingCaPubKeyFile;
  1221. EpidFileHeader epid_header = this->kCert.header;
  1222. epid_header.file_type.data[1] = 0x00;
  1223. EXPECT_EQ(kEpidNoErr,
  1224. EpidParseFileHeader((void*)&epid_header, sizeof(epid_header),
  1225. &epid_version, &file_type));
  1226. EXPECT_EQ(kEpid2x, epid_version);
  1227. EXPECT_EQ(kNumFileTypes, file_type);
  1228. }
  1229. TEST_F(EpidFileParser, ParseFileHeaderCanSkipExtractingSomeValues) {
  1230. EpidVersion epid_version = kNumEpidVersions;
  1231. EpidFileType file_type = kNumFileTypes;
  1232. EpidFileHeader epid_header = this->kCert.header;
  1233. EXPECT_EQ(kEpidNoErr,
  1234. EpidParseFileHeader((void*)&epid_header, sizeof(epid_header),
  1235. nullptr, &file_type));
  1236. EXPECT_EQ(kIssuingCaPubKeyFile, file_type);
  1237. EXPECT_EQ(kEpidNoErr,
  1238. EpidParseFileHeader((void*)&epid_header, sizeof(epid_header),
  1239. &epid_version, nullptr));
  1240. EXPECT_EQ(kEpid2x, epid_version);
  1241. EXPECT_EQ(kEpidNoErr,
  1242. EpidParseFileHeader((void*)&epid_header, sizeof(epid_header),
  1243. nullptr, nullptr));
  1244. }
  1245. TEST_F(EpidFileParser, ParseFileHeaderParsesCorrectly) {
  1246. EpidVersion epid_version = kNumEpidVersions;
  1247. EpidFileType file_type = kNumFileTypes;
  1248. EpidFileHeader epid_header = this->kCert.header;
  1249. EXPECT_EQ(kEpidNoErr,
  1250. EpidParseFileHeader((void*)&epid_header, sizeof(epid_header),
  1251. &epid_version, &file_type));
  1252. EXPECT_EQ(kEpid2x, epid_version);
  1253. EXPECT_EQ(kIssuingCaPubKeyFile, file_type);
  1254. EpidFileHeader epid_header2 = {0x01, 0x00, 0x00, 0x0B};
  1255. EXPECT_EQ(kEpidNoErr,
  1256. EpidParseFileHeader((void*)&epid_header2, sizeof(epid_header2),
  1257. &epid_version, &file_type));
  1258. EXPECT_EQ(kEpid1x, epid_version);
  1259. EXPECT_EQ(kSigRlRequestFile, file_type);
  1260. }
  1261. } // namespace