From 6f8ecb28c5cee680a4b448eff1a9453a67217ce3 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 8 Apr 2019 21:49:42 +0900 Subject: [PATCH] Correctly calculate MD5 hash for SSE-C keys Previously s3fs calculated the strlen of a binary input instead of using the stored length. This yielded IO errors when interacting with SSE-encrypted objects. Fixes #696. --- src/curl.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index e1f68de..eb8102c 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -63,7 +63,7 @@ static const std::string empty_payload_hash = "e3b0c44298fc1c149afbf4c8996fb9242 // This function uses temporary file, but should not use it. // For not using it, we implement function in each auth file(openssl, nss. gnutls). // -static bool make_md5_from_string(const char* pstr, string& md5) +static bool make_md5_from_binary(const char* pstr, size_t length, string& md5) { if(!pstr || '\0' == pstr[0]){ S3FS_PRN_ERR("Parameter is wrong."); @@ -74,7 +74,6 @@ static bool make_md5_from_string(const char* pstr, string& md5) S3FS_PRN_ERR("Could not make tmpfile."); return false; } - size_t length = strlen(pstr); if(length != fwrite(pstr, sizeof(char), length, fp)){ S3FS_PRN_ERR("Failed to write tmpfile."); fclose(fp); @@ -1006,7 +1005,7 @@ bool S3fsCurl::PushbackSseKeys(string& onekey) // make MD5 string strMd5; - if(!make_md5_from_string(raw_key.c_str(), strMd5)){ + if(!make_md5_from_binary(raw_key.c_str(), raw_key.length(), strMd5)){ S3FS_PRN_ERR("Could not make MD5 from SSE-C keys(%s).", raw_key.c_str()); return false; }