Skip to content

Commit 87ce0ff

Browse files
committed
CXX-1506 Don't checksum GridFS files
The GridFS spec has deprecated the checksum feature, and FIPS compliance prohibits MD5.
1 parent 2a3cde8 commit 87ce0ff

File tree

9 files changed

+5
-581
lines changed

9 files changed

+5
-581
lines changed

THIRD-PARTY-NOTICES

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,3 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
3636
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
3737
License for the specific language governing permissions and limitations
3838
under the License.
39-
40-
3) License notice for Aladdin MD5
41-
---------------------------------
42-
43-
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
44-
45-
This software is provided 'as-is', without any express or implied
46-
warranty. In no event will the authors be held liable for any damages
47-
arising from the use of this software.
48-
49-
Permission is granted to anyone to use this software for any purpose,
50-
including commercial applications, and to alter it and redistribute it
51-
freely, subject to the following restrictions:
52-
53-
1. The origin of this software must not be misrepresented; you must not
54-
claim that you wrote the original software. If you use this software
55-
in a product, an acknowledgment in the product documentation would be
56-
appreciated but is not required.
57-
2. Altered source versions must be plainly marked as such, and must not be
58-
misrepresented as being the original software.
59-
3. This notice may not be removed or altered from any source distribution.
60-
61-
L. Peter Deutsch
62-
ghost@aladdin.com

src/mongocxx/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ set(mongocxx_sources
107107
result/insert_one.cpp
108108
result/replace_one.cpp
109109
result/update.cpp
110-
third_party/md5.cpp
111110
uri.cpp
112111
validation_criteria.cpp
113112
write_concern.cpp

src/mongocxx/gridfs/private/uploader.hh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <string>
1818
#include <vector>
1919

20-
#include <mongocxx/third_party/md5.h>
2120
#include <bsoncxx/stdx/make_unique.hpp>
2221
#include <bsoncxx/string/to_string.hpp>
2322
#include <mongocxx/gridfs/uploader.hpp>
@@ -45,9 +44,7 @@ class uploader::impl {
4544
filename{bsoncxx::string::to_string(filename)},
4645
files{std::move(files)},
4746
metadata{std::move(metadata)},
48-
result{std::move(result)} {
49-
md5_init(&md5);
50-
}
47+
result{std::move(result)} {}
5148

5249
// Bytes that have been written for the current chunk.
5350
std::unique_ptr<std::uint8_t[]> buffer;
@@ -76,9 +73,6 @@ class uploader::impl {
7673
// The collection to which the files document will be written.
7774
collection files;
7875

79-
// Keeps track of the md5 hash of the file.
80-
md5_state_t md5;
81-
8276
// User-specified metadata for the file.
8377
stdx::optional<bsoncxx::document::value> metadata;
8478

src/mongocxx/gridfs/uploader.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,6 @@ result::gridfs::upload uploader::close() {
111111
file.append(kvp("length", bytes_uploaded + leftover));
112112
file.append(kvp("chunkSize", _get_impl().chunk_size));
113113
file.append(kvp("uploadDate", bsoncxx::types::b_date{std::chrono::system_clock::now()}));
114-
115-
md5_byte_t md5_hash_array[16];
116-
md5_finish(&_get_impl().md5, md5_hash_array);
117-
118-
std::stringstream md5_hash;
119-
120-
for (auto i = 0; i < 16; ++i) {
121-
md5_hash << std::setfill('0') << std::setw(2) << std::hex
122-
<< static_cast<int>(md5_hash_array[i]);
123-
}
124-
125-
file.append(kvp("md5", md5_hash.str()));
126114
file.append(kvp("filename", _get_impl().filename));
127115

128116
if (_get_impl().metadata) {
@@ -175,9 +163,6 @@ void uploader::finish_chunk() {
175163
static_cast<std::uint32_t>(bytes_in_chunk),
176164
_get_impl().buffer.get()};
177165

178-
md5_append(
179-
&_get_impl().md5, _get_impl().buffer.get(), static_cast<std::int32_t>(bytes_in_chunk));
180-
181166
chunk.append(kvp("data", data));
182167
_get_impl().chunks_collection_documents.push_back(chunk.extract());
183168

src/mongocxx/private/md5.hh

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/mongocxx/test/gridfs/bucket.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ void validate_gridfs_file(database db,
6565
REQUIRE(files_doc->view()["filename"].get_utf8().value ==
6666
stdx::string_view(expected_file_name));
6767

68+
// md5 is deprecated in GridFS, we don't include it:
69+
// https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst
70+
REQUIRE(!files_doc->view()["md5"]);
71+
6872
std::int32_t index = 0;
6973

7074
for (auto&& chunks_doc :

src/mongocxx/test/spec/gridfs.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ void compare_collections(database db) {
160160
REQUIRE(actual["chunkSize"]);
161161
REQUIRE(expected["chunkSize"].get_int32().value == actual["chunkSize"].get_int32().value);
162162

163-
REQUIRE(expected["md5"]);
164-
REQUIRE(actual["md5"]);
165-
REQUIRE(expected["md5"].get_utf8().value == actual["md5"].get_utf8().value);
166-
167163
REQUIRE(expected["filename"]);
168164
REQUIRE(actual["filename"]);
169165
REQUIRE(expected["filename"].get_utf8().value == actual["filename"].get_utf8().value);

0 commit comments

Comments
 (0)