forked from aws/aws-lc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR ISC | ||
|
||
#include <openssl/base.h> | ||
#include <cstdint> | ||
|
||
#if defined(OPENSSL_LINUX) | ||
|
||
#include "snapsafe_detect.h" | ||
#include <fcntl.h> | ||
#include <string.h> | ||
#include <sys/mman.h> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#define NUMBER_OF_TEST_VALUES 5 | ||
|
||
TEST(SnapsafeGenerationTest, SysGenIDretrieval) { | ||
#if defined(AWSLC_SYSGENID_PATH) | ||
const char* sgc_file_path = AWSLC_SYSGENID_PATH; | ||
int fd_sgc = open(sgc_file_path, O_CREAT | O_RDWR | O_APPEND); | ||
if (fd_sgc == -1) { | ||
FAIL(); | ||
return; | ||
} | ||
long page_size = sysconf(_SC_PAGESIZE); | ||
if (page_size <= 0) { | ||
FAIL(); | ||
return; | ||
} | ||
size_t pgsize = (size_t)page_size; | ||
void *addr = | ||
mmap(NULL, pgsize, PROT_WRITE, MAP_SHARED, fd_sgc, 0); | ||
|
||
close(fd_sgc); | ||
|
||
if (addr == MAP_FAILED) { | ||
FAIL(); | ||
return; | ||
} | ||
|
||
// TODO: Testing | ||
unsigned int set_sgn = 0; | ||
memcpy(addr, &set_sgn, sizeof(unsigned int)); | ||
msync(addr, pgsize, MS_SYNC); | ||
|
||
unsigned int reported_sgn; | ||
ASSERT_EQ(1, CRYPTO_get_snapsafe_generation(&reported_sgn)); | ||
ASSERT_EQ((unsigned int)0, reported_sgn); | ||
|
||
#else | ||
PASS(); | ||
#endif // defined(AWSLC_SYSGENID_PATH) | ||
} | ||
|
||
#endif // defined(OPENSSL_LINUX) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters