OUT-942 Media key partial implementation
parent
e7a18ffd82
commit
19f79dced1
|
@ -2250,3 +2250,15 @@ STDMETHODIMP CpEpEngine::EnableEchoProtocolInOutgoingMessageRatingPreview(VARIAN
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CpEpEngine::ConfigMediaKey(BSTR pattern, BSTR fpr) noexcept
|
||||
{
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
string _pattern = utf8_string(pattern);
|
||||
string _fpr = utf8_string(fpr);
|
||||
stringpair_list_t* media_key_map = new_stringpair_list(new_stringpair(_pattern.c_str(), _fpr.c_str()));
|
||||
status = config_media_keys(session(), media_key_map);
|
||||
free_stringpair_list(media_key_map);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -301,6 +301,7 @@ public:
|
|||
// Echo protocol & Media key
|
||||
STDMETHOD(EnableEchoProtocol)(VARIANT_BOOL enable);
|
||||
STDMETHOD(EnableEchoProtocolInOutgoingMessageRatingPreview)(VARIANT_BOOL enable);
|
||||
STDMETHOD(ConfigMediaKey)(BSTR pattern, BSTR fpr);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ void LocalProvisioning::Run()
|
|||
std::wstring isProvisioned = provisionRegKey.GetValue(ProvisioningIsProvisionedRegKey,
|
||||
L"False");
|
||||
std::wstring localFolder = provisionRegKey.GetValue(ProvisioningLocalFolderRegKey,
|
||||
defaultProvisioningPath());
|
||||
LocalProvisioning::defaultProvisioningPath());
|
||||
std::wstring provisioning_file_name = provisionRegKey.GetValue(ProvisioningFileNameRegKey,
|
||||
DefaultProvisionPackage);
|
||||
|
||||
|
@ -30,7 +30,7 @@ void LocalProvisioning::Run()
|
|||
std::filesystem::path target_path = provisioning_path / L"package";
|
||||
|
||||
if (!std::filesystem::exists(provisioning_path))
|
||||
create_dir_if_not_exists(provisioning_path);
|
||||
LocalProvisioning::create_dir_if_not_exists(provisioning_path);
|
||||
|
||||
if (!std::filesystem::exists(pkg_path)) // there is no package to provision
|
||||
return;
|
||||
|
|
|
@ -27,17 +27,26 @@ namespace pEp
|
|||
/// <param name="in"></param>
|
||||
/// <returns></returns>
|
||||
bool convert_bool(const std::wstring& in);
|
||||
/// <summary>
|
||||
/// Get default provisioning directory
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
std::wstring defaultProvisioningPath();
|
||||
bool create_dir_if_not_exists(const std::filesystem::path& path);
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Run provisioning procedure
|
||||
/// </summary>
|
||||
void Run();
|
||||
|
||||
/// <summary>
|
||||
/// Get default provisioning directory
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
static std::wstring defaultProvisioningPath();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a directory
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
static bool create_dir_if_not_exists(const std::filesystem::path& path);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
#include "stdafx.h"
|
||||
#include "MediaKeyManager.h"
|
||||
#include <fstream>
|
||||
#include <pEp/media_key.h>
|
||||
|
||||
namespace pEp
|
||||
{
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::string MediaKeyManager::trim_chars(const std::string& in, const std::string& chars)
|
||||
{
|
||||
std::string part;
|
||||
size_t start = in.find_first_not_of(chars);
|
||||
part = (start == std::string::npos) ? "" : in.substr(start);
|
||||
size_t end = part.find_last_not_of(chars);
|
||||
return (end == std::string::npos) ? "" : part.substr(0, end + 1);
|
||||
}
|
||||
|
||||
|
||||
std::string MediaKeyManager::load_text_file_contents(const std::filesystem::path& p)
|
||||
{
|
||||
std::ifstream t(p);
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
void MediaKeyManager::save_fpr_stamp(const std::filesystem::path& p, const std::string& fpr)
|
||||
{
|
||||
std::ofstream outfile;
|
||||
outfile.open(p / stamp_filename, std::ios_base::trunc);
|
||||
outfile << fpr;
|
||||
}
|
||||
|
||||
void MediaKeyManager::add_registry_pattern(const std::string& pattern, const std::string& fpr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
PEP_STATUS MediaKeyManager::config_media_key(const std::string& pattern, const std::string& fpr)
|
||||
{
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
stringpair_list_t* media_key_map = new_stringpair_list(new_stringpair(pattern.c_str(), fpr.c_str()));
|
||||
status = config_media_keys(session, media_key_map);
|
||||
free_stringpair_list(media_key_map);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string MediaKeyManager::import_media_key(const std::filesystem::path& p)
|
||||
{
|
||||
std::string k = load_text_file_contents(p);
|
||||
identity_list *l;
|
||||
import_key(session, k.c_str(), k.size(), &l);
|
||||
return l->ident->fpr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MediaKeyManager::load_keys_in_dir(const std::filesystem::path& p)
|
||||
{
|
||||
fs::path privkey_path = p / privkey_filename;
|
||||
fs::path pubkey_path = p / pubkey_filename;
|
||||
fs::path pattern_path = p / pattern_filename;
|
||||
|
||||
if (fs::exists(privkey_path) && fs::exists(pubkey_path) && fs::exists(pattern_path))
|
||||
{
|
||||
std::string fpr_pri = import_media_key(privkey_path);
|
||||
std::string fpr_pub = import_media_key(pubkey_path);
|
||||
if (fpr_pri.compare(fpr_pub) != 0)
|
||||
{
|
||||
// TODO log
|
||||
std::cout << "FPRs do not match\n";
|
||||
delete_keypair(session, fpr_pri.c_str());
|
||||
delete_keypair(session, fpr_pub.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string pattern = trim_chars(load_text_file_contents(pattern_path));
|
||||
PEP_STATUS status = config_media_key(pattern, fpr_pri);
|
||||
if (status != PEP_STATUS_OK)
|
||||
{
|
||||
// TODO log
|
||||
std::cout << "Error in config_media_key: " << status << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
save_fpr_stamp(p, fpr_pri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MediaKeyManager::ImportKeys()
|
||||
{
|
||||
fs::path provisioning_path(LocalProvisioning::defaultProvisioningPath());
|
||||
fs::path media_key_path = provisioning_path / MediaKeyDir;
|
||||
|
||||
LocalProvisioning::create_dir_if_not_exists(media_key_path);
|
||||
|
||||
for (const fs::directory_entry& dir_entry : fs::directory_iterator(media_key_path))
|
||||
{
|
||||
std::cerr << dir_entry << '\n';
|
||||
if (dir_entry.is_directory())
|
||||
{
|
||||
load_keys_in_dir(dir_entry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MediaKeyManager::ConfigureMediaKeyMap()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace pEp
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
#include "LocalProvisioning.h"
|
||||
#include <pEp/pEpEngine.h>
|
||||
|
||||
namespace pEp
|
||||
{
|
||||
#define MediaKeyRegKey _T("Software\\pEp\\Provisioning\\Mediakeys")
|
||||
#define MediaKeyDir _T("Mediakeys")
|
||||
|
||||
class MediaKeyManager
|
||||
{
|
||||
|
||||
inline static const std::wstring pubkey_filename = L"public_key.asc";
|
||||
inline static const std::wstring privkey_filename = L"private_key.asc";
|
||||
inline static const std::wstring pattern_filename = L"pattern.txt";
|
||||
inline static const std::wstring stamp_filename = L"stamp.txt";
|
||||
|
||||
PEP_SESSION session;
|
||||
|
||||
void load_keys_in_dir(const std::filesystem::path& p);
|
||||
std::string import_media_key(const std::filesystem::path& p);
|
||||
|
||||
std::string trim_chars(const std::string& in, const std::string& chars = " \n\r\t\f\v");
|
||||
std::string load_text_file_contents(const std::filesystem::path& p);
|
||||
void add_registry_pattern(const std::string& pattern, const std::string& fpr);
|
||||
PEP_STATUS config_media_key(const std::string& pattern, const std::string& fpr);
|
||||
void save_fpr_stamp(const std::filesystem::path& p, const std::string& fpr);
|
||||
|
||||
public:
|
||||
|
||||
MediaKeyManager(PEP_SESSION session) noexcept : session(session)
|
||||
{
|
||||
}
|
||||
|
||||
void ImportKeys();
|
||||
|
||||
void ConfigureMediaKeyMap();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
#include "LocalJSONAdapter.h"
|
||||
#include "CMainWindow.h"
|
||||
#include "LocalProvisioning.h"
|
||||
|
||||
#include "MediaKeyManager.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
@ -107,6 +107,10 @@ extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/
|
|||
assert(mw);
|
||||
}
|
||||
|
||||
pEp::MediaKeyManager media_key_manager(first_session);
|
||||
media_key_manager.ImportKeys();
|
||||
media_key_manager.ConfigureMediaKeyMap();
|
||||
|
||||
auto rv = _AtlModule.WinMain(nShowCmd);
|
||||
|
||||
if (ljs) {
|
||||
|
|
|
@ -566,7 +566,7 @@ interface IpEpEngine : IUnknown {
|
|||
// Enable Echo protocol
|
||||
[id(72)] HRESULT EnableEchoProtocol([in] VARIANT_BOOL enable);
|
||||
[id(73)] HRESULT EnableEchoProtocolInOutgoingMessageRatingPreview([in] VARIANT_BOOL enable);
|
||||
|
||||
[id(74)] HRESULT ConfigMediaKey([in] BSTR pattern, [in] BSTR fpr);
|
||||
};
|
||||
|
||||
[
|
||||
|
|
|
@ -144,6 +144,7 @@
|
|||
<ClCompile Include="CpEpEngine.cpp" />
|
||||
<ClCompile Include="GateKeeper.cpp" />
|
||||
<ClCompile Include="LocalJSONAdapter.cpp" />
|
||||
<ClCompile Include="MediaKeyManager.cpp" />
|
||||
<ClCompile Include="pEpCOMServerAdapter.cpp" />
|
||||
<ClCompile Include="pEpCOMServerAdapter_i.c">
|
||||
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
|
||||
|
@ -177,6 +178,7 @@
|
|||
<ClInclude Include="GateKeeper.h" />
|
||||
<ClInclude Include="LocalJSONAdapter.h" />
|
||||
<ClInclude Include="LocalProvisioning.h" />
|
||||
<ClInclude Include="MediaKeyManager.h" />
|
||||
<ClInclude Include="pEpCOMServerAdapter.h" />
|
||||
<ClInclude Include="pEpCOMServerAdapter_i.h" />
|
||||
<ClInclude Include="pEp_utility.h" />
|
||||
|
|
|
@ -55,6 +55,9 @@
|
|||
<ClCompile Include="LocalProvisioning.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MediaKeyManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
|
@ -102,6 +105,9 @@
|
|||
<ClInclude Include="LocalProvisioning.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MediaKeyManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="pEpCOMServerAdapter.rc">
|
||||
|
|
Loading…
Reference in New Issue