Skip to content

Commit

Permalink
Merge pull request #75 from twardokus/data-structures
Browse files Browse the repository at this point in the history
Data structures
  • Loading branch information
twardokus authored May 7, 2024
2 parents 80df89c + 79b4ad4 commit 71c6b24
Show file tree
Hide file tree
Showing 20 changed files with 979 additions and 107 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/cmake-build-debug/
/cmake-build-debug/
/docs/
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: cpp

matrix:
include:
- os: linux
- language: cpp
os: linux
dist: focal
compiler: gcc
script:
Expand All @@ -16,7 +15,8 @@ matrix:
- make
- ctest
- cd ../
- os: osx
- language: cpp
os: osx
compiler: clang
script:
- mkdir build
Expand Down
29 changes: 16 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ project(v2verifier)

set(CMAKE_CXX_STANDARD 17)

set(V2V_LIBRARIES v2xmessage)
set(V2V_LIBRARIES v2xmessage logger)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
##------------------------------------------------------------
## macOS stuff
set(CMAKE_OSX_ARCHITECTURES arm64)
set(OPENSSL_ROOT_DIR /opt/homebrew/Cellar/openssl@3/3.2.1)
# set(Boost_NO_SYSTEM_PATHS TRUE)
# set(BOOST_ROOT /opt/homebrew/Cellar/boost/1.84.0)
# set(Boost_LIBRARY_DIRS "${BOOST_ROOT}/lib/")
##------------------------------------------------------------
endif()

find_package(OpenSSL REQUIRED)

add_subdirectory(logger)
add_subdirectory(v2xmessage)
add_subdirectory(v2verifier-app)

Expand All @@ -17,18 +31,7 @@ add_subdirectory(v2verifier-app)
# src/threading.cpp)
#
#
#if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# ##------------------------------------------------------------
# ## macOS stuff
# set(CMAKE_OSX_ARCHITECTURES arm64)
# set(OPENSSL_ROOT_DIR /opt/homebrew/Cellar/openssl@3/3.2.1)
# set(Boost_NO_SYSTEM_PATHS TRUE)
# set(BOOST_ROOT /opt/homebrew/Cellar/boost/1.84.0)
# set(Boost_LIBRARY_DIRS "${BOOST_ROOT}/lib/")
# ##------------------------------------------------------------
#endif()
#
#find_package(OpenSSL REQUIRED)

#find_package(Boost REQUIRED)
#
#add_executable(${PROJECT_NAME} ${SOURCE_FILES})
Expand Down
10 changes: 10 additions & 0 deletions logger/CMakeLists.txt
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()
52 changes: 52 additions & 0 deletions logger/Log.cpp
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();
}

}
46 changes: 46 additions & 0 deletions logger/Log.h
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
59 changes: 13 additions & 46 deletions open-street-map-gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,26 @@
##
# @file gui.py
# @brief Python program to launch and run the OSM-based GUI for V2Verifier


# Imports
import eel
import json
import os
import pandas as pd
from pprint import pprint

# def render_all_vehicles(vehicles: pd.DataFrame) -> None:
# """ Clear existing vehicle markers and generate new markers by invoking JS functions via EEL
#
# :param vehicles: DataFrame storing the vehicles represented in the GUI
# :return: None
# """
# eel.reset_markers()
# for i in range(len(vehicles)):
# eel.add_new_vehicle(vehicles.loc[i, 'longitude'],
# vehicles.loc[i, 'latitude'],
# vehicles.loc[i, 'heading'].astype(float))
# eel.update_markers()
#
#
# def update_vehicles_from_json(vehicle_json_data: dict, vehicles: pd.DataFrame) -> pd.DataFrame:
# """ Update vehicles tracked in the GUI from JSON input data. JSON is expected to be a
# dictionary parsed out of JSON with a single key (`vehicles`) that maps to a list of
# dictionaries of vehicle data, where each dictionary contains an id_number,
# longitude, latitude, and heading value for one vehicle.
#
# :param vehicle_json_data: dictionary extracted from JSON containing an array of vehicle data
# :param vehicles: DataFrame used to track vehicles represented on the GUI
# :return: an updated copy of vehicles with the new information included
# """
#
# v_df = pd.DataFrame(vehicle_json_data['vehicles'])
#
# # For each vehicle that we got new information about in the JSON
# for i in range(len(v_df)):
#
# # If this is a new vehicle, make note of it
# if not v_df.loc[i, 'id_number'] in list(vehicles['id_number']):
# vehicles.loc[len(vehicles.index)] = [v_df.loc[i, 'id_number'],
# v_df.loc[i, 'latitude'],
# v_df.loc[i, 'longitude'],
# v_df.loc[i, 'heading']]
#
# # Otherwise, update the relevant row in the vehicles DataFrame
# else:
# v_idx = vehicles[vehicles['id_number'] == v_df.loc[i, 'id_number']].index
#
# vehicles.loc[v_idx] = v_df.loc[i,:].tolist()
#
# return vehicles

class GUI:
"""! The GUI class to manage the interface"""

def __init__(self):
"""! Initializer for the GUI"""
self.vehicles = pd.DataFrame(columns=['id_number', 'latitude', 'longitude', 'heading'])

def update_vehicle(self, vehicle_info: dict):
"""! Updates information about vehicles in the system
@param vehicle_info
"""
if self.vehicle_is_known(vehicle_info['id_number']):
self.vehicles.loc[self.vehicles['id_number']==vehicle_info['id_number']] = [pd.Series(vehicle_info)]
else:
Expand Down
9 changes: 9 additions & 0 deletions open-street-map-gui/gui_test.py
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()
13 changes: 4 additions & 9 deletions open-street-map-gui/webapp/scripts/add_new_vehicle.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/**
* Add a new vehicle to the GUI.
*
* @param {float} lng longitude of the vehicle
* @param {float} lat latitude of the vehicle
* @param {float} heading heading of the vehicle
*
* @return {void}
*/
/// @file add_new_vehicle.js



function add_new_vehicle(lng, lat, heading) {

const el = document.createElement('div');
Expand Down
9 changes: 5 additions & 4 deletions v2verifier-app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#set(SOURCE_FILES
#)
#
set(MAIN_SOURCE_FILE
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
src/Vehicle.cpp
include/Vehicle.hpp)
include/Vehicle.hpp
src/V2VSecurity.cpp
include/V2VSecurity.hpp)

set(APP_NAME v2verifier)

add_executable(${APP_NAME} ${SOURCE_FILES} ${MAIN_SOURCE_FILE})

target_link_libraries(${PROJECT_NAME} OpenSSL::Crypto)
target_link_libraries(${APP_NAME} ${V2V_LIBRARIES})

enable_testing()
Expand Down
75 changes: 75 additions & 0 deletions v2verifier-app/include/V2VSecurity.hpp
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
Loading

0 comments on commit 71c6b24

Please sign in to comment.