Skip to content

Commit bcf6881

Browse files
committed
Update usage of couch_hash:md5_hash shim
#1445 introduced a shim to enable CouchDB to be compiled to use the Erlang MD5 function. This allows CouchDB to run in FIPS environments where the crypto module is restricted such that `crypto:hash(md5,..)` is blocked (fails with `notsup` error). This commit replaces usage of `crypto:hash(md5, ..)` introduced since the original PR with the shim function.
1 parent 6d432a9 commit bcf6881

6 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/couch_mrview/test/eunit/couch_mrview_purge_docs_tests.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ test_purge_partial(Db) ->
139139
FDI1 = couch_db:get_full_doc_info(Db, <<"1">>), Rev1 = get_rev(FDI1),
140140
Update = {[
141141
{'_id', <<"1">>},
142-
{'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
142+
{'_rev', couch_doc:rev_to_str({1, [couch_hash:md5_hash(<<"1.2">>)]})},
143143
{'val', 1.2}
144144
]},
145145
{ok, [_Rev2]} = save_docs(Db, [Update], [replicated_changes]),

src/couch_pse_tests/src/cpse_test_purge_docs.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ cpse_purge_partial_revs(DbName) ->
253253
{ok, Rev1} = cpse_util:save_doc(DbName, {[{'_id', foo}, {vsn, <<"1.1">>}]}),
254254
Update = {[
255255
{'_id', foo},
256-
{'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
256+
{'_rev', couch_doc:rev_to_str({1, [couch_hash:md5_hash(<<"1.2">>)]})},
257257
{vsn, <<"1.2">>}
258258
]},
259259
{ok, [_Rev2]} = cpse_util:save_docs(DbName, [Update], [replicated_changes]),
@@ -392,7 +392,7 @@ cpse_purge_repeated_revisions(DbName) ->
392392
{ok, Rev1} = cpse_util:save_doc(DbName, {[{'_id', foo}, {vsn, <<"1.1">>}]}),
393393
Update = {[
394394
{'_id', foo},
395-
{'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
395+
{'_rev', couch_doc:rev_to_str({1, [couch_hash:md5_hash(<<"1.2">>)]})},
396396
{vsn, <<"1.2">>}
397397
]},
398398
{ok, [Rev2]} = cpse_util:save_docs(DbName, [Update], [replicated_changes]),

src/couch_pse_tests/src/cpse_test_purge_seqs.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ cpse_increment_purge_seq_on_partial_purge(DbName) ->
101101
{ok, Rev1} = cpse_util:save_doc(DbName, {[{'_id', foo1}, {vsn, <<"1.1">>}]}),
102102
Update = {[
103103
{'_id', foo1},
104-
{'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
104+
{'_rev', couch_doc:rev_to_str({1, [couch_hash:md5_hash(<<"1.2">>)]})},
105105
{vsn, <<"1.2">>}
106106
]},
107107
{ok, [_Rev2]} = cpse_util:save_docs(DbName, [Update], [replicated_changes]),

src/couch_pse_tests/src/cpse_util.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ gen_write(Db, {Action, {DocId, Body, Atts}}) ->
371371

372372

373373
gen_rev(A, DocId, {Pos, Rev}, Body, Atts) when A == update; A == delete ->
374-
NewRev = crypto:hash(md5, term_to_binary({DocId, Rev, Body, Atts})),
374+
NewRev = couch_hash:md5_hash(term_to_binary({DocId, Rev, Body, Atts})),
375375
{Pos + 1, [NewRev, Rev]};
376376
gen_rev(conflict, DocId, _, Body, Atts) ->
377377
UUID = couch_uuids:random(),
378-
NewRev = crypto:hash(md5, term_to_binary({DocId, UUID, Body, Atts})),
378+
NewRev = couch_hash:md5_hash(term_to_binary({DocId, UUID, Body, Atts})),
379379
{1, [NewRev]}.
380380

381381

src/dreyfus/src/dreyfus_index.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ handle_info({'EXIT', FromPid, {updated, NewSeq}},
197197
nil;
198198
false ->
199199
spawn_link(fun() ->
200-
dreyfus_index_updater:update(IndexPid, Index)
200+
dreyfus_index_updater:update(IndexPid, Index)
201201
end)
202202
end,
203203
{noreply, State#state{index=Index,
@@ -274,7 +274,7 @@ design_doc_to_index(#doc{id=Id,body={Fields}}, IndexName) ->
274274
undefined ->
275275
{error, InvalidDDocError};
276276
Def ->
277-
Sig = ?l2b(couch_util:to_hex(crypto:hash(md5,
277+
Sig = ?l2b(couch_util:to_hex(couch_hash:md5_hash(
278278
term_to_binary({Analyzer, Def})))),
279279
{ok, #index{
280280
analyzer=Analyzer,

src/fabric/test/eunit/fabric_rpc_purge_tests.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ create_update(Doc, NewVsn) ->
241241
body = {Props}
242242
} = Doc,
243243
NewProps = lists:keyreplace(<<"vsn">>, 1, Props, {<<"vsn">>, NewVsn}),
244-
NewRev = crypto:hash(md5, term_to_binary({DocId, Rev, {NewProps}})),
244+
NewRev = couch_hash:md5_hash(term_to_binary({DocId, Rev, {NewProps}})),
245245
Doc#doc{
246246
revs = {Pos + 1, [NewRev | Revs]},
247247
body = {NewProps}

0 commit comments

Comments
 (0)