Skip to content

Commit

Permalink
Updated to use latest openssl, vs2019
Browse files Browse the repository at this point in the history
moving over to static openssl usage
  • Loading branch information
nooperation committed Nov 16, 2019
1 parent f04690e commit ea58892
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,5 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs

Directory.Build.props
10 changes: 5 additions & 5 deletions LibUserPreferences/LibUserPreferences.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
<ProjectGuid>{E8A8F157-EBAE-43E4-90AE-32A8DAC51096}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>LibUserPreferences</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
10 changes: 2 additions & 8 deletions UserPreferences.Shared.Tests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ TEST_CASE("Encryption")
{
const auto guid = std::string("01234567-89ab-cdef-0123-456789abcdef");
const auto salt = std::string("6E3F032949637D2E");
const auto plaintext = std::string("{\"username\":\"example@example.com\",\"refresh_token\":\"\",\"scope_string\":\"\"}");
const auto plaintext = std::string("Hello World");// std::string("{\"username\":\"example@example.com\",\"refresh_token\":\"\",\"scope_string\":\"\"}");
const auto ciphertext = std::vector<uint8_t>{
0x80, 0x19, 0xD3, 0xEC, 0x72, 0x59, 0xA7, 0x5C, 0xC6, 0xDF, 0xF9, 0xBE,
0x09, 0x51, 0xF8, 0x7C, 0x02, 0x7F, 0x4F, 0x63, 0x72, 0xCA, 0x02, 0xB0,
0x32, 0xD5, 0x86, 0x6B, 0x68, 0x04, 0xC9, 0xD6, 0x7D, 0xFB, 0xBA, 0x39,
0x11, 0x46, 0x1C, 0xF6, 0xE4, 0x94, 0xD3, 0xD8, 0xFD, 0xE2, 0x9B, 0x52,
0x71, 0x89, 0xBB, 0x6C, 0x45, 0xF9, 0x87, 0x37, 0xF7, 0x4D, 0xCC, 0x15,
0x17, 0xDC, 0x64, 0x6E, 0x72, 0x0F, 0x65, 0xB7, 0xC0, 0x65, 0x6F, 0xB9,
0xBC, 0xB3, 0x04, 0x0D, 0xE5, 0x88, 0xAF, 0x5B
0x6a, 0x0f, 0xb1, 0xca, 0x3b, 0x60, 0x63, 0x04, 0x2c, 0x16, 0x92, 0xa2, 0x6e, 0x40, 0x71, 0x02
};

SECTION("Encrypt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
<ProjectGuid>{74BE1B66-A57A-44D1-9D92-05C1596BE7DA}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>UserPreferencesSharedTests</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
36 changes: 21 additions & 15 deletions UserPreferences.Shared/Encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <vector>
#include <string>

#pragma comment(lib, "libeay32")
#pragma comment(lib, "libssl_static")
#pragma comment(lib, "libcrypto_static")
#pragma comment(lib, "ws2_32")

namespace
{
Expand Down Expand Up @@ -69,11 +71,12 @@ namespace
auto cipher = EVP_aes_256_cbc();
auto ctx = EVP_CIPHER_CTX_new();

auto num_blocks = plaintext.size() / cipher->block_size;
if (plaintext.size() % cipher->block_size != 0) {
auto cipher_block_size = EVP_CIPHER_block_size(cipher);
auto num_blocks = plaintext.size() / cipher_block_size;
if (plaintext.size() % cipher_block_size != 0) {
++num_blocks;
}
auto out_plaintext = std::vector<uint8_t>(cipher->block_size * num_blocks);
auto out_plaintext = std::vector<uint8_t>(cipher_block_size * num_blocks);

EVP_CIPHER_CTX_init(ctx);

Expand Down Expand Up @@ -120,8 +123,11 @@ namespace
auto cipher = EVP_aes_256_cbc();
auto md = EVP_sha1();

out_key.resize(cipher->key_len);
out_initialization_vector.resize(cipher->iv_len);
auto cipher_key_length = EVP_CIPHER_key_length(cipher);
auto cipher_iv_length = EVP_CIPHER_iv_length(cipher);

out_key.resize(cipher_key_length);
out_initialization_vector.resize(cipher_iv_length);

auto derived_key_length = EVP_BytesToKey(
cipher,
Expand Down Expand Up @@ -171,9 +177,9 @@ namespace
/// <param name="is_encrypting">Determines if data should be encrypted or decrypted</param>
/// <returns>Encrypted or decrypted data</returns>
std::vector<uint8_t> EncryptOrDecryptData(
const std::vector<uint8_t>& data,
const std::string& machine_guid,
const std::string& salt_string,
const std::vector<uint8_t> &data,
const std::string &machine_guid,
const std::string &salt_string,
bool is_encrypting)
{
std::vector<uint8_t> salt_bytes;
Expand Down Expand Up @@ -202,17 +208,17 @@ namespace UserPreferences
namespace Encryption
{
std::vector<uint8_t> DecryptData(
const std::vector<uint8_t>& encrypted_data,
const std::string& machine_guid,
const std::string& salt_string)
const std::vector<uint8_t> &encrypted_data,
const std::string &machine_guid,
const std::string &salt_string)
{
return EncryptOrDecryptData(encrypted_data, machine_guid, salt_string, false);
}

std::vector<uint8_t> EncryptData(
const std::vector<uint8_t>& plaintext_data,
const std::string& machine_guid,
const std::string& salt_string)
const std::vector<uint8_t> &plaintext_data,
const std::string &machine_guid,
const std::string &salt_string)
{
return EncryptOrDecryptData(plaintext_data, machine_guid, salt_string, true);
}
Expand Down
10 changes: 5 additions & 5 deletions UserPreferences.Shared/UserPreferences.Shared.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@
<ProjectGuid>{21DB7E9B-DA4E-420E-A209-A4F6C339F10C}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>UserPreferencesShared</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>UserPreferences.Shared</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
10 changes: 5 additions & 5 deletions UserPreferencesExplorer/UserPreferencesExplorer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
<ProjectGuid>{69E20B05-83B9-444C-ADF6-6E28C9B056B0}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>UserPreferencesExplorer</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down

0 comments on commit ea58892

Please sign in to comment.