Skip to content

Commit

Permalink
Disabling oauth1.
Browse files Browse the repository at this point in the history
  • Loading branch information
stgates committed Aug 14, 2014
1 parent fd880ca commit aa39c5f
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 86 deletions.
10 changes: 7 additions & 3 deletions Release/include/cpprest/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace client
{

// credentials and web_proxy class has been moved from web::http::client namespace to web namespace.
// The below using declarations ensure we dont break existing code.
// The below using declarations ensure we don't break existing code.
// Please use the web::credentials and web::web_proxy class going forward.
using web::credentials;
using web::web_proxy;
Expand Down Expand Up @@ -118,7 +118,9 @@ class http_client_config
/// <returns>Shared pointer to OAuth 1.0 configuration.</returns>
const std::shared_ptr<oauth1::experimental::oauth1_config> oauth1() const
{
return m_oauth1;
// CodePlex #230
throw std::runtime_error("oauth1 is not implemented yet.");
//return m_oauth1;
}

/// <summary>
Expand All @@ -127,7 +129,9 @@ class http_client_config
/// <param name="config">OAuth 1.0 configuration to set.</param>
void set_oauth1(oauth1::experimental::oauth1_config config)
{
m_oauth1 = std::make_shared<oauth1::experimental::oauth1_config>(std::move(config));
// CodePlex #230
throw std::runtime_error("oauth1 is not implemented yet.");
//m_oauth1 = std::make_shared<oauth1::experimental::oauth1_config>(std::move(config));
}
#endif

Expand Down
1 change: 1 addition & 0 deletions Release/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ elseif(WIN32)
http/client/http_win7.cpp
http/listener/http_windows_server.cpp
http/oauth/oauth1.cpp
http/oauth/oauth2.cpp
streams/windows/fileio.cpp
streams/windows/ioscheduler.cpp
utilities/dllmain.cpp
Expand Down
2 changes: 1 addition & 1 deletion Release/src/build/sources.proj
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@

<!-- non-TargetXP and non-Phone8.0 files go here-->
<ItemGroup Condition ="'$(TargetXP)' != 'true' and '$(PlatformToolset)' != 'v110_wp80'">
<ClInclude Include="$(CasablancaIncludeDir)\cpprest\oauth1.h">
<ClInclude Include="$(CasablancaIncludeDir)\cpprest\oauth1.h">
<Filter>Header Files\cpprest</Filter>
</ClInclude>
<ClCompile Include="$(CasablancaSrcDir)\http\oauth\oauth1.cpp">
Expand Down
85 changes: 9 additions & 76 deletions Release/src/http/oauth/oauth1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,60 +59,10 @@ namespace experimental
#include <winternl.h>
#include <bcrypt.h>

std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data)
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&, const utility::string_t&)
{
NTSTATUS status;
BCRYPT_ALG_HANDLE alg_handle = nullptr;
BCRYPT_HASH_HANDLE hash_handle = nullptr;

std::vector<unsigned char> hash;
DWORD hash_len = 0;
ULONG result_len = 0;

auto key_c = conversions::utf16_to_utf8(key);
auto data_c = conversions::utf16_to_utf8(data);

status = BCryptOpenAlgorithmProvider(&alg_handle, BCRYPT_SHA1_ALGORITHM, nullptr, BCRYPT_ALG_HANDLE_HMAC_FLAG);
if (!NT_SUCCESS(status))
{
goto cleanup;
}
status = BCryptGetProperty(alg_handle, BCRYPT_HASH_LENGTH, (PBYTE) &hash_len, sizeof(hash_len), &result_len, 0);
if (!NT_SUCCESS(status))
{
goto cleanup;
}
hash.resize(hash_len);

status = BCryptCreateHash(alg_handle, &hash_handle, nullptr, 0, (PBYTE) key_c.c_str(), (ULONG) key_c.length(), 0);
if (!NT_SUCCESS(status))
{
goto cleanup;
}
status = BCryptHashData(hash_handle, (PBYTE) data_c.c_str(), (ULONG) data_c.length(), 0);
if (!NT_SUCCESS(status))
{
goto cleanup;
}
status = BCryptFinishHash(hash_handle, hash.data(), hash_len, 0);
if (!NT_SUCCESS(status))
{
goto cleanup;
}

return hash;

cleanup:
if (hash_handle)
{
BCryptDestroyHash(hash_handle);
}
if (alg_handle)
{
BCryptCloseAlgorithmProvider(alg_handle, 0);
}

return hash;
// CodePlex #230
throw std::runtime_error("oauth1 is not implemented yet.");
}

