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