Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Unable to connect through HTTPS proxy #330

@neilkenny

Description

@neilkenny

We are having issues connecting to azure blob storage through a HTTPS proxy.

We have verified that the proxy details are correct, and have written a similar test app to the below one using the AWS S3 SDK that connects through the proxy without any issues.

If I remove the operationContext.set_proxy(proxy); line from the below code it connects.

The error we get is:
WinHttpReceiveResponse: 12030: The connection with the server was terminated abnormally

It seems to us that there is a problem with the SDK, here is code from the test app we have written:

    std::wstring wAzureAccountName = L"<storageaccount>";
    std::wstring wAzureAccountKey = L"<accountkey>";
    std::wstring wProxyType = utility::conversions::to_string_t("https");
    std::wstring wProxyHost = utility::conversions::to_string_t("10.225.70.163");
    std::wstring wProxyPort = utility::conversions::to_string_t("8443");
    std::wstring wProxyUsername = utility::conversions::to_string_t("<username>");
    std::wstring wProxyPassword = utility::conversions::to_string_t("<password>");
    std::string strErrMsg;
    bool connectionSucceed;

    azure::storage::cloud_storage_account storageAccount;
    azure::storage::cloud_blob_client blobClient;
    azure::storage::operation_context operationContext;
    azure::storage::blob_request_options options;

    azure::storage::storage_credentials storageCredentials
        = azure::storage::storage_credentials(wAzureAccountName, wAzureAccountKey);

    storageAccount = azure::storage::cloud_storage_account(storageCredentials, true);

    if (storageAccount.is_initialized()) {
        blobClient = storageAccount.create_cloud_blob_client();
        operationContext = azure::storage::operation_context();
        options = azure::storage::blob_request_options();
    }
    
    std::wstring address;
    address.append(wProxyType).append(L"://").append(wProxyHost).append(L":").append(wProxyPort);

    web::web_proxy proxy(address);

    web::credentials credentials(wProxyUsername, wProxyPassword);

    proxy.set_credentials(credentials);

    operationContext.set_proxy(proxy);

    try {
        auto containerIt = blobClient.list_containers(
            std::wstring(), azure::storage::container_listing_details::none, 0, options, operationContext);

        if (containerIt->is_valid()) {
            connectionSucceed = true;
        }
    }
    catch (azure::storage::storage_exception & storageException) {
        std::string code = std::to_string(storageException.result().http_status_code());
        std::string message(storageException.what());

        if (code.empty()) {
            message.clear();
            message.append("Invalid credentials or network issue");
        }

        strErrMsg.append("Failed to retrieve container for test: ").append(code).append(" : ").append(message);
    }
    catch (web::http::http_exception & httpException) {
        strErrMsg.append("Failed to retrieve container for test: ").append(httpException.error_code().message());
    }
    catch (web::uri_exception & uriException) {
        strErrMsg.append("Failed to create Azure Blob host error: ").append(uriException.what());
    }
    catch (std::exception & e) {
        strErrMsg.append("Failed to retrieve container for test: ").append(e.what());
    }

Following more in-depth investigation we noted the following:

  • If using an HTTPS Only proxy it will fail
  • This is because the server is attempting to use the proxy as an HTTP proxy rather than HTTPS
  • This is evident in a Wireshark trace where we can see the TCP handshake followed by an HTTP CONNECT in clear text
  • The TCP handshake should be followed by an SSL negotiation and the HTTP CONNECT should occur of the SSL connection instead

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions