1 #include "keymaster_tools.h" 2 #include "avb_tools.h" 3 4 #include "gtest/gtest.h" 5 #include "nugget/app/keymaster/keymaster.pb.h" 6 7 #include <app_nugget.h> 8 #include "Keymaster.client.h" 9 #include <keymaster.h> 10 #include <nos/NuggetClient.h> 11 12 #include <chrono> 13 #include <iostream> 14 #include <thread> 15 #include <vector> 16 17 #ifdef ANDROID 18 #include <android-base/endian.h> 19 #include "nos/CitadeldProxyClient.h" 20 #else 21 #include "gflags/gflags.h" 22 #endif // ANDROID 23 24 using std::string; 25 using namespace nugget::app::keymaster; 26 using namespace avb_tools; 27 28 namespace keymaster_tools { 29 SetRootOfTrust(nos::NuggetClientInterface * client)30void SetRootOfTrust(nos::NuggetClientInterface *client) 31 { 32 33 // Do keymaster setup that is normally executed by the bootloader. 34 avb_tools::SetBootloader(client); 35 36 SetRootOfTrustRequest request; 37 SetRootOfTrustResponse response; 38 Keymaster service(*client); 39 request.set_digest(string(32, '\0')); 40 ASSERT_NO_ERROR(service.SetRootOfTrust(request, &response), ""); 41 EXPECT_EQ((ErrorCode)response.error_code(), ErrorCode::OK); 42 43 avb_tools::BootloaderDone(client); 44 } 45 SetBootState(nos::NuggetClientInterface * client)46void SetBootState(nos::NuggetClientInterface *client) 47 { 48 49 // Do keymaster setup that is normally executed by the bootloader. 50 avb_tools::SetBootloader(client); 51 52 SetBootStateRequest request; 53 SetBootStateResponse response; 54 Keymaster service(*client); 55 request.set_public_key(string(32, '\0')); 56 request.set_boot_hash(string(32, '\0')); 57 ASSERT_NO_ERROR(service.SetBootState(request, &response), ""); 58 EXPECT_EQ((ErrorCode)response.error_code(), ErrorCode::OK); 59 60 avb_tools::BootloaderDone(client); 61 } 62 63 } // namespace keymaster_tools 64