From ea5889236bd3c41b24a34788cf3415e18591f5a3 Mon Sep 17 00:00:00 2001 From: nooperation Date: Sat, 16 Nov 2019 18:14:17 -0500 Subject: [PATCH] Updated to use latest openssl, vs2019 moving over to static openssl usage --- .gitignore | 2 ++ LibUserPreferences/LibUserPreferences.vcxproj | 10 +++--- UserPreferences.Shared.Tests/Tests.cpp | 10 ++---- .../UserPreferences.Shared.Tests.vcxproj | 10 +++--- UserPreferences.Shared/Encryption.cpp | 36 +++++++++++-------- .../UserPreferences.Shared.vcxproj | 10 +++--- .../UserPreferencesExplorer.vcxproj | 10 +++--- 7 files changed, 45 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 940794e..1fb529e 100644 --- a/.gitignore +++ b/.gitignore @@ -286,3 +286,5 @@ __pycache__/ *.btm.cs *.odx.cs *.xsd.cs + +Directory.Build.props \ No newline at end of file diff --git a/LibUserPreferences/LibUserPreferences.vcxproj b/LibUserPreferences/LibUserPreferences.vcxproj index 6249391..8c006c9 100644 --- a/LibUserPreferences/LibUserPreferences.vcxproj +++ b/LibUserPreferences/LibUserPreferences.vcxproj @@ -23,32 +23,32 @@ {E8A8F157-EBAE-43E4-90AE-32A8DAC51096} Win32Proj LibUserPreferences - 10.0.16299.0 + 10.0 DynamicLibrary true - v141 + v142 Unicode DynamicLibrary false - v141 + v142 true Unicode DynamicLibrary true - v141 + v142 Unicode DynamicLibrary false - v141 + v142 true Unicode diff --git a/UserPreferences.Shared.Tests/Tests.cpp b/UserPreferences.Shared.Tests/Tests.cpp index 28fc4d3..95345df 100644 --- a/UserPreferences.Shared.Tests/Tests.cpp +++ b/UserPreferences.Shared.Tests/Tests.cpp @@ -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{ - 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") diff --git a/UserPreferences.Shared.Tests/UserPreferences.Shared.Tests.vcxproj b/UserPreferences.Shared.Tests/UserPreferences.Shared.Tests.vcxproj index 6f475fa..b2e1b8e 100644 --- a/UserPreferences.Shared.Tests/UserPreferences.Shared.Tests.vcxproj +++ b/UserPreferences.Shared.Tests/UserPreferences.Shared.Tests.vcxproj @@ -23,32 +23,32 @@ {74BE1B66-A57A-44D1-9D92-05C1596BE7DA} Win32Proj UserPreferencesSharedTests - 10.0.15063.0 + 10.0 Application true - v141 + v142 Unicode Application false - v141 + v142 true Unicode Application true - v141 + v142 Unicode Application false - v141 + v142 true Unicode diff --git a/UserPreferences.Shared/Encryption.cpp b/UserPreferences.Shared/Encryption.cpp index 5d77278..f25d686 100644 --- a/UserPreferences.Shared/Encryption.cpp +++ b/UserPreferences.Shared/Encryption.cpp @@ -6,7 +6,9 @@ #include #include -#pragma comment(lib, "libeay32") +#pragma comment(lib, "libssl_static") +#pragma comment(lib, "libcrypto_static") +#pragma comment(lib, "ws2_32") namespace { @@ -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(cipher->block_size * num_blocks); + auto out_plaintext = std::vector(cipher_block_size * num_blocks); EVP_CIPHER_CTX_init(ctx); @@ -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, @@ -171,9 +177,9 @@ namespace /// Determines if data should be encrypted or decrypted /// Encrypted or decrypted data std::vector EncryptOrDecryptData( - const std::vector& data, - const std::string& machine_guid, - const std::string& salt_string, + const std::vector &data, + const std::string &machine_guid, + const std::string &salt_string, bool is_encrypting) { std::vector salt_bytes; @@ -202,17 +208,17 @@ namespace UserPreferences namespace Encryption { std::vector DecryptData( - const std::vector& encrypted_data, - const std::string& machine_guid, - const std::string& salt_string) + const std::vector &encrypted_data, + const std::string &machine_guid, + const std::string &salt_string) { return EncryptOrDecryptData(encrypted_data, machine_guid, salt_string, false); } std::vector EncryptData( - const std::vector& plaintext_data, - const std::string& machine_guid, - const std::string& salt_string) + const std::vector &plaintext_data, + const std::string &machine_guid, + const std::string &salt_string) { return EncryptOrDecryptData(plaintext_data, machine_guid, salt_string, true); } diff --git a/UserPreferences.Shared/UserPreferences.Shared.vcxproj b/UserPreferences.Shared/UserPreferences.Shared.vcxproj index 178206f..3fca3f7 100644 --- a/UserPreferences.Shared/UserPreferences.Shared.vcxproj +++ b/UserPreferences.Shared/UserPreferences.Shared.vcxproj @@ -23,33 +23,33 @@ {21DB7E9B-DA4E-420E-A209-A4F6C339F10C} Win32Proj UserPreferencesShared - 10.0.16299.0 + 10.0 UserPreferences.Shared StaticLibrary true - v141 + v142 Unicode StaticLibrary false - v141 + v142 true Unicode StaticLibrary true - v141 + v142 Unicode StaticLibrary false - v141 + v142 true Unicode diff --git a/UserPreferencesExplorer/UserPreferencesExplorer.vcxproj b/UserPreferencesExplorer/UserPreferencesExplorer.vcxproj index 28ac882..9f4b19c 100644 --- a/UserPreferencesExplorer/UserPreferencesExplorer.vcxproj +++ b/UserPreferencesExplorer/UserPreferencesExplorer.vcxproj @@ -23,32 +23,32 @@ {69E20B05-83B9-444C-ADF6-6E28C9B056B0} Win32Proj UserPreferencesExplorer - 10.0.15063.0 + 10.0 Application true - v141 + v142 Unicode Application false - v141 + v142 true Unicode Application true - v141 + v142 Unicode Application false - v141 + v142 true Unicode