-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from twardokus/data-structures
Data structures
- Loading branch information
Showing
20 changed files
with
979 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/cmake-build-debug/ | ||
/cmake-build-debug/ | ||
/docs/ |
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,10 @@ | ||
set(SOURCE_FILES | ||
${CMAKE_CURRENT_SOURCE_DIR}/Log.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/Log.h | ||
) | ||
|
||
set(LIB_NAME logger) | ||
|
||
add_library(${LIB_NAME} ${SOURCE_FILES}) | ||
|
||
#enable_testing() |
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,52 @@ | ||
|
||
|
||
#include "Log.h" | ||
|
||
namespace Logger { | ||
|
||
static std::unique_ptr<Log> shared_log; | ||
|
||
std::mutex log_mtx; | ||
|
||
void startLog(const std::string_view filepath) { | ||
shared_log = std::make_unique<Log>(filepath); | ||
Logger::log(Level::Info, "Initialized log"); | ||
} | ||
|
||
void log(Level l, const std::string_view message) { | ||
shared_log->addLog(l, message); | ||
} | ||
|
||
void logFatal(std::string_view message) { | ||
shared_log->addLog(Logger::Fatal, message); | ||
} | ||
|
||
void logError(std::string_view message) { | ||
shared_log->addLog(Logger::Error, message); | ||
} | ||
|
||
void logWarning(std::string_view message) { | ||
shared_log->addLog(Logger::Warning, message); | ||
} | ||
|
||
void logInfo(std::string_view message) { | ||
shared_log->addLog(Logger::Info, message); | ||
} | ||
|
||
Log::Log(const std::string_view filepath) : logfile{} { | ||
logfile.open(filepath); | ||
} | ||
|
||
void Log::addLog(Logger::Level l, const std::string_view message) { | ||
// std::lock_guard<std::mutex> guard(log_mtx); | ||
if(logfile.is_open()) { | ||
logfile << levels[static_cast<int>(l)] << ": " << message << std::endl; | ||
} | ||
} | ||
|
||
Log::~Log() { | ||
addLog(Level::Info, "Stopped logging."); | ||
logfile.close(); | ||
} | ||
|
||
} |
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,46 @@ | ||
// | ||
// Created by Geoff Twardokus on 2/17/24. | ||
// | ||
|
||
#ifndef V2VERIFIER_LOG_H | ||
#define V2VERIFIER_LOG_H | ||
|
||
#include <fstream> | ||
#include <mutex> | ||
#include <string> | ||
|
||
namespace Logger { | ||
|
||
enum Level { | ||
Fatal, | ||
Error, | ||
Warning, | ||
Info | ||
}; | ||
|
||
void startLog(std::string_view filepath); | ||
void log(Level l, std::string_view message); | ||
void logFatal(std::string_view message); | ||
void logError(std::string_view message); | ||
void logWarning(std::string_view message); | ||
void logInfo(std::string_view message); | ||
|
||
class Log { | ||
public: | ||
Log(std::string_view filepath); | ||
|
||
void addLog(Level l, std::string_view message); | ||
|
||
~Log(); | ||
|
||
private: | ||
std::ofstream logfile; | ||
std::string levels[4] = {"Fatal", "Error", "Warning", "Info"}; | ||
}; | ||
|
||
|
||
|
||
}; | ||
|
||
|
||
#endif //V2VERIFIER_LOG_H |
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,9 @@ | ||
import pytest | ||
|
||
|
||
def testiffive(): | ||
return 5 == 5 | ||
|
||
|
||
def test_testiffive(): | ||
assert testiffive() |
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,75 @@ | ||
/** @file V2VSecurity.hpp | ||
* @brief Message signing and cryptomaterial management functions. | ||
* | ||
* @author Geoff Twardokus | ||
* | ||
* @bug No known bugs | ||
*/ | ||
|
||
#ifndef V2VERIFIER_V2VSECURITY_HPP | ||
#define V2VERIFIER_V2VSECURITY_HPP | ||
|
||
#define ECDSA_P256_DER_LENGTH_BYTES 72 | ||
|
||
#include <openssl/evp.h> | ||
#include <string> | ||
#include <fstream> | ||
|
||
class V2VSecurity { | ||
|
||
public: | ||
|
||
/** @brief Explicitly deleted default constructor. We never want a security manager module that does not have | ||
* a key loaded at initialization. */ | ||
V2VSecurity() = delete; | ||
|
||
/** @brief Create a new V2VSecurity module from a provided PEM key file. | ||
* | ||
* @param pemFilename Filepath to the public/private keypair to be used for signing and verifying messages. | ||
*/ | ||
explicit V2VSecurity(std::string &pemFilename); | ||
|
||
/** @brief Destructor */ | ||
~V2VSecurity(); | ||
|
||
/** @brief Sign arbitrary data with ECDSA P.256. Allocates new memory on the heap to store the `sig` value. | ||
* | ||
* @param msg Pointer to the raw message data to be signed. | ||
* @param sig Pointer to be used to store the signature. | ||
* @param sig_len Length of the generated signature | ||
* @return True if signature is successfully generated, false if errors are encountered. | ||
*/ | ||
bool signMessage(char* msg, unsigned char* &sig, size_t &sig_len); | ||
|
||
/** @brief Verify ECDSA P.256 signature. | ||
* | ||
* @param msg Pointer to the raw message data to be verified. | ||
* @param publicKey Pointer to the public key to be used for verification. | ||
* @param signature Pointer to the ECDSA signature to be verified. | ||
* @param sig_len Length of the signature to be verified. | ||
* @return True on successful verification, false on error or verification failure. | ||
*/ | ||
bool verifyMessage(char *msg, evp_pkey_st *publicKey, const unsigned char* signature, size_t sig_len); | ||
|
||
EVP_PKEY *pkey = nullptr; | ||
|
||
private: | ||
|
||
std::ifstream pemfile; | ||
|
||
EVP_MD_CTX *mdctx_sign = nullptr; | ||
EVP_MD_CTX *mdctx_verify = nullptr; | ||
|
||
/** @brief Load a public/private keypair from a provided filepath. | ||
* | ||
* @param filename Path to the file from which to load the keypair. | ||
*/ | ||
void loadPEMFile(std::string &filename); | ||
|
||
/** @brief Initialize various OPENSSL contexts and signature primitives for later use. */ | ||
void setup(); | ||
|
||
}; | ||
|
||
|
||
#endif //V2VERIFIER_V2VSECURITY_HPP |
Oops, something went wrong.