Skip to content

Commit e01a05c

Browse files
committed
Updating to use SecureZeroMemory on WinRT.
1 parent b9b9498 commit e01a05c

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

Release/include/cpprest/web_utilities.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class credentials
8484
{
8585
public:
8686
/// <summary>
87-
/// Constructs and empty set of credentials without a user name or password.
87+
/// Constructs an empty set of credentials without a user name or password.
8888
/// </summary>
8989
credentials() {}
9090

@@ -148,7 +148,7 @@ class credentials
148148

149149
/// <summary>
150150
/// web_proxy represents the concept of the web proxy, which can be auto-discovered,
151-
/// disabled, or specified explicitly by the user
151+
/// disabled, or specified explicitly by the user.
152152
/// </summary>
153153
class web_proxy
154154
{

Release/src/http/client/http_win7.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,30 +883,28 @@ class winhttp_client : public _http_client_communicator
883883
// we cannot call WinHttpQueryAuthSchemes and WinHttpSetCredentials.
884884
if (error != ERROR_WINHTTP_RESEND_REQUEST)
885885
{
886+
// Obtain the supported and preferred schemes.
886887
DWORD dwSupportedSchemes;
887888
DWORD dwFirstScheme;
888-
DWORD dwSelectedScheme = 0;
889889
DWORD dwAuthTarget;
890-
credentials cred;
891-
892-
// Obtain the supported and preferred schemes.
893890
if(!WinHttpQueryAuthSchemes(
894891
hRequestHandle,
895892
&dwSupportedSchemes,
896893
&dwFirstScheme,
897-
&dwAuthTarget))
894+
&dwAuthTarget))
898895
{
899896
// This will return the authentication failure to the user, without reporting fatal errors
900897
return false;
901898
}
902899

903-
dwSelectedScheme = ChooseAuthScheme(dwSupportedSchemes);
900+
DWORD dwSelectedScheme = ChooseAuthScheme(dwSupportedSchemes);
904901
if(dwSelectedScheme == 0)
905902
{
906903
// This will return the authentication failure to the user, without reporting fatal errors
907904
return false;
908905
}
909906

907+
credentials cred;
910908
if (dwAuthTarget == WINHTTP_AUTH_TARGET_SERVER && !p_request_context->m_server_authentication_tried)
911909
{
912910
cred = p_request_context->m_http_client->client_config().credentials();

Release/src/utilities/web_utilities.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,15 @@ namespace details
4242
#if defined(_MS_WINDOWS)
4343
#if defined(__cplusplus_winrt)
4444

45-
// Helper function since SecureZeroMemory isn't available.
46-
void winrt_secure_zero_memory(_Out_writes_(count) void *buffer, _In_ size_t count)
47-
{
48-
auto vptr = reinterpret_cast<volatile char *>(buffer);
49-
while (count != 0)
50-
{
51-
*vptr = 0;
52-
++vptr;
53-
--count;
54-
}
55-
}
45+
// Helper function to zero out memory of an IBuffer.
5646
void winrt_secure_zero_buffer(Windows::Storage::Streams::IBuffer ^buffer)
5747
{
5848
Microsoft::WRL::ComPtr<IInspectable> bufferInspectable(reinterpret_cast<IInspectable *>(buffer));
5949
Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess;
6050
bufferInspectable.As(&bufferByteAccess);
6151
byte * rawBytes;
6252
bufferByteAccess->Buffer(&rawBytes);
63-
winrt_secure_zero_memory(rawBytes, buffer->Length);
53+
SecureZeroMemory(rawBytes, buffer->Length);
6454
}
6555

6656
winrt_encryption::winrt_encryption(const std::wstring &data)
@@ -98,7 +88,7 @@ plaintext_string winrt_encryption::decrypt() const
9888
auto data = plaintext_string(new std::wstring(
9989
reinterpret_cast<const std::wstring::value_type *>(rawPlaintext),
10090
plaintext->Length / 2));
101-
winrt_secure_zero_memory(rawPlaintext, plaintext->Length);
91+
SecureZeroMemory(rawPlaintext, plaintext->Length);
10292
return std::move(data);
10393
}
10494
#else
@@ -144,11 +134,7 @@ plaintext_string win32_encryption::decrypt() const
144134

145135
void zero_memory_deleter::operator()(::utility::string_t *data) const
146136
{
147-
#if defined(__cplusplus_winrt)
148-
winrt_secure_zero_memory(
149-
#else
150137
SecureZeroMemory(
151-
#endif
152138
const_cast<::utility::string_t::value_type *>(data->data()),
153139
data->size() * sizeof(::utility::string_t::value_type));
154140
delete data;

0 commit comments

Comments
 (0)