Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds bind phrase feature #12

Merged
merged 30 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2b7bf64
rename encryption and move option out of constructor (just use the se…
Consti10 Aug 10, 2023
877fba3
rename encryption and move option out of constructor (just use the se…
Consti10 Aug 10, 2023
58e19c6
encryption in WBTx - default to true
Consti10 Aug 10, 2023
7cb621f
add option to debug packets variance
Consti10 Aug 10, 2023
4959ee2
keys
Consti10 Aug 10, 2023
c83385e
upload keys
Consti10 Aug 10, 2023
d11bf50
fix unit tests
Consti10 Aug 10, 2023
ee15273
fix unit tests
Consti10 Aug 10, 2023
74109e7
encrypton - add bind phrase feature
Consti10 Aug 10, 2023
79222d3
encrypton - add bind phrase feature
Consti10 Aug 10, 2023
05dad44
encrypton - add bind phrase feature
Consti10 Aug 10, 2023
bb2ca9b
encrypton - add bind phrase feature
Consti10 Aug 10, 2023
7039149
encrypton - add bind phrase feature
Consti10 Aug 10, 2023
76bce99
encrypton - add bind phrase feature
Consti10 Aug 10, 2023
d175931
encrypton - add bind phrase feature
Consti10 Aug 10, 2023
b23cf77
encrypton - add bind phrase feature
Consti10 Aug 11, 2023
96a2ed1
encrypton - add bind phrase feature
Consti10 Aug 11, 2023
2fb7040
encrypton - add bind phrase feature
Consti10 Aug 11, 2023
85051fe
encrypton - add bind phrase feature
Consti10 Aug 11, 2023
5d4aaef
this option is obsolete
Consti10 Aug 11, 2023
2616f7c
encryption add bind phrase feature
Consti10 Aug 11, 2023
f738e66
encryption add bind phrase feature
Consti10 Aug 11, 2023
dea18a3
encryption add bind phrase feature
Consti10 Aug 11, 2023
ae52c8b
encryption add bind phrase feature
Consti10 Aug 11, 2023
031c419
encryption add bind phrase feature
Consti10 Aug 11, 2023
f923ed6
encryption add bind phrase feature
Consti10 Aug 11, 2023
1a97c5b
encryption add bind phrase feature
Consti10 Aug 11, 2023
173065d
encryption add bind phrase feature
Consti10 Aug 11, 2023
5df29b8
encryption add bind phrase feature
Consti10 Aug 11, 2023
82d5a75
add likely wrong bind phrase feature
Consti10 Aug 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build_and_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ jobs:
./build/wfb_keygen
- name: Unit test
run: |
./build/unit_test
cd build
./unit_test

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ wfb_tx
unit_test
benchmark
gs.key
drone.key
key_1.key
wfb_keygen
udp_generator_validator
socket_helper_test
Expand Down
1 change: 1 addition & 0 deletions example_key/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Example tx / rx key, generated from the default openhd bind phrase "openhd"
3 changes: 3 additions & 0 deletions example_key/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#bin/bash

./../cmake-build-debug/wfb_keygen -b openhd
2 changes: 2 additions & 0 deletions example_key/txrx.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
~%�Er>�������>����|��x�;r�F��KW��mn��hX��Y��--r{���C��m5�ʲ
�&��\� �T,�I�d����i1��}�/���E4V����)��p�0�5���L�P���
3 changes: 0 additions & 3 deletions example_keys/generate.sh

This file was deleted.

6 changes: 4 additions & 2 deletions executables/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ void benchmark_fec_encode(const Options &options, bool printBlockTime = false) {
void benchmark_crypt(const Options &options,const bool packet_validation_only) {
assert(options.benchmarkType == BENCHMARK_ENCRYPT || options.benchmarkType == BENCHMARK_DECRYPT);
const bool encrypt=options.benchmarkType==BENCHMARK_ENCRYPT;
Encryptor encryptor{std::nullopt,packet_validation_only};
Decryptor decryptor{std::nullopt,packet_validation_only};
wb::Encryptor encryptor{wb::generate_keypair_deterministic(true)};
encryptor.set_encryption_enabled(!packet_validation_only);
wb::Decryptor decryptor{wb::generate_keypair_deterministic(true)};
decryptor.set_encryption_enabled(!packet_validation_only);
std::array<uint8_t, crypto_box_NONCEBYTES> sessionKeyNonce{};
std::array<uint8_t, crypto_aead_chacha20poly1305_KEYBYTES + crypto_box_MACBYTES> sessionKeyData{};
encryptor.makeNewSessionKey(sessionKeyNonce, sessionKeyData);
Expand Down
3 changes: 1 addition & 2 deletions executables/example_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ int main(int argc, char *const *argv) {
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
options_txrx.set_direction= true;
options_txrx.pcap_rx_set_direction = true;
options_txrx.use_gnd_identifier=!is_air;
if(advanced_debugging){
options_txrx.log_all_received_validated_packets= true;
Expand Down
3 changes: 1 addition & 2 deletions executables/example_pollute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ int main(int argc, char *const *argv) {
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
options_txrx.set_direction= true;
options_txrx.pcap_rx_set_direction = true;
options_txrx.enable_non_openhd_mode= true;

std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx);
Expand Down
5 changes: 2 additions & 3 deletions executables/example_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ int main(int argc, char *const *argv) {
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
//options_txrx.set_direction= false;
options_txrx.set_direction= pcap_setdirection;
//options_txrx.pcap_rx_set_direction= false;
options_txrx.pcap_rx_set_direction = pcap_setdirection;
options_txrx.log_all_received_validated_packets= false;

std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx);
Expand Down
3 changes: 1 addition & 2 deletions executables/injection_rate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ int main(int argc, char *const *argv) {
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
//options_txrx.set_direction= false;
//options_txrx.pcap_rx_set_direction= false;
options_txrx.log_all_received_validated_packets= false;

std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx);
Expand Down
5 changes: 2 additions & 3 deletions executables/test_txrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ int main(int argc, char *const *argv) {
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
//options_txrx.set_direction= false;
options_txrx.set_direction= pcap_setdirection;
//options_txrx.pcap_rx_set_direction= false;
options_txrx.pcap_rx_set_direction = pcap_setdirection;
options_txrx.log_all_received_validated_packets= true;

std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx);
Expand Down
32 changes: 18 additions & 14 deletions executables/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,34 @@ static void test_fec_stream_random_bs_fs_overhead_dropped(){
}

// Test encryption+packet validation and packet validation only
static void test_encrypt_decrypt_validate(const bool useGeneratedFiles,bool message_signing_only) {
std::cout << "Using generated keypair (default seed otherwise):" << (useGeneratedFiles ? "y" : "n") << "\n";
const std::string filename_gs="gs.key"; //"../example_keys/gs.key"
const std::string filename_drone="drone.key" //"../example_keys/drone.key"
std::optional<std::string> encKey = useGeneratedFiles ? std::optional<std::string>(filename_gs) : std::nullopt;
std::optional<std::string> decKey = useGeneratedFiles ? std::optional<std::string>(filename_drone) : std::nullopt;
if(message_signing_only){
std::cout<<"Testing message signing\n";
static void test_encrypt_decrypt_validate(const bool use_key_from_file,bool message_signing_only) {
const std::string TEST_TYPE=message_signing_only ? "Sign" : "Encrypt&Sign";
const std::string TEST_KEY_TYPE=use_key_from_file ? "key from file" : "default key";
fmt::print("Testing {} with {}\n",TEST_TYPE,TEST_KEY_TYPE);
const std::string KEY_FILENAME="../example_key/txrx.key";
wb::KeyPairTxRx keyPairTxRx{};
if(use_key_from_file){
keyPairTxRx=wb::read_keypair_from_file(KEY_FILENAME);
}else{
std::cout<<"Testing encryption & signing\n";
const auto before=std::chrono::steady_clock::now();
keyPairTxRx=wb::generate_keypair_from_bind_phrase("openhd");
std::cout<<"Generating keypair from bind phrase took:"<<MyTimeHelper::R(std::chrono::steady_clock::now()-before)<<std::endl;
}

Encryptor encryptor{encKey,message_signing_only};
Decryptor decryptor{decKey,message_signing_only};
wb::Encryptor encryptor{keyPairTxRx.get_tx_key(true)};// We send from air unit
encryptor.set_encryption_enabled(!message_signing_only);
wb::Decryptor decryptor{keyPairTxRx.get_rx_key(false)}; // To the ground unit
decryptor.set_encryption_enabled(!message_signing_only);
struct SessionStuff{
std::array<uint8_t, crypto_box_NONCEBYTES> sessionKeyNonce{}; // random data
std::array<uint8_t, crypto_box_NONCEBYTES> sessionKeyNonce{}; // filled with random data
std::array<uint8_t, crypto_aead_chacha20poly1305_KEYBYTES + crypto_box_MACBYTES> sessionKeyData{};
};
SessionStuff sessionKeyPacket;
// make session key (tx)
encryptor.makeNewSessionKey(sessionKeyPacket.sessionKeyNonce, sessionKeyPacket.sessionKeyData);
// and "receive" session key (rx)
assert(decryptor.onNewPacketSessionKeyData(sessionKeyPacket.sessionKeyNonce, sessionKeyPacket.sessionKeyData)
== Decryptor::SESSION_VALID_NEW);
== wb::Decryptor::SESSION_VALID_NEW);
// now encrypt a couple of packets and decrypt them again afterwards
for (uint64_t nonce = 0; nonce < 200; nonce++) {
const auto data = GenericHelper::createRandomDataBuffer(FEC_PACKET_MAX_PAYLOAD_SIZE);
Expand Down Expand Up @@ -170,7 +174,7 @@ static void test_encrypt_decrypt_validate(const bool useGeneratedFiles,bool mess
nonce, enrypted_wrong_sign->data(), enrypted_wrong_sign->size());
assert(decrypted== nullptr);
}
std::cout << "encryption test passed\n";
fmt::print("Test {} with {} passed\n",TEST_TYPE,TEST_KEY_TYPE);
}


Expand Down
32 changes: 28 additions & 4 deletions executables/wfb_keygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,33 @@
#include "../src/Encryption.hpp"

/**
* Generates a new keypair and saves it to file for later use.
* Generates a new tx rx keypair and saves it to file for later use.
*/
int main(void) {
auto keypair=wbencryption::generate_keypair();
return wbencryption::write_to_file(keypair);
int main(int argc, char *const *argv) {
int opt;
std::optional<std::string> bind_phrase=std::nullopt;
while ((opt = getopt(argc, argv, "b:")) != -1) {
switch (opt) {
case 'b':{
bind_phrase=std::string(optarg);
}
break;
default: /* '?' */
show_usage:
fprintf(stderr,
"wfb-keygen [-b bind_phrase,deterministic], if no bind phrase is specified, random keys are generated (non-deterministic)\n",
argv[0]);
exit(1);
}
}
wb::KeyPairTxRx keyPairTxRx{};
if(bind_phrase.has_value()){
std::cout<<"Generating txrx keypair using bind phrase ["<<bind_phrase.value()<<"]"<<std::endl;
keyPairTxRx=wb::generate_keypair_from_bind_phrase(bind_phrase.value());
}else{
std::cout<<"Generating random txrx keypair"<<std::endl;
keyPairTxRx=wb::generate_keypair_random();
}
//auto keypair=wb::generate_keypair_from_bind_phrase("openhd");
return wb::write_keypair_to_file(keyPairTxRx,"txrx.key");
}
2 changes: 1 addition & 1 deletion latencyTesting/SimpleTestProgram/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env/
_trial_temp/
test
gs.key
drone.key
key_1.key
wfb_keygen
telemetry/conf/site.cfg
telemetry/conf/local.cfg
Expand Down
Loading