#elif defined(_MS_WINDOWS) && defined(__cplusplus_winrt) // Windows RT
Expand All @@ -121,37 +71,20 @@ using namespace Windows::Security::Cryptography;
using namespace Windows::Security::Cryptography::Core;
using namespace Windows::Storage::Streams;

std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data)
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&, const utility::string_t&)
{
Platform::String^ data_str = ref new Platform::String(data.c_str());
Platform::String^ key_str = ref new Platform::String(key.c_str());

MacAlgorithmProvider^ HMACSha1Provider = MacAlgorithmProvider::OpenAlgorithm(MacAlgorithmNames::HmacSha1);
IBuffer^ content_buffer = CryptographicBuffer::ConvertStringToBinary(data_str, BinaryStringEncoding::Utf8);
IBuffer^ key_buffer = CryptographicBuffer::ConvertStringToBinary(key_str, BinaryStringEncoding::Utf8);

auto signature_key = HMACSha1Provider->CreateKey(key_buffer);
auto signed_buffer = CryptographicEngine::Sign(signature_key, content_buffer);

Platform::Array<unsigned char, 1>^ arr;
CryptographicBuffer::CopyToByteArray(signed_buffer, &arr);
return std::vector<unsigned char>(arr->Data, arr->Data + arr->Length);
// CodePlex #230
throw std::runtime_error("oauth1 is not implemented yet.");
}

#else // Linux, Mac OS X

#include <openssl/hmac.h>

std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data)
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&, const utility::string_t&)
{
unsigned char digest[HMAC_MAX_MD_CBLOCK];
unsigned int digest_len = 0;

HMAC(EVP_sha1(), key.c_str(), static_cast<int>(key.length()),
(const unsigned char*) data.c_str(), data.length(),
digest, &digest_len);

return std::vector<unsigned char>(digest, digest + digest_len);
// CodePlex #230
throw std::runtime_error("oauth1 is not implemented yet.");
}

#endif
Expand Down
1 change: 0 additions & 1 deletion Release/tests/Functional/http/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ set(SOURCES
http_client_tests.cpp
http_methods_tests.cpp
multiple_requests.cpp
oauth1_tests.cpp
oauth2_tests.cpp
outside_tests.cpp
pipeline_stage_tests.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
<ClCompile Include="..\header_tests.cpp" />
<ClCompile Include="..\http_client_tests.cpp" />
<ClCompile Include="..\http_methods_tests.cpp" />
<ClCompile Include="..\oauth1_tests.cpp" />
<ClCompile Include="..\oauth2_tests.cpp" />
<ClCompile Include="..\outside_tests.cpp" />
<ClCompile Include="..\multiple_requests.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
<ClCompile Include="..\header_tests.cpp" />
<ClCompile Include="..\http_client_tests.cpp" />
<ClCompile Include="..\http_methods_tests.cpp" />
<ClCompile Include="..\oauth1_tests.cpp" />
<ClCompile Include="..\oauth2_tests.cpp" />
<ClCompile Include="..\outside_tests.cpp" />
<ClCompile Include="..\multiple_requests.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@
<ClCompile Include="..\header_tests.cpp" />
<ClCompile Include="..\http_client_tests.cpp" />
<ClCompile Include="..\http_methods_tests.cpp" />
<ClCompile Include="..\oauth1_tests.cpp" />
<ClCompile Include="..\oauth2_tests.cpp" />
<ClCompile Include="..\outside_tests.cpp" />
<ClCompile Include="..\multiple_requests.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@
<ClCompile Include="..\header_tests.cpp" />
<ClCompile Include="..\http_client_tests.cpp" />
<ClCompile Include="..\http_methods_tests.cpp" />
<ClCompile Include="..\oauth1_tests.cpp" />
<ClCompile Include="..\oauth2_tests.cpp" />
<ClCompile Include="..\outside_tests.cpp" />
<ClCompile Include="..\multiple_requests.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
<ClCompile Include="..\header_tests.cpp" />
<ClCompile Include="..\http_client_tests.cpp" />
<ClCompile Include="..\http_methods_tests.cpp" />
<ClCompile Include="..\oauth1_tests.cpp" />
<ClCompile Include="..\oauth2_tests.cpp" />
<ClCompile Include="..\outside_tests.cpp" />
<ClCompile Include="..\multiple_requests.cpp" />
Expand Down

0 comments on commit aa39c5f

Please sign in to comment.