-
Notifications
You must be signed in to change notification settings - Fork 10
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 #29 from mysteriumnetwork/windows [major]
Windows wireguard service support
- Loading branch information
Showing
22 changed files
with
703 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BasedOnStyle: Google | ||
ColumnLimit: 120 |
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
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
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,39 @@ | ||
#include <windows.h> | ||
|
||
#include <codecvt> | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
namespace wireguard_dart { | ||
|
||
std::wstring WriteConfigToTempFile(std::string config) { | ||
WCHAR temp_path[MAX_PATH]; | ||
DWORD temp_path_len = GetTempPath(MAX_PATH, temp_path); | ||
if (temp_path_len > MAX_PATH || temp_path_len == 0) { | ||
throw std::runtime_error("could not get temporary dir: " + GetLastError()); | ||
} | ||
|
||
WCHAR temp_filename[MAX_PATH]; | ||
UINT temp_filename_result = GetTempFileName(temp_path, L"wg_conf", 0, temp_filename); | ||
wcscat_s(temp_filename, L".conf"); | ||
if (temp_filename_result == 0) { | ||
throw std::runtime_error("could not get temporary file name: " + GetLastError()); | ||
} | ||
|
||
HANDLE temp_file = CreateFile(temp_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | ||
if (temp_file == INVALID_HANDLE_VALUE) { | ||
throw std::runtime_error("unable to create temporary file: " + GetLastError()); | ||
} | ||
|
||
DWORD bytes_written; | ||
if (!WriteFile(temp_file, config.c_str(), static_cast<DWORD>(config.length()), &bytes_written, NULL)) { | ||
throw std::runtime_error("could not write temporary config file:" + GetLastError()); | ||
} | ||
|
||
if (!CloseHandle(temp_file)) { | ||
throw std::runtime_error("unable to close temporary file:" + GetLastError()); | ||
} | ||
return temp_filename; | ||
} | ||
|
||
} |
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,7 @@ | ||
#include <string> | ||
|
||
namespace wireguard_dart { | ||
|
||
std::wstring WriteConfigToTempFile(std::string config); | ||
|
||
} |
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,29 @@ | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "libbase64.h" | ||
#include "tunnel.h" | ||
|
||
namespace wireguard_dart { | ||
|
||
const size_t kKeyLen = 32; | ||
const size_t kBase64BufferSize = kKeyLen * 2; // Min size = src * 4/3 https://github.com/aklomp/base64#base64_encode | ||
|
||
std::pair<std::string, std::string> GenerateKeyPair() { | ||
char public_key_bytes[kKeyLen]; | ||
char private_key_bytes[kKeyLen]; | ||
WireGuardGenerateKeypair((unsigned char *)public_key_bytes, (unsigned char *)private_key_bytes); | ||
|
||
char b64_buf[kBase64BufferSize]; | ||
size_t b64_output_len; | ||
|
||
base64_encode(public_key_bytes, kKeyLen, b64_buf, &b64_output_len, 0); | ||
const std::string public_key_b64(b64_buf, 0, b64_output_len); | ||
|
||
base64_encode(private_key_bytes, kKeyLen, b64_buf, &b64_output_len, 0); | ||
const std::string private_key_b64(b64_buf, 0, b64_output_len); | ||
|
||
return std::make_pair(public_key_b64, private_key_b64); | ||
} | ||
|
||
} // namespace wireguard_dart |
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,13 @@ | ||
#ifndef WIREGUARD_DART_KEY_GENERATOR_H | ||
#define WIREGUARD_DART_KEY_GENERATOR_H | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
namespace wireguard_dart { | ||
|
||
std::pair<std::string, std::string> GenerateKeyPair(); | ||
|
||
} | ||
|
||
#endif |
Binary file not shown.
Oops, something went wrong.