Skip to content

Commit ea58892

Browse files
committed
Updated to use latest openssl, vs2019
moving over to static openssl usage
1 parent f04690e commit ea58892

7 files changed

Lines changed: 45 additions & 43 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,5 @@ __pycache__/
286286
*.btm.cs
287287
*.odx.cs
288288
*.xsd.cs
289+
290+
Directory.Build.props

LibUserPreferences/LibUserPreferences.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323
<ProjectGuid>{E8A8F157-EBAE-43E4-90AE-32A8DAC51096}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>LibUserPreferences</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3030
<ConfigurationType>DynamicLibrary</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v141</PlatformToolset>
32+
<PlatformToolset>v142</PlatformToolset>
3333
<CharacterSet>Unicode</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>DynamicLibrary</ConfigurationType>
3737
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v141</PlatformToolset>
38+
<PlatformToolset>v142</PlatformToolset>
3939
<WholeProgramOptimization>true</WholeProgramOptimization>
4040
<CharacterSet>Unicode</CharacterSet>
4141
</PropertyGroup>
4242
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4343
<ConfigurationType>DynamicLibrary</ConfigurationType>
4444
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v141</PlatformToolset>
45+
<PlatformToolset>v142</PlatformToolset>
4646
<CharacterSet>Unicode</CharacterSet>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4949
<ConfigurationType>DynamicLibrary</ConfigurationType>
5050
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v141</PlatformToolset>
51+
<PlatformToolset>v142</PlatformToolset>
5252
<WholeProgramOptimization>true</WholeProgramOptimization>
5353
<CharacterSet>Unicode</CharacterSet>
5454
</PropertyGroup>

