| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249 |
- /*
- * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
- *
- * SPDX-License-Identifier: Apache-2.0
- */
- #include "catch.hpp"
- #include "nvs.hpp"
- #include "nvs_test_api.h"
- #include "sdkconfig.h"
- #include "spi_flash_emulation.h"
- #include "nvs_partition_manager.hpp"
- #include "nvs_partition.hpp"
- #include "mbedtls/aes.h"
- #include "mbedtls/md.h"
- #include <sstream>
- #include <iostream>
- #include <fstream>
- #include <dirent.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <string.h>
- #include <string>
- #include "test_fixtures.hpp"
- #define TEST_ESP_ERR(rc, res) CHECK((rc) == (res))
- #define TEST_ESP_OK(rc) CHECK((rc) == ESP_OK)
- stringstream s_perf;
- bool memeq(void *a, size_t a_len, void *b, size_t b_len)
- {
- if (a_len != b_len) {
- return false;
- }
- return memcmp(a, b, a_len) == 0;
- }
- static void check_nvs_part_gen_args(SpiFlashEmulator *spi_flash_emulator,
- char const *part_name,
- int size,
- char const *filename,
- bool is_encr,
- nvs_sec_cfg_t *xts_cfg)
- {
- nvs_handle_t handle;
- esp_partition_t esp_part;
- esp_part.encrypted = false; // we're not testing generic flash encryption here, only the legacy NVS encryption
- esp_part.address = 0;
- esp_part.size = size * SPI_FLASH_SEC_SIZE;
- strncpy(esp_part.label, part_name, PART_NAME_MAX_SIZE);
- unique_ptr<nvs::Partition> part;
- if (is_encr) {
- nvs::NVSEncryptedPartition *enc_part = new (std::nothrow) nvs::NVSEncryptedPartition(&esp_part);
- REQUIRE(enc_part != nullptr);
- TEST_ESP_OK(enc_part->init(xts_cfg));
- part.reset(enc_part);
- } else {
- part.reset(new PartitionEmulation(spi_flash_emulator, 0, size, part_name));
- }
- TEST_ESP_OK( nvs::NVSPartitionManager::get_instance()->init_custom(part.get(), 0, size) );
- TEST_ESP_OK( nvs_open_from_partition(part_name, "dummyNamespace", NVS_READONLY, &handle));
- uint8_t u8v;
- TEST_ESP_OK( nvs_get_u8(handle, "dummyU8Key", &u8v));
- CHECK(u8v == 127);
- int8_t i8v;
- TEST_ESP_OK( nvs_get_i8(handle, "dummyI8Key", &i8v));
- CHECK(i8v == -128);
- uint16_t u16v;
- TEST_ESP_OK( nvs_get_u16(handle, "dummyU16Key", &u16v));
- CHECK(u16v == 32768);
- uint32_t u32v;
- TEST_ESP_OK( nvs_get_u32(handle, "dummyU32Key", &u32v));
- CHECK(u32v == 4294967295);
- int32_t i32v;
- TEST_ESP_OK( nvs_get_i32(handle, "dummyI32Key", &i32v));
- CHECK(i32v == -2147483648);
- char string_buf[256];
- const char test_str[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
- "Fusce quis risus justo.\n"
- "Suspendisse egestas in nisi sit amet auctor.\n"
- "Pellentesque rhoncus dictum sodales.\n"
- "In justo erat, viverra at interdum eget, interdum vel dui.";
- size_t str_len = sizeof(test_str);
- TEST_ESP_OK( nvs_get_str(handle, "dummyStringKey", string_buf, &str_len));
- CHECK(strncmp(string_buf, test_str, str_len) == 0);
- char buf[64] = {0};
- uint8_t hexdata[] = {0x01, 0x02, 0x03, 0xab, 0xcd, 0xef};
- size_t buflen = 64;
- int j;
- TEST_ESP_OK( nvs_get_blob(handle, "dummyHex2BinKey", buf, &buflen));
- CHECK(memeq(buf, buflen, hexdata, sizeof(hexdata)));
- uint8_t base64data[] = {'1', '2', '3', 'a', 'b', 'c'};
- TEST_ESP_OK( nvs_get_blob(handle, "dummyBase64Key", buf, &buflen));
- CHECK(memeq(buf, buflen, base64data, sizeof(base64data)));
- buflen = 64;
- uint8_t hexfiledata[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
- TEST_ESP_OK( nvs_get_blob(handle, "hexFileKey", buf, &buflen));
- CHECK(memeq(buf, buflen, hexfiledata, sizeof(hexfiledata)));
- buflen = 64;
- const char strfiledata[64] = "abcdefghijklmnopqrstuvwxyz";
- TEST_ESP_OK( nvs_get_str(handle, "stringFileKey", buf, &buflen));
- CHECK(strcmp(buf, strfiledata) == 0);
- char bin_data[5200];
- size_t bin_len = sizeof(bin_data);
- char binfiledata[5200];
- ifstream file;
- file.open(filename);
- file.read(binfiledata,5200);
- size_t binfile_len = file.gcount();
- TEST_ESP_OK( nvs_get_blob(handle, "binFileKey", bin_data, &bin_len));
- CHECK(memeq(bin_data, bin_len, binfiledata, binfile_len));
- file.close();
- nvs_close(handle);
- TEST_ESP_OK(nvs_flash_deinit_partition(part_name));
- }
- static void check_nvs_part_gen_args_mfg(SpiFlashEmulator *spi_flash_emulator,
- char const *part_name,
- int size,
- char const *filename,
- bool is_encr,
- nvs_sec_cfg_t *xts_cfg)
- {
- nvs_handle_t handle;
- esp_partition_t esp_part;
- esp_part.encrypted = false; // we're not testing generic flash encryption here, only the legacy NVS encryption
- esp_part.address = 0;
- esp_part.size = size * SPI_FLASH_SEC_SIZE;
- strncpy(esp_part.label, part_name, PART_NAME_MAX_SIZE);
- unique_ptr<nvs::Partition> part;
- if (is_encr) {
- nvs::NVSEncryptedPartition *enc_part = new (std::nothrow) nvs::NVSEncryptedPartition(&esp_part);
- REQUIRE(enc_part != nullptr);
- TEST_ESP_OK(enc_part->init(xts_cfg));
- part.reset(enc_part);
- } else {
- part.reset(new PartitionEmulation(spi_flash_emulator, 0, size, part_name));
- }
- TEST_ESP_OK( nvs::NVSPartitionManager::get_instance()->init_custom(part.get(), 0, size) );
- TEST_ESP_OK( nvs_open_from_partition(part_name, "dummyNamespace", NVS_READONLY, &handle));
- uint8_t u8v;
- TEST_ESP_OK( nvs_get_u8(handle, "dummyU8Key", &u8v));
- CHECK(u8v == 127);
- int8_t i8v;
- TEST_ESP_OK( nvs_get_i8(handle, "dummyI8Key", &i8v));
- CHECK(i8v == -128);
- uint16_t u16v;
- TEST_ESP_OK( nvs_get_u16(handle, "dummyU16Key", &u16v));
- CHECK(u16v == 32768);
- uint32_t u32v;
- TEST_ESP_OK( nvs_get_u32(handle, "dummyU32Key", &u32v));
- CHECK(u32v == 4294967295);
- int32_t i32v;
- TEST_ESP_OK( nvs_get_i32(handle, "dummyI32Key", &i32v));
- CHECK(i32v == -2147483648);
- char buf[64] = {0};
- size_t buflen = 64;
- TEST_ESP_OK( nvs_get_str(handle, "dummyStringKey", buf, &buflen));
- CHECK(strncmp(buf, "0A:0B:0C:0D:0E:0F", buflen) == 0);
- uint8_t hexdata[] = {0x01, 0x02, 0x03, 0xab, 0xcd, 0xef};
- buflen = 64;
- int j;
- TEST_ESP_OK( nvs_get_blob(handle, "dummyHex2BinKey", buf, &buflen));
- CHECK(memeq(buf, buflen, hexdata, sizeof(hexdata)));
- uint8_t base64data[] = {'1', '2', '3', 'a', 'b', 'c'};
- TEST_ESP_OK( nvs_get_blob(handle, "dummyBase64Key", buf, &buflen));
- CHECK(memeq(buf, buflen, base64data, sizeof(base64data)));
- buflen = 64;
- uint8_t hexfiledata[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
- TEST_ESP_OK( nvs_get_blob(handle, "hexFileKey", buf, &buflen));
- CHECK(memeq(buf, buflen, hexfiledata, sizeof(hexfiledata)));
- buflen = 64;
- const char strfiledata[64] = "abcdefghijklmnopqrstuvwxyz";
- TEST_ESP_OK( nvs_get_str(handle, "stringFileKey", buf, &buflen));
- CHECK(strcmp(buf, strfiledata) == 0);
- char bin_data[5200];
- size_t bin_len = sizeof(bin_data);
- char binfiledata[5200];
- ifstream file;
- file.open(filename);
- file.read(binfiledata,5200);
- size_t binfile_len = file.gcount();
- TEST_ESP_OK( nvs_get_blob(handle, "binFileKey", bin_data, &bin_len));
- CHECK(memeq(bin_data, bin_len, binfiledata, binfile_len));
- file.close();
- nvs_close(handle);
- TEST_ESP_OK(nvs_flash_deinit_partition(part_name));
- }
- #if CONFIG_NVS_ENCRYPTION
- TEST_CASE("check underlying xts code for 32-byte size sector encryption", "[nvs]")
- {
- auto toHex = [](char ch) {
- if(ch >= '0' && ch <= '9')
- return ch - '0';
- else if(ch >= 'a' && ch <= 'f')
- return ch - 'a' + 10;
- else if(ch >= 'A' && ch <= 'F')
- return ch - 'A' + 10;
- else
- return 0;
- };
- auto toHexByte = [toHex](char* c) {
- return 16 * toHex(c[0]) + toHex(c[1]);
- };
- auto toHexStream = [toHexByte](char* src, uint8_t* dest) {
- uint32_t cnt =0;
- char* p = src;
- while(*p != '\0' && *(p + 1) != '\0')
- {
- dest[cnt++] = toHexByte(p); p += 2;
- }
- };
- uint8_t eky_hex[2 * NVS_KEY_SIZE];
- uint8_t ptxt_hex[nvs::Page::ENTRY_SIZE], ctxt_hex[nvs::Page::ENTRY_SIZE], ba_hex[16];
- mbedtls_aes_xts_context ectx[1];
- mbedtls_aes_xts_context dctx[1];
- char eky[][2 * NVS_KEY_SIZE + 1] = {
- "0000000000000000000000000000000000000000000000000000000000000000",
- "1111111111111111111111111111111111111111111111111111111111111111"
- };
- char tky[][2 * NVS_KEY_SIZE + 1] = {
- "0000000000000000000000000000000000000000000000000000000000000000",
- "2222222222222222222222222222222222222222222222222222222222222222"
- };
- char blk_addr[][2*16 + 1] = {
- "00000000000000000000000000000000",
- "33333333330000000000000000000000"
- };
- char ptxt[][2 * nvs::Page::ENTRY_SIZE + 1] = {
- "0000000000000000000000000000000000000000000000000000000000000000",
- "4444444444444444444444444444444444444444444444444444444444444444"
- };
- char ctxt[][2 * nvs::Page::ENTRY_SIZE + 1] = {
- "d456b4fc2e620bba6ffbed27b956c9543454dd49ebd8d8ee6f94b65cbe158f73",
- "e622334f184bbce129a25b2ac76b3d92abf98e22df5bdd15af471f3db8946a85"
- };
- mbedtls_aes_xts_init(ectx);
- mbedtls_aes_xts_init(dctx);
- for(uint8_t cnt = 0; cnt < sizeof(eky)/sizeof(eky[0]); cnt++) {
- toHexStream(eky[cnt], eky_hex);
- toHexStream(tky[cnt], &eky_hex[NVS_KEY_SIZE]);
- toHexStream(ptxt[cnt], ptxt_hex);
- toHexStream(ctxt[cnt], ctxt_hex);
- toHexStream(blk_addr[cnt], ba_hex);
- CHECK(!mbedtls_aes_xts_setkey_enc(ectx, eky_hex, 2 * NVS_KEY_SIZE * 8));
- CHECK(!mbedtls_aes_xts_setkey_enc(dctx, eky_hex, 2 * NVS_KEY_SIZE * 8));
- CHECK(!mbedtls_aes_crypt_xts(ectx, MBEDTLS_AES_ENCRYPT, nvs::Page::ENTRY_SIZE, ba_hex, ptxt_hex, ptxt_hex));
- CHECK(!memcmp(ptxt_hex, ctxt_hex, nvs::Page::ENTRY_SIZE));
- }
- }
- TEST_CASE("test nvs apis with encryption enabled", "[nvs]")
- {
- nvs_handle_t handle_1;
- const uint32_t NVS_FLASH_SECTOR = 6;
- const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
- nvs_sec_cfg_t xts_cfg;
- for(int count = 0; count < NVS_KEY_SIZE; count++) {
- xts_cfg.eky[count] = 0x11;
- xts_cfg.tky[count] = 0x22;
- }
- EncryptedPartitionFixture fixture(&xts_cfg, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN);
- fixture.emu.randomize(100);
- fixture.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
- for (uint16_t i = NVS_FLASH_SECTOR; i <NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN; ++i) {
- fixture.emu.erase(i);
- }
- TEST_ESP_OK( nvs::NVSPartitionManager::get_instance()->
- init_custom(&fixture.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
- TEST_ESP_ERR(nvs_open("namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND);
- TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle_1));
- TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x12345678));
- TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x23456789));
- nvs_handle_t handle_2;
- TEST_ESP_OK(nvs_open("namespace2", NVS_READWRITE, &handle_2));
- TEST_ESP_OK(nvs_set_i32(handle_2, "foo", 0x3456789a));
- const char* str = "value 0123456789abcdef0123456789abcdef";
- TEST_ESP_OK(nvs_set_str(handle_2, "key", str));
- int32_t v1;
- TEST_ESP_OK(nvs_get_i32(handle_1, "foo", &v1));
- CHECK(0x23456789 == v1);
- int32_t v2;
- TEST_ESP_OK(nvs_get_i32(handle_2, "foo", &v2));
- CHECK(0x3456789a == v2);
- char buf[strlen(str) + 1];
- size_t buf_len = sizeof(buf);
- size_t buf_len_needed;
- TEST_ESP_OK(nvs_get_str(handle_2, "key", NULL, &buf_len_needed));
- CHECK(buf_len_needed == buf_len);
- size_t buf_len_short = buf_len - 1;
- TEST_ESP_ERR(ESP_ERR_NVS_INVALID_LENGTH, nvs_get_str(handle_2, "key", buf, &buf_len_short));
- CHECK(buf_len_short == buf_len);
- size_t buf_len_long = buf_len + 1;
- TEST_ESP_OK(nvs_get_str(handle_2, "key", buf, &buf_len_long));
- CHECK(buf_len_long == buf_len);
- TEST_ESP_OK(nvs_get_str(handle_2, "key", buf, &buf_len));
- CHECK(0 == strcmp(buf, str));
- nvs_close(handle_1);
- nvs_close(handle_2);
- TEST_ESP_OK(nvs_flash_deinit());
- }
- TEST_CASE("test nvs apis for nvs partition generator utility with encryption enabled", "[nvs_part_gen]")
- {
- int status;
- int childpid = fork();
- if (childpid == 0) {
- exit(execlp("cp", " cp",
- "-rf",
- "../nvs_partition_generator/testdata",
- ".", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../nvs_partition_generator/sample_multipage_blob.csv",
- "partition_encrypted.bin",
- "0x4000",
- "--inputkey",
- "../nvs_partition_generator/testdata/sample_encryption_keys.bin",
- "--outdir",
- "../nvs_partition_generator", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- SpiFlashEmulator emu("../nvs_partition_generator/partition_encrypted.bin");
- nvs_sec_cfg_t cfg;
- for (int count = 0; count < NVS_KEY_SIZE; count++) {
- cfg.eky[count] = 0x11;
- cfg.tky[count] = 0x22;
- }
- check_nvs_part_gen_args(&emu, NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("rm", " rm",
- "-rf",
- "testdata", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- TEST_CASE("test decrypt functionality for encrypted data", "[nvs_part_gen]")
- {
- //retrieving the temporary test data
- int status = system("cp -rf ../nvs_partition_generator/testdata .");
- CHECK(status == 0);
- //encoding data from sample_multipage_blob.csv
- status = system("python ../nvs_partition_generator/nvs_partition_gen.py generate ../nvs_partition_generator/sample_multipage_blob.csv partition_encoded.bin 0x5000 --outdir ../nvs_partition_generator");
- CHECK(status == 0);
- //encrypting data from sample_multipage_blob.csv
- status = system("python ../nvs_partition_generator/nvs_partition_gen.py encrypt ../nvs_partition_generator/sample_multipage_blob.csv partition_encrypted.bin 0x5000 --inputkey ../nvs_partition_generator/testdata/sample_encryption_keys.bin --outdir ../nvs_partition_generator");
- CHECK(status == 0);
- //encrypting data from sample_multipage_blob.csv (hmac-based scheme)
- status = system("python ../nvs_partition_generator/nvs_partition_gen.py encrypt ../nvs_partition_generator/sample_multipage_blob.csv partition_encrypted_hmac.bin 0x5000 --keygen --key_protect_hmac --kp_hmac_inputkey ../nvs_partition_generator/testdata/sample_hmac_key.bin --outdir ../nvs_partition_generator");
- CHECK(status == 0);
- //decrypting data from partition_encrypted.bin
- status = system("python ../nvs_partition_generator/nvs_partition_gen.py decrypt ../nvs_partition_generator/partition_encrypted.bin ../nvs_partition_generator/testdata/sample_encryption_keys.bin ../nvs_partition_generator/partition_decrypted.bin");
- CHECK(status == 0);
- status = system("diff ../nvs_partition_generator/partition_decrypted.bin ../nvs_partition_generator/partition_encoded.bin");
- CHECK(status == 0);
- //decrypting data from partition_encrypted_hmac.bin
- status = system("python ../nvs_partition_generator/nvs_partition_gen.py decrypt ../nvs_partition_generator/partition_encrypted_hmac.bin ../nvs_partition_generator/testdata/sample_encryption_keys_hmac.bin ../nvs_partition_generator/partition_decrypted_hmac.bin");
- CHECK(status == 0);
- status = system("diff ../nvs_partition_generator/partition_decrypted_hmac.bin ../nvs_partition_generator/partition_encoded.bin");
- CHECK(status == 0);
- CHECK(WEXITSTATUS(status) == 0);
- //cleaning up the temporary test data
- status = system("rm -rf testdata");
- CHECK(status == 0);
- }
- TEST_CASE("test nvs apis for nvs partition generator utility with encryption enabled using keygen", "[nvs_part_gen]")
- {
- int childpid = fork();
- int status;
- if (childpid == 0) {
- exit(execlp("cp", " cp",
- "-rf",
- "../nvs_partition_generator/testdata",
- ".", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("rm", " rm",
- "-rf",
- "../nvs_partition_generator/keys", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../nvs_partition_generator/sample_multipage_blob.csv",
- "partition_encrypted_using_keygen.bin",
- "0x4000",
- "--keygen",
- "--outdir",
- "../nvs_partition_generator", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- DIR *dir;
- struct dirent *file;
- char *filename;
- char *files;
- char *file_ext;
- dir = opendir("../nvs_partition_generator/keys");
- while ((file = readdir(dir)) != NULL) {
- filename = file->d_name;
- files = strrchr(filename, '.');
- if (files != NULL) {
- file_ext = files + 1;
- if (strncmp(file_ext, "bin", 3) == 0) {
- break;
- }
- }
- }
- std::string encr_file = std::string("../nvs_partition_generator/keys/") + std::string(filename);
- SpiFlashEmulator emu("../nvs_partition_generator/partition_encrypted_using_keygen.bin");
- char buffer[64];
- FILE *fp;
- fp = fopen(encr_file.c_str(), "rb");
- fread(buffer, sizeof(buffer), 1, fp);
- fclose(fp);
- nvs_sec_cfg_t cfg;
- for (int count = 0; count < NVS_KEY_SIZE; count++) {
- cfg.eky[count] = buffer[count] & 255;
- cfg.tky[count] = buffer[count + 32] & 255;
- }
- check_nvs_part_gen_args(&emu, NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
- }
- TEST_CASE("test nvs apis for nvs partition generator utility with encryption enabled using inputkey", "[nvs_part_gen]")
- {
- int childpid = fork();
- int status;
- DIR *dir;
- struct dirent *file;
- char *filename;
- char *files;
- char *file_ext;
- dir = opendir("../nvs_partition_generator/keys");
- while ((file = readdir(dir)) != NULL) {
- filename = file->d_name;
- files = strrchr(filename, '.');
- if (files != NULL) {
- file_ext = files + 1;
- if (strncmp(file_ext, "bin", 3) == 0) {
- break;
- }
- }
- }
- std::string encr_file = std::string("../nvs_partition_generator/keys/") + std::string(filename);
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../nvs_partition_generator/sample_multipage_blob.csv",
- "partition_encrypted_using_keyfile.bin",
- "0x4000",
- "--inputkey",
- encr_file.c_str(),
- "--outdir",
- "../nvs_partition_generator", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- SpiFlashEmulator emu("../nvs_partition_generator/partition_encrypted_using_keyfile.bin");
- char buffer[64];
- FILE *fp;
- fp = fopen(encr_file.c_str(), "rb");
- fread(buffer, sizeof(buffer), 1, fp);
- fclose(fp);
- nvs_sec_cfg_t cfg;
- for (int count = 0; count < NVS_KEY_SIZE; count++) {
- cfg.eky[count] = buffer[count] & 255;
- cfg.tky[count] = buffer[count + 32] & 255;
- }
- check_nvs_part_gen_args(&emu, NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("rm", " rm",
- "-rf",
- "../nvs_partition_generator/keys", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("rm", " rm",
- "-rf",
- "testdata", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- static void compute_nvs_keys_with_hmac(nvs_sec_cfg_t *cfg, void *hmac_key)
- {
- unsigned char key_bytes[32] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
- 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
- 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20 };
- if (hmac_key != NULL){
- memcpy(key_bytes, hmac_key, 32);
- }
- unsigned char ekey_seed[32], tkey_seed[32];
- for (unsigned int i = 0; i < sizeof(ekey_seed); i+=4) {
- ekey_seed[i] = 0x5A;
- ekey_seed[i + 1] = 0x5A;
- ekey_seed[i + 2] = 0xBE;
- ekey_seed[i + 3] = 0xAE;
- }
- for (unsigned int i = 0; i < sizeof(tkey_seed); i+=4) {
- tkey_seed[i] = 0xA5;
- tkey_seed[i + 1] = 0xA5;
- tkey_seed[i + 2] = 0xDE;
- tkey_seed[i + 3] = 0xCE;
- }
- const mbedtls_md_type_t alg = MBEDTLS_MD_SHA256;
- mbedtls_md_context_t ctx;
- mbedtls_md_init(&ctx);
- const mbedtls_md_info_t *info = mbedtls_md_info_from_type(alg);
- mbedtls_md_setup(&ctx, info, 1);
- mbedtls_md_hmac_starts(&ctx, key_bytes, sizeof(key_bytes));
- mbedtls_md_hmac_update(&ctx, ekey_seed, sizeof(ekey_seed));
- mbedtls_md_hmac_finish(&ctx, cfg->eky);
- mbedtls_md_hmac_reset(&ctx);
- mbedtls_md_hmac_update(&ctx, tkey_seed, sizeof(tkey_seed));
- mbedtls_md_hmac_finish(&ctx, cfg->tky);
- assert(memcmp(cfg->eky, cfg->tky, NVS_KEY_SIZE));
- mbedtls_md_free(&ctx);
- }
- TEST_CASE("test nvs apis for nvs partition generator utility with encryption enabled using keygen (user-provided HMAC-key)", "[nvs_part_gen]")
- {
- int childpid = fork();
- int status;
- if (childpid == 0) {
- exit(execlp("cp", " cp",
- "-rf",
- "../nvs_partition_generator/testdata",
- ".", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("rm", " rm",
- "-rf",
- "../nvs_partition_generator/keys", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../nvs_partition_generator/sample_multipage_blob.csv",
- "partition_encrypted_using_keygen_hmac.bin",
- "0x4000",
- "--keygen",
- "--key_protect_hmac",
- "--kp_hmac_inputkey",
- "../nvs_partition_generator/testdata/sample_hmac_key.bin",
- "--outdir",
- "../nvs_partition_generator", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- SpiFlashEmulator emu("../nvs_partition_generator/partition_encrypted_using_keygen_hmac.bin");
- nvs_sec_cfg_t cfg;
- compute_nvs_keys_with_hmac(&cfg, NULL);
- check_nvs_part_gen_args(&emu, NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
- }
- TEST_CASE("test nvs apis for nvs partition generator utility with encryption enabled using keygen (dynamically generated HMAC-key)", "[nvs_part_gen]")
- {
- int childpid = fork();
- int status;
- if (childpid == 0) {
- exit(execlp("cp", " cp",
- "-rf",
- "../nvs_partition_generator/testdata",
- ".", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("rm", " rm",
- "-rf",
- "../nvs_partition_generator/keys", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../nvs_partition_generator/sample_multipage_blob.csv",
- "partition_encrypted_using_keygen_hmac.bin",
- "0x4000",
- "--keygen",
- "--key_protect_hmac",
- "--kp_hmac_keygen",
- "--outdir",
- "../nvs_partition_generator", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- DIR *dir;
- struct dirent *file;
- char *filename;
- char *files;
- char *file_ext;
- char *hmac_key_file;
- dir = opendir("../nvs_partition_generator/keys");
- while ((file = readdir(dir)) != NULL) {
- filename = file->d_name;
- file_ext = NULL;
- files = strrchr(filename, '.');
- if (files != NULL) {
- file_ext = files + 1;
- if (strncmp(file_ext, "bin", 3) != 0) {
- continue;
- }
- }
- if (strstr(filename, "hmac") != NULL) {
- hmac_key_file = filename;
- }
- }
- std::string hmac_key_path = std::string("../nvs_partition_generator/keys/") + std::string(hmac_key_file);
- SpiFlashEmulator emu("../nvs_partition_generator/partition_encrypted_using_keygen_hmac.bin");
- char hmac_key_buf[32];
- FILE *fp;
- fp = fopen(hmac_key_path.c_str(), "rb");
- fread(hmac_key_buf, sizeof(hmac_key_buf), 1, fp);
- fclose(fp);
- nvs_sec_cfg_t cfg;
- compute_nvs_keys_with_hmac(&cfg, hmac_key_buf);
- check_nvs_part_gen_args(&emu, NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
- }
- TEST_CASE("check and read data from partition generated via manufacturing utility with encryption enabled using sample inputkey", "[mfg_gen]")
- {
- int childpid = fork();
- int status;
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf ../../../tools/mass_mfg/host_test | \
- cp -rf ../../../tools/mass_mfg/testdata mfg_testdata | \
- cp -rf ../nvs_partition_generator/testdata . | \
- mkdir -p ../../../tools/mass_mfg/host_test", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../../../tools/mass_mfg/mfg_gen.py",
- "generate",
- "../../../tools/mass_mfg/samples/sample_config.csv",
- "../../../tools/mass_mfg/samples/sample_values_multipage_blob.csv",
- "Test",
- "0x4000",
- "--outdir",
- "../../../tools/mass_mfg/host_test",
- "--version",
- "2",
- "--inputkey",
- "mfg_testdata/sample_encryption_keys.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../../../tools/mass_mfg/host_test/csv/Test-1.csv",
- "../nvs_partition_generator/Test-1-partition-encrypted.bin",
- "0x4000",
- "--version",
- "2",
- "--inputkey",
- "testdata/sample_encryption_keys.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- SpiFlashEmulator emu1("../../../tools/mass_mfg/host_test/bin/Test-1.bin");
- nvs_sec_cfg_t cfg;
- for (int count = 0; count < NVS_KEY_SIZE; count++) {
- cfg.eky[count] = 0x11;
- cfg.tky[count] = 0x22;
- }
- check_nvs_part_gen_args_mfg(&emu1, NVS_DEFAULT_PART_NAME, 4, "mfg_testdata/sample_multipage_blob.bin", true, &cfg);
- SpiFlashEmulator emu2("../nvs_partition_generator/Test-1-partition-encrypted.bin");
- check_nvs_part_gen_args_mfg(&emu2, NVS_DEFAULT_PART_NAME, 4, "testdata/sample_multipage_blob.bin", true, &cfg);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf ../../../tools/mass_mfg/host_test | \
- rm -rf mfg_testdata | \
- rm -rf testdata", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- TEST_CASE("check and read data from partition generated via manufacturing utility with encryption enabled using new generated key", "[mfg_gen]")
- {
- int childpid = fork();
- int status;
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf ../../../tools/mass_mfg/host_test | \
- cp -rf ../../../tools/mass_mfg/testdata mfg_testdata | \
- cp -rf ../nvs_partition_generator/testdata . | \
- mkdir -p ../../../tools/mass_mfg/host_test", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../../../tools/mass_mfg/mfg_gen.py",
- "generate-key",
- "--outdir",
- "../../../tools/mass_mfg/host_test",
- "--keyfile",
- "encr_keys_host_test.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../../../tools/mass_mfg/mfg_gen.py",
- "generate",
- "../../../tools/mass_mfg/samples/sample_config.csv",
- "../../../tools/mass_mfg/samples/sample_values_multipage_blob.csv",
- "Test",
- "0x4000",
- "--outdir",
- "../../../tools/mass_mfg/host_test",
- "--version",
- "2",
- "--inputkey",
- "../../../tools/mass_mfg/host_test/keys/encr_keys_host_test.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../../../tools/mass_mfg/host_test/csv/Test-1.csv",
- "../nvs_partition_generator/Test-1-partition-encrypted.bin",
- "0x4000",
- "--version",
- "2",
- "--inputkey",
- "../../../tools/mass_mfg/host_test/keys/encr_keys_host_test.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- }
- SpiFlashEmulator emu1("../../../tools/mass_mfg/host_test/bin/Test-1.bin");
- char buffer[64];
- FILE *fp;
- fp = fopen("../../../tools/mass_mfg/host_test/keys/encr_keys_host_test.bin", "rb");
- fread(buffer, sizeof(buffer), 1, fp);
- fclose(fp);
- nvs_sec_cfg_t cfg;
- for (int count = 0; count < NVS_KEY_SIZE; count++) {
- cfg.eky[count] = buffer[count] & 255;
- cfg.tky[count] = buffer[count + 32] & 255;
- }
- check_nvs_part_gen_args_mfg(&emu1, NVS_DEFAULT_PART_NAME, 4, "mfg_testdata/sample_multipage_blob.bin", true, &cfg);
- SpiFlashEmulator emu2("../nvs_partition_generator/Test-1-partition-encrypted.bin");
- check_nvs_part_gen_args_mfg(&emu2, NVS_DEFAULT_PART_NAME, 4, "testdata/sample_multipage_blob.bin", true, &cfg);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf keys | \
- rm -rf mfg_testdata | \
- rm -rf testdata | \
- rm -rf ../../../tools/mass_mfg/host_test", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- TEST_CASE("check and read data from partition generated via manufacturing utility with encryption enabled using new generated key (user-provided HMAC-key)", "[mfg_gen]")
- {
- int childpid = fork();
- int status;
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf ../../../tools/mass_mfg/host_test | \
- cp -rf ../../../tools/mass_mfg/testdata mfg_testdata | \
- cp -rf ../nvs_partition_generator/testdata . | \
- mkdir -p ../../../tools/mass_mfg/host_test", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../../../tools/mass_mfg/mfg_gen.py",
- "generate",
- "../../../tools/mass_mfg/samples/sample_config.csv",
- "../../../tools/mass_mfg/samples/sample_values_multipage_blob.csv",
- "Test",
- "0x4000",
- "--version",
- "2",
- "--keygen",
- "--key_protect_hmac",
- "--kp_hmac_inputkey",
- "mfg_testdata/sample_hmac_key.bin",
- "--outdir",
- "../../../tools/mass_mfg/host_test",NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../../../tools/mass_mfg/host_test/csv/Test-1.csv",
- "../nvs_partition_generator/Test-1-partition-encrypted-hmac.bin",
- "0x4000",
- "--version",
- "2",
- "--keygen",
- "--key_protect_hmac",
- "--kp_hmac_inputkey",
- "mfg_testdata/sample_hmac_key.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- SpiFlashEmulator emu1("../../../tools/mass_mfg/host_test/bin/Test-1.bin");
- nvs_sec_cfg_t cfg;
- compute_nvs_keys_with_hmac(&cfg, NULL);
- check_nvs_part_gen_args_mfg(&emu1, NVS_DEFAULT_PART_NAME, 4, "mfg_testdata/sample_multipage_blob.bin", true, &cfg);
- SpiFlashEmulator emu2("../nvs_partition_generator/Test-1-partition-encrypted-hmac.bin");
- check_nvs_part_gen_args_mfg(&emu2, NVS_DEFAULT_PART_NAME, 4, "testdata/sample_multipage_blob.bin", true, &cfg);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf ../../../tools/mass_mfg/host_test | \
- rm -rf mfg_testdata | \
- rm -rf testdata", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- TEST_CASE("check and read data from partition generated via manufacturing utility with encryption enabled using new generated key (dynamically generated HMAC-key)", "[mfg_gen]")
- {
- int childpid = fork();
- int status;
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf ../../../tools/mass_mfg/host_test | \
- cp -rf ../../../tools/mass_mfg/testdata mfg_testdata | \
- cp -rf ../nvs_partition_generator/testdata . | \
- mkdir -p ../../../tools/mass_mfg/host_test", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../../../tools/mass_mfg/mfg_gen.py",
- "generate-key",
- "--outdir",
- "../../../tools/mass_mfg/host_test",
- "--key_protect_hmac",
- "--kp_hmac_keygen",
- "--kp_hmac_keyfile",
- "hmac_key_host_test.bin",
- "--keyfile",
- "encr_keys_host_test.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../../../tools/mass_mfg/mfg_gen.py",
- "generate",
- "../../../tools/mass_mfg/samples/sample_config.csv",
- "../../../tools/mass_mfg/samples/sample_values_multipage_blob.csv",
- "Test",
- "0x4000",
- "--outdir",
- "../../../tools/mass_mfg/host_test",
- "--version",
- "2",
- "--inputkey",
- "../../../tools/mass_mfg/host_test/keys/encr_keys_host_test.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("python", "python",
- "../nvs_partition_generator/nvs_partition_gen.py",
- "encrypt",
- "../../../tools/mass_mfg/host_test/csv/Test-1.csv",
- "../nvs_partition_generator/Test-1-partition-encrypted-hmac.bin",
- "0x4000",
- "--version",
- "2",
- "--inputkey",
- "../../../tools/mass_mfg/host_test/keys/encr_keys_host_test.bin", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- }
- }
- SpiFlashEmulator emu1("../../../tools/mass_mfg/host_test/bin/Test-1.bin");
- char hmac_key_buf[32];
- FILE *fp;
- fp = fopen("../../../tools/mass_mfg/host_test/keys/hmac_key_host_test.bin", "rb");
- fread(hmac_key_buf, sizeof(hmac_key_buf), 1, fp);
- fclose(fp);
- nvs_sec_cfg_t cfg;
- compute_nvs_keys_with_hmac(&cfg, hmac_key_buf);
- check_nvs_part_gen_args_mfg(&emu1, NVS_DEFAULT_PART_NAME, 4, "mfg_testdata/sample_multipage_blob.bin", true, &cfg);
- SpiFlashEmulator emu2("../nvs_partition_generator/Test-1-partition-encrypted-hmac.bin");
- check_nvs_part_gen_args_mfg(&emu2, NVS_DEFAULT_PART_NAME, 4, "testdata/sample_multipage_blob.bin", true, &cfg);
- childpid = fork();
- if (childpid == 0) {
- exit(execlp("bash", " bash",
- "-c",
- "rm -rf keys | \
- rm -rf mfg_testdata | \
- rm -rf testdata | \
- rm -rf ../../../tools/mass_mfg/host_test", NULL));
- } else {
- CHECK(childpid > 0);
- waitpid(childpid, &status, 0);
- CHECK(WEXITSTATUS(status) == 0);
- }
- }
- #endif
|