file_parser-test.cc 67 KB

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