UserPreferences.Shared.Tests/Tests.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@ TEST_CASE("Encryption")
1313
{
1414
const auto guid = std::string("01234567-89ab-cdef-0123-456789abcdef");
1515
const auto salt = std::string("6E3F032949637D2E");
16-
const auto plaintext = std::string("{\"username\":\"example@example.com\",\"refresh_token\":\"\",\"scope_string\":\"\"}");
16+
const auto plaintext = std::string("Hello World");// std::string("{\"username\":\"example@example.com\",\"refresh_token\":\"\",\"scope_string\":\"\"}");
1717
const auto ciphertext = std::vector<uint8_t>{
18-
0x80, 0x19, 0xD3, 0xEC, 0x72, 0x59, 0xA7, 0x5C, 0xC6, 0xDF, 0xF9, 0xBE,
19-
0x09, 0x51, 0xF8, 0x7C, 0x02, 0x7F, 0x4F, 0x63, 0x72, 0xCA, 0x02, 0xB0,
20-
0x32, 0xD5, 0x86, 0x6B, 0x68, 0x04, 0xC9, 0xD6, 0x7D, 0xFB, 0xBA, 0x39,
21-
0x11, 0x46, 0x1C, 0xF6, 0xE4, 0x94, 0xD3, 0xD8, 0xFD, 0xE2, 0x9B, 0x52,
22-
0x71, 0x89, 0xBB, 0x6C, 0x45, 0xF9, 0x87, 0x37, 0xF7, 0x4D, 0xCC, 0x15,
23-
0x17, 0xDC, 0x64, 0x6E, 0x72, 0x0F, 0x65, 0xB7, 0xC0, 0x65, 0x6F, 0xB9,
24-
0xBC, 0xB3, 0x04, 0x0D, 0xE5, 0x88, 0xAF, 0x5B
18+
0x6a, 0x0f, 0xb1, 0xca, 0x3b, 0x60, 0x63, 0x04, 0x2c, 0x16, 0x92, 0xa2, 0x6e, 0x40, 0x71, 0x02
2519
};
2620

2721
SECTION("Encrypt")

UserPreferences.Shared.Tests/UserPreferences.Shared.Tests.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323
<ProjectGuid>{74BE1B66-A57A-44D1-9D92-05C1596BE7DA}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>UserPreferencesSharedTests</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3030
<ConfigurationType>Application</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v141</PlatformToolset>
32+
<PlatformToolset>v142</PlatformToolset>
3333
<CharacterSet>Unicode</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>Application</ConfigurationType>
3737
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v141</PlatformToolset>
38+
<PlatformToolset>v142</PlatformToolset>
3939
<WholeProgramOptimization>true</WholeProgramOptimization>
4040
<CharacterSet>Unicode</CharacterSet>
4141
</PropertyGroup>
4242
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4343
<ConfigurationType>Application</ConfigurationType>
4444
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v141</PlatformToolset>
45+
<PlatformToolset>v142</PlatformToolset>
4646
<CharacterSet>Unicode</CharacterSet>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4949
<ConfigurationType>Application</ConfigurationType>
5050
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v141</PlatformToolset>
51+
<PlatformToolset>v142</PlatformToolset>
5252
<WholeProgramOptimization>true</WholeProgramOptimization>
5353
<CharacterSet>Unicode</CharacterSet>
5454
</PropertyGroup>

UserPreferences.Shared/Encryption.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include <vector>
77
#include <string>
88

9-
#pragma comment(lib, "libeay32")
9+
#pragma comment(lib, "libssl_static")
10+
#pragma comment(lib, "libcrypto_static")
11+
#pragma comment(lib, "ws2_32")
1012

1113
namespace
1214
{
@@ -69,11 +71,12 @@ namespace
6971
auto cipher = EVP_aes_256_cbc();
7072
auto ctx = EVP_CIPHER_CTX_new();
7173

72-
auto num_blocks = plaintext.size() / cipher->block_size;
73-
if (plaintext.size() % cipher->block_size != 0) {
74+
auto cipher_block_size = EVP_CIPHER_block_size(cipher);
75+
auto num_blocks = plaintext.size() / cipher_block_size;
76+
if (plaintext.size() % cipher_block_size != 0) {
7477
++num_blocks;
7578
}
76-
auto out_plaintext = std::vector<uint8_t>(cipher->block_size * num_blocks);
79+
auto out_plaintext = std::vector<uint8_t>(cipher_block_size * num_blocks);
7780

7881
EVP_CIPHER_CTX_init(ctx);
7982

@@ -120,8 +123,11 @@ namespace
120123
auto cipher = EVP_aes_256_cbc();
121124
auto md = EVP_sha1();
122125

123-
out_key.resize(cipher->key_len);
124-
out_initialization_vector.resize(cipher->iv_len);
126+
auto cipher_key_length = EVP_CIPHER_key_length(cipher);
127+
auto cipher_iv_length = EVP_CIPHER_iv_length(cipher);
128+
129+
out_key.resize(cipher_key_length);
130+
out_initialization_vector.resize(cipher_iv_length);
125131

126132
auto derived_key_length = EVP_BytesToKey(
127133
cipher,
@@ -171,9 +177,9 @@ namespace
171177
/// <param name="is_encrypting">Determines if data should be encrypted or decrypted</param>
172178
/// <returns>Encrypted or decrypted data</returns>
173179
std::vector<uint8_t> EncryptOrDecryptData(
174-
const std::vector<uint8_t>& data,
175-
const std::string& machine_guid,
176-
const std::string& salt_string,
180+
const std::vector<uint8_t> &data,
181+
const std::string &machine_guid,
182+
const std::string &salt_string,
177183
bool is_encrypting)
178184
{
179185
std::vector<uint8_t> salt_bytes;
@@ -202,17 +208,17 @@ namespace UserPreferences
202208
namespace Encryption
203209
{
204210
std::vector<uint8_t> DecryptData(
205-
const std::vector<uint8_t>& encrypted_data,
206-
const std::string& machine_guid,
207-
const std::string& salt_string)
211+
const std::vector<uint8_t> &encrypted_data,
212+
const std::string &machine_guid,
213+
const std::string &salt_string)
208214
{
209215
return EncryptOrDecryptData(encrypted_data, machine_guid, salt_string, false);
210216
}
211217

212218
std::vector<uint8_t> EncryptData(
213-
const std::vector<uint8_t>& plaintext_data,
214-
const std::string& machine_guid,
215-
const std::string& salt_string)
219+
const std::vector<uint8_t> &plaintext_data,
220+
const std::string &machine_guid,
221+
const std::string &salt_string)
216222
{
217223
return EncryptOrDecryptData(plaintext_data, machine_guid, salt_string, true);
218224
}

UserPreferences.Shared/UserPreferences.Shared.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@
2323
<ProjectGuid>{21DB7E9B-DA4E-420E-A209-A4F6C339F10C}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>UserPreferencesShared</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2727
<ProjectName>UserPreferences.Shared</ProjectName>
2828
</PropertyGroup>
2929
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
3030
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3131
<ConfigurationType>StaticLibrary</ConfigurationType>
3232
<UseDebugLibraries>true</UseDebugLibraries>
33-
<PlatformToolset>v141</PlatformToolset>
33+
<PlatformToolset>v142</PlatformToolset>
3434
<CharacterSet>Unicode</CharacterSet>
3535
</PropertyGroup>
3636
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3737
<ConfigurationType>StaticLibrary</ConfigurationType>
3838
<UseDebugLibraries>false</UseDebugLibraries>
39-
<PlatformToolset>v141</PlatformToolset>
39+
<PlatformToolset>v142</PlatformToolset>
4040
<WholeProgramOptimization>true</WholeProgramOptimization>
4141
<CharacterSet>Unicode</CharacterSet>
4242
</PropertyGroup>
4343
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4444
<ConfigurationType>StaticLibrary</ConfigurationType>
4545
<UseDebugLibraries>true</UseDebugLibraries>
46-
<PlatformToolset>v141</PlatformToolset>
46+
<PlatformToolset>v142</PlatformToolset>
4747
<CharacterSet>Unicode</CharacterSet>
4848
</PropertyGroup>
4949
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
5050
<ConfigurationType>StaticLibrary</ConfigurationType>
5151
<UseDebugLibraries>false</UseDebugLibraries>
52-
<PlatformToolset>v141</PlatformToolset>
52+
<PlatformToolset>v142</PlatformToolset>
5353
<WholeProgramOptimization>true</WholeProgramOptimization>
5454
<CharacterSet>Unicode</CharacterSet>
5555
</PropertyGroup>

UserPreferencesExplorer/UserPreferencesExplorer.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323
<ProjectGuid>{69E20B05-83B9-444C-ADF6-6E28C9B056B0}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>UserPreferencesExplorer</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3030
<ConfigurationType>Application</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v141</PlatformToolset>
32+
<PlatformToolset>v142</PlatformToolset>
3333
<CharacterSet>Unicode</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>Application</ConfigurationType>
3737
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v141</PlatformToolset>
38+
<PlatformToolset>v142</PlatformToolset>
3939
<WholeProgramOptimization>true</WholeProgramOptimization>
4040
<CharacterSet>Unicode</CharacterSet>
4141
</PropertyGroup>
4242
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4343
<ConfigurationType>Application</ConfigurationType>
4444
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v141</PlatformToolset>
45+
<PlatformToolset>v142</PlatformToolset>
4646
<CharacterSet>Unicode</CharacterSet>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4949
<ConfigurationType>Application</ConfigurationType>
5050
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v141</PlatformToolset>
51+
<PlatformToolset>v142</PlatformToolset>
5252
<WholeProgramOptimization>true</WholeProgramOptimization>
5353
<CharacterSet>Unicode</CharacterSet>
5454
</PropertyGroup>

0 commit comments

Comments
 (0)