Skip to content

Unable to read the blob object data on FIPS enabled environment due to MD5 is restricted and missing API to enable/disable MD5 Content hash #6474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
csi-amolpawar opened this issue Mar 19, 2025 · 3 comments
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@csi-amolpawar
Copy link

Describe the bug
Unable to read the blob object data on FIPS enabled environment

[user1@kk60-fips bin]$ fips-mode-setup --check
FIPS mode is enabled.
[user1@kk60-fips bin]$ ./blob-reader testcontainer testblob.txt 
error: Crypto error while init Md5Hash.

due to MD5 is restricted and missing API to enable/disable the MD5 content hash

Please refer this migration guide which clearly specify the missing MD5 configuration in version 12, was provided in the previous version 7.5
https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/storage/MigrationGuide.md#blob-content-md5

To Reproduce
Steps to reproduce the behavior:
The issue is easily reproducible with below code

#include <iostream>
#include <string>
#include <sstream>
#include <memory>
#include <stdexcept>
#include <azure/storage/blobs.hpp>                       // For azure blob
#include <azure/storage/common/storage_exception.hpp>    // For azure exceptions

using namespace Azure::Storage;
using namespace Azure::Storage::Blobs;

int main(int argc, char** argv) try
{
  if(argc == 3)
  {
    std::string container(argv[1]), blob(argv[2]);
    std::string accountname("testaccount");
    std::string accountkey("accountkey");

    std::ostringstream url;
    url << "https://" << accountname << ".blob.core.windows.net/"
        << container <<  '/' << blob;

    auto credential = std::make_shared<StorageSharedKeyCredential>(
      accountname, accountkey);

    auto blob_client = std::make_unique<BlobClient>(url.str(), credential);
    auto blobsize = blob_client->GetProperties().Value.BlobSize;

    DownloadBlobOptions download_options;
    download_options.Range = { 0, blobsize };

    auto response = blob_client->Download(download_options).Value;
    auto contenthash = response.Details.HttpHeaders.ContentHash.Value;

    Azure::Core::Cryptography::Md5Hash md5hash;
    
    const auto BUFFER_SIZE = 4 * 1'024 * 1'024;
    std::array<char, BUFFER_SIZE> outbuf;
    auto stream = std::move(response.BodyStream);
    for (int64_t offset = 0; offset != blobsize; )
    {
      auto readsize = stream->Read((uint8_t*)outbuf.data(), BUFFER_SIZE);
      md5hash.Append((const uint8_t*)outbuf.data(), readsize);
      offset += readsize;
    }

    if(md5hash.Final() != contenthash)
    {
      std::ostringstream oss; oss << ": Download blob failed: "
        << "Bad Hash(md5/crc64)";
      throw std::runtime_error(oss.str());
    }
    std::cout << "The md4 hash is successful for az://" << argv[1] << "/" << argv[2] << std::endl;
  }
  else
  {
    std::cout << argv[0] << " <container> <blob>" << std::endl;
  }
  return 0;
}
catch(const std::exception& e)
{
  std::cout << "error: " << e.what() << std::endl;
}

Expected behavior
The program should able to read blob irrespective of its environment i.e on FIPS enabled by configuring the MD5 content hash flag as ON/OFF

Setup (please complete the following information):

  • OS: Rocky Linux 9.5 (Blue Onyx)
  • Version of the Library used : 12.10.0
  • C++ Version: g++ (GCC) 11.5.0

Additional context
This should work as usual like Non FIPS environment

[user2@8e3dcaf8d95e azure]# fips-mode-setup --check
Installation of FIPS modules is not completed.
cat: /proc/sys/crypto/fips_enabled: No such file or directory
FIPS mode is .
[user2@8e3dcaf8d95e azure]# ./blob-reader testcontainer testblob.txt 
The md4 hash is successful for az://testcontainer/testblob.txt
@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Mar 19, 2025
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Jinming-Hu @microzchang @vinjiang.

@csi-amolpawar csi-amolpawar changed the title Unable to read the blob object data on FIPS enabled environment due to MD5 is restricted and missing configuration setting for MD5 Unable to read the blob object data on FIPS enabled environment due to MD5 is restricted and missing API to enable/disable MD5 Content has Mar 19, 2025
@csi-amolpawar csi-amolpawar changed the title Unable to read the blob object data on FIPS enabled environment due to MD5 is restricted and missing API to enable/disable MD5 Content has Unable to read the blob object data on FIPS enabled environment due to MD5 is restricted and missing API to enable/disable MD5 Content hash Mar 19, 2025
@Jinming-Hu
Copy link
Member

The exception is thrown from azure-core SDK

throw std::runtime_error("Crypto error while init Md5Hash.");

@Jinming-Hu Jinming-Hu added Azure.Core and removed Storage Storage Service (Queues, Blobs, Files) labels May 7, 2025
@csi-amolpawar
Copy link
Author

@Jinming-Hu Yes, Can we get API to enable/disable md5 and use method like CRC64 etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants