|
|
|
@ -25,8 +25,6 @@ |
|
|
|
|
#include "lz4.h" |
|
|
|
|
#include "utils.h" |
|
|
|
|
|
|
|
|
|
#define __packed __attribute__((__packed__)) |
|
|
|
|
|
|
|
|
|
#define TEST_FAILURE 1 |
|
|
|
|
#define TEST_SUCCESS 0 |
|
|
|
|
#define INCFS_MAX_MTREE_LEVELS 8 |
|
|
|
@ -69,101 +67,6 @@ struct linux_dirent64 { |
|
|
|
|
char d_name[0]; |
|
|
|
|
} __packed; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The certificate below and the private key were created by calling: |
|
|
|
|
* openssl req -x509 -newkey rsa:4096 -keyout private.key -out cert.crt |
|
|
|
|
* -days 1000 -sha256 -nodes -outform PEM -subj |
|
|
|
|
* "/C=US/ST=WA/L=Kirkland/O=Example/OU=Org/CN=www.example.com" |
|
|
|
|
*/ |
|
|
|
|
char x509_cert[] = |
|
|
|
|
"-----BEGIN CERTIFICATE-----\n" |
|
|
|
|
"MIIFvzCCA6egAwIBAgIUXpwqelEljm6BBllRQGHLrls2MYgwDQYJKoZIhvcNAQEL\n" |
|
|
|
|
"BQAwbzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xETAPBgNVBAcM\n" |
|
|
|
|
"CEtpcmtsYW5kMRAwDgYDVQQKDAdFeGFtcGxlMQwwCgYDVQQLDANPcmcxGDAWBgNV\n" |
|
|
|
|
"BAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xOTA4MDgyMzA3MDZaFw0yMjA1MDQyMzA3\n" |
|
|
|
|
"MDZaMG8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApXYXNoaW5ndG9uMREwDwYDVQQH\n" |
|
|
|
|
"DAhLaXJrbGFuZDEQMA4GA1UECgwHRXhhbXBsZTEMMAoGA1UECwwDT3JnMRgwFgYD\n" |
|
|
|
|
"VQQDDA93d3cuZXhhbXBsZS5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK\n" |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Ipk3B\n" |
|
|
|
|
"j5JgCmIxAcPnzj42rduRSx421hHMZhbAIWI/JL4ZSF64qlG0YrmJDXlJgSMoyst5\n" |
|
|
|
|
"biUqeWgO7Js5udPt3zhkeA62z3hGM6dE5B3k7gHTaKKtK17+UeR9imZKsOK8GBnM\n" |
|
|
|
|
"rxMPI6XghxxAK2OQ/r09DHDiyf/GxgOE46oknfXfMPx3HaSvDKrZUTZ+UvVbM5c2\n" |
|
|
|
|
"5eXOgH5UO/e4llLknJK7CoP/R6G7pV44iT4t4t9FMnvCYvavAHwfR+6z5vTF3o8a\n" |
|
|
|
|
"wd80fC8z1vfLsIPLROdzBl9rGCvv536fPiEA677CM1AZkjfT0a9DVzrE1NDvuCUF\n" |
|
|
|
|
"0KgEdiNwux+hO6dbTyiS38yPT6TbpoWJptJmFhFkC4hGvUgoX/TI0covSyf74VRH\n" |
|
|
|
|
"k3BHojOBMYiX1K66xoN7fhlGK8cith3L0XXPB8CgSEUPWURvm8RCaGuX2T3FZomF\n" |
|
|
|
|
"BCnNpN+WNnN3Yf4OkjtuvtxxktUU7pfVLsUxrdpo/ph4rWm6U83VT/Zlq92aF4vW\n" |
|
|
|
|
"QJ+7uraQFip7e+Gy9g3UJINm3B7b1C4ch/Z/upCZESOI/23sVGzkfTgOrS+23i6/\n" |
|
|
|
|
"Vi9YW75zySC2FCa1AWMS1NmS5qfDSycJUgD6YvOUg0C54ZI=\n" |
|
|
|
|
"-----END CERTIFICATE-----"; |
|
|
|
|
|
|
|
|
|
char private_key[] = |
|
|
|
|
"-----BEGIN PRIVATE KEY-----\n" |
|
|
|
|
"MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC1LuFW/lDV/Gfl\n" |
|
|
|
|
"qFMz7RDvFFgWld982ZuDJRaK55JNj+MI4RZNL61PDw43NeeJtqUoVxSLS9wHURjS\n" |
|
|
|
|
"jD/CV5GudUOnzGfbwFlLko+jhYRT4HNFS+5ys1FEJLtAuYcY4P9GH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ggEBAJWxS7EuB/qL7fOz0o3HRy0plR3qbwZ0pLoCz0Ii7WxraBS1yQwmxif1\n" |
|
|
|
|
"Rgv89GyFqg1yQl3CSrMiw7oC9WxxxuiEZDO18c4KO3NTv9K4itN9OPQVBTHmEhod\n" |
|
|
|
|
"KWcyP4/W/Sfuae77PyclSqUsAARRrKYn2fpLTS5ibaU0QZgHmdPgYDUrPr+6PHKK\n" |
|
|
|
|
"ZfQKU2uBfuo6zoMbMmFi3UYG49j9rv4d6v+44vS1MPHV9JK/LD8YfBhgx8Pg/u6D\n" |
|
|
|
|
"nUgipS48pkGjJr2u2Vu7Mx70vqz0Yf2neyyDbdLtkYauC4w7YKPTD0yzDJyGuAeB\n" |
|
|
|
|
"GyPbW1yZa5vE302a1Cr0Cd7RC4AFAAw=\n" |
|
|
|
|
"-----END PRIVATE KEY-----"; |
|
|
|
|
|
|
|
|
|
struct test_files_set get_test_files_set(void) |
|
|
|
|
{ |
|
|
|
|
static struct test_file files[] = { |
|
|
|
@ -290,7 +193,7 @@ char *bin2hex(char *dst, const void *src, size_t count) |
|
|
|
|
return dst; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static char *get_index_filename(char *mnt_dir, incfs_uuid_t id) |
|
|
|
|
static char *get_index_filename(const char *mnt_dir, incfs_uuid_t id) |
|
|
|
|
{ |
|
|
|
|
char path[FILENAME_MAX]; |
|
|
|
|
char str_id[1 + 2 * sizeof(id)]; |
|
|
|
@ -722,8 +625,6 @@ static int build_mtree(struct test_file *file) |
|
|
|
|
int tree_lvl_index[INCFS_MAX_MTREE_LEVELS] = {}; |
|
|
|
|
int tree_lvl_count[INCFS_MAX_MTREE_LEVELS] = {}; |
|
|
|
|
int levels_count = 0; |
|
|
|
|
char data_to_sign[256] = {}; |
|
|
|
|
int sig_data_size; |
|
|
|
|
int i, level; |
|
|
|
|
|
|
|
|
|
if (file->size == 0) |
|
|
|
@ -797,19 +698,6 @@ static int build_mtree(struct test_file *file) |
|
|
|
|
sha256(file->mtree[0].data, |
|
|
|
|
INCFS_DATA_FILE_BLOCK_SIZE, file->root_hash); |
|
|
|
|
|
|
|
|
|
/* Calculating digital signature */ |
|
|
|
|
snprintf(file->sig.add_data, sizeof(file->sig.add_data), "%ld", |
|
|
|
|
file->size); |
|
|
|
|
memcpy(data_to_sign, file->root_hash, SHA256_DIGEST_SIZE); |
|
|
|
|
memcpy(data_to_sign + SHA256_DIGEST_SIZE, file->sig.add_data, |
|
|
|
|
strlen(file->sig.add_data)); |
|
|
|
|
sig_data_size = SHA256_DIGEST_SIZE + strlen(file->sig.add_data); |
|
|
|
|
if (!sign_pkcs7(data_to_sign, sig_data_size, private_key, x509_cert, |
|
|
|
|
&file->sig.data, &file->sig.size)) { |
|
|
|
|
ksft_print_msg("Signing failed.\n"); |
|
|
|
|
return -EINVAL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1873,162 +1761,6 @@ failure: |
|
|
|
|
return TEST_FAILURE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int signature_test(char *mount_dir) |
|
|
|
|
{ |
|
|
|
|
struct test_files_set test = get_test_files_set(); |
|
|
|
|
const int file_num = test.files_count; |
|
|
|
|
int i = 0; |
|
|
|
|
unsigned char sig_buf[INCFS_MAX_SIGNATURE_SIZE]; |
|
|
|
|
char *backing_dir; |
|
|
|
|
int cmd_fd = -1; |
|
|
|
|
|
|
|
|
|
backing_dir = create_backing_dir(mount_dir); |
|
|
|
|
if (!backing_dir) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
/* Mount FS and release the backing file. (10s wait time) */ |
|
|
|
|
if (mount_fs(mount_dir, backing_dir, 10000) != 0) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
cmd_fd = open_commands_file(mount_dir); |
|
|
|
|
if (cmd_fd < 0) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
/* Write hashes and data. */ |
|
|
|
|
for (i = 0; i < file_num; i++) { |
|
|
|
|
struct test_file *file = &test.files[i]; |
|
|
|
|
int res; |
|
|
|
|
|
|
|
|
|
build_mtree(file); |
|
|
|
|
|
|
|
|
|
res = crypto_emit_file(cmd_fd, NULL, file->name, &file->id, |
|
|
|
|
file->size, file->root_hash, |
|
|
|
|
file->sig.data, file->sig.size, file->sig.add_data); |
|
|
|
|
|
|
|
|
|
if (res) { |
|
|
|
|
ksft_print_msg("Emit failed for %s. error: %s\n", |
|
|
|
|
file->name, strerror(-res)); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (emit_test_file_data(mount_dir, file)) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
res = load_hash_tree(mount_dir, file); |
|
|
|
|
if (res) { |
|
|
|
|
ksft_print_msg("Can't load hashes for %s. error: %s\n", |
|
|
|
|
file->name, strerror(-res)); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Validate data */ |
|
|
|
|
for (i = 0; i < file_num; i++) { |
|
|
|
|
struct test_file *file = &test.files[i]; |
|
|
|
|
int sig_len; |
|
|
|
|
char *path; |
|
|
|
|
int fd; |
|
|
|
|
|
|
|
|
|
if (validate_test_file_content(mount_dir, file) < 0) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
path = concat_file_name(mount_dir, file->name); |
|
|
|
|
fd = open(path, O_RDWR); |
|
|
|
|
free(path); |
|
|
|
|
if (fd < 0) { |
|
|
|
|
print_error("Can't open file"); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sig_len = get_file_signature(fd, sig_buf, ARRAY_SIZE(sig_buf)); |
|
|
|
|
|
|
|
|
|
if (close(fd)) { |
|
|
|
|
print_error("Can't close file"); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (sig_len < 0) { |
|
|
|
|
ksft_print_msg("Can't load signature %s. error: %s\n", |
|
|
|
|
file->name, strerror(-sig_len)); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (sig_len != file->sig.size || |
|
|
|
|
memcmp(sig_buf, file->sig.data, sig_len)) { |
|
|
|
|
ksft_print_msg("Signature mismatch %s.\n", |
|
|
|
|
file->name); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Unmount and mount again, to make sure the signature is persistent. */ |
|
|
|
|
close(cmd_fd); |
|
|
|
|
cmd_fd = -1; |
|
|
|
|
if (umount(mount_dir) != 0) { |
|
|
|
|
print_error("Can't unmout FS"); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
if (mount_fs(mount_dir, backing_dir, 50) != 0) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
cmd_fd = open_commands_file(mount_dir); |
|
|
|
|
if (cmd_fd < 0) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
/* Validate data again */ |
|
|
|
|
for (i = 0; i < file_num; i++) { |
|
|
|
|
struct test_file *file = &test.files[i]; |
|
|
|
|
int sig_len; |
|
|
|
|
char *path; |
|
|
|
|
int fd; |
|
|
|
|
|
|
|
|
|
if (validate_test_file_content(mount_dir, file) < 0) |
|
|
|
|
goto failure; |
|
|
|
|
|
|
|
|
|
path = concat_file_name(mount_dir, file->name); |
|
|
|
|
fd = open(path, O_RDWR); |
|
|
|
|
free(path); |
|
|
|
|
if (fd < 0) { |
|
|
|
|
print_error("Can't open file"); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sig_len = get_file_signature(fd, sig_buf, ARRAY_SIZE(sig_buf)); |
|
|
|
|
|
|
|
|
|
if (close(fd)) { |
|
|
|
|
print_error("Can't close file"); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (sig_len < 0) { |
|
|
|
|
ksft_print_msg("Can't load signature %s. error: %s\n", |
|
|
|
|
file->name, strerror(-sig_len)); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
if (sig_len != file->sig.size || |
|
|
|
|
memcmp(sig_buf, file->sig.data, sig_len)) { |
|
|
|
|
ksft_print_msg("Signature mismatch %s.\n", |
|
|
|
|
file->name); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Final unmount */ |
|
|
|
|
close(cmd_fd); |
|
|
|
|
cmd_fd = -1; |
|
|
|
|
if (umount(mount_dir) != 0) { |
|
|
|
|
print_error("Can't unmout FS"); |
|
|
|
|
goto failure; |
|
|
|
|
} |
|
|
|
|
return TEST_SUCCESS; |
|
|
|
|
|
|
|
|
|
failure: |
|
|
|
|
close(cmd_fd); |
|
|
|
|
free(backing_dir); |
|
|
|
|
umount(mount_dir); |
|
|
|
|
return TEST_FAILURE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int hash_tree_test(char *mount_dir) |
|
|
|
|
{ |
|
|
|
|
char *backing_dir; |
|
|
|
@ -2057,8 +1789,8 @@ static int hash_tree_test(char *mount_dir) |
|
|
|
|
|
|
|
|
|
build_mtree(file); |
|
|
|
|
res = crypto_emit_file(cmd_fd, NULL, file->name, &file->id, |
|
|
|
|
file->size, file->root_hash, |
|
|
|
|
file->sig.data, file->sig.size, file->sig.add_data); |
|
|
|
|
file->size, file->root_hash, |
|
|
|
|
file->sig.add_data); |
|
|
|
|
|
|
|
|
|
if (i == corrupted_file_idx) { |
|
|
|
|
/* Corrupt third blocks hash */ |
|
|
|
@ -2383,7 +2115,6 @@ int main(int argc, char *argv[]) |
|
|
|
|
MAKE_TEST(work_after_remount_test), |
|
|
|
|
MAKE_TEST(child_procs_waiting_for_data_test), |
|
|
|
|
MAKE_TEST(multiple_providers_test), |
|
|
|
|
MAKE_TEST(signature_test), |
|
|
|
|
MAKE_TEST(hash_tree_test), |
|
|
|
|
MAKE_TEST(read_log_test), |
|
|
|
|
}; |
|
|
|
|