nvs_util: Add support for creation of unique encryption keys

(cherry picked from commit e1f466e708c2c1b825e955ec28b70dc3058f9262)
This commit is contained in:
Shivani Tipnis 2018-11-28 10:56:06 +05:30
parent 8480e79ae2
commit 5d2c23c8ab
2 changed files with 180 additions and 94 deletions

View file

@ -37,8 +37,10 @@ try:
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
except ImportError:
print("cryptography package needs to be installed.\nRun: pip install cryptography>=2.1.4")
sys.exit(0)
print('The cryptography package is not installed.'
'Please refer to the Get Started section of the ESP-IDF Programming Guide for '
'setting up the required packages.')
raise
VERSION1_PRINT = "v1 - Multipage Blob Support Disabled"
VERSION2_PRINT = "v2 - Multipage Blob Support Enabled"
@ -621,7 +623,7 @@ def write_entry(nvs_instance, key, datatype, encoding, value):
if datatype == "file":
abs_file_path = value
if os.path.isabs(value) is False:
script_dir = os.path.dirname(__file__)
script_dir = os.getcwd()
abs_file_path = os.path.join(script_dir, value)
with open(abs_file_path, 'rb') as f:

View file

@ -2127,7 +2127,20 @@ static void check_nvs_part_gen_args(char const *part_name, int size, char const
TEST_CASE("check and read data from partition generated via partition generation utility with multipage blob support disabled", "[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) != -1);
childpid = fork();
if (childpid == 0) {
exit(execlp("python", "python",
"../nvs_partition_generator/nvs_partition_gen.py",
@ -2145,18 +2158,42 @@ TEST_CASE("check and read data from partition generated via partition generation
waitpid(childpid, &status, 0);
CHECK(WEXITSTATUS(status) != -1);
}
}
SpiFlashEmulator emu("../nvs_partition_generator/partition_single_page.bin");
TEST_ESP_OK(nvs_flash_deinit());
check_nvs_part_gen_args("test", 3, "../nvs_partition_generator/testdata/sample_singlepage_blob.bin", false, NULL);
}
if (childpid == 0) {
exit(execlp("rm", " rm",
"-rf",
"testdata",NULL));
} else {
CHECK(childpid > 0);
waitpid(childpid, &status, 0);
CHECK(WEXITSTATUS(status) != -1);
}
}
TEST_CASE("check and read data from partition generated via partition generation utility with multipage blob support 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) != -1);
childpid = fork();
if (childpid == 0) {
exit(execlp("python", "python",
"../nvs_partition_generator/nvs_partition_gen.py",
@ -2170,15 +2207,25 @@ TEST_CASE("check and read data from partition generated via partition generation
"v2",NULL));
} else {
CHECK(childpid > 0);
int status;
waitpid(childpid, &status, 0);
CHECK(WEXITSTATUS(status) != -1);
}
}
SpiFlashEmulator emu("../nvs_partition_generator/partition_multipage_blob.bin");
check_nvs_part_gen_args("test", 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin",false,NULL);
if (childpid == 0) {
exit(execlp("rm", " rm",
"-rf",
"testdata",NULL));
} else {
CHECK(childpid > 0);
waitpid(childpid, &status, 0);
CHECK(WEXITSTATUS(status) != -1);
}
}
#if CONFIG_NVS_ENCRYPTION
@ -2322,7 +2369,20 @@ TEST_CASE("test nvs apis with encryption enabled", "[nvs]")
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) != -1);
childpid = fork();
if (childpid == 0) {
exit(execlp("python", "python",
"../nvs_partition_generator/nvs_partition_gen.py",
@ -2338,10 +2398,10 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
"../nvs_partition_generator/testdata/sample_encryption_keys.bin",NULL));
} else {
CHECK(childpid > 0);
int status;
waitpid(childpid, &status, 0);
CHECK(WEXITSTATUS(status) != -1);
}
}
SpiFlashEmulator emu("../nvs_partition_generator/partition_encrypted.bin");
@ -2353,6 +2413,18 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
check_nvs_part_gen_args(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) != -1);
}
}
@ -2362,9 +2434,10 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
int status;
if (childpid == 0) {
exit(execlp("rm", " rm",
exit(execlp("cp", " cp",
"-rf",
"keys",NULL));
"../nvs_partition_generator/testdata",
".",NULL));
} else {
CHECK(childpid > 0);
waitpid(childpid, &status, 0);
@ -2516,6 +2589,17 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
waitpid(childpid, &status, 0);
CHECK(WEXITSTATUS(status) != -1);
childpid = fork();
if (childpid == 0) {
exit(execlp("rm", " rm",
"-rf",
"testdata",NULL));
} else {
CHECK(childpid > 0);
waitpid(childpid, &status, 0);
CHECK(WEXITSTATUS(status) != -1);
}
}
}