diff options
author | Jan Lehnardt <jan@apache.org> | 2017-10-31 22:05:14 +0100 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2017-10-31 22:05:14 +0100 |
commit | abc545ad7e00f1fa06def8baef1d6a3faa5c2355 (patch) | |
tree | 90fa12ee5d03efaee8828bb1c85c9375e61434c9 | |
parent | dccb6a193d25bfa551af6ccd1fd26b2fc2357d5a (diff) | |
download | couchdb-abc545ad7e00f1fa06def8baef1d6a3faa5c2355.tar.gz |
R20 compatarchive/one-ex-exone-ex-ex
-rw-r--r-- | src/couch_plugins/src/couch_plugins.erl | 2 | ||||
-rw-r--r-- | src/couch_replicator/test/couch_replicator_missing_stubs_tests.erl | 2 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_auth.erl | 8 | ||||
-rw-r--r-- | src/couchdb/couch_passwords.erl | 6 | ||||
-rw-r--r-- | src/couchdb/couch_server.erl | 2 | ||||
-rw-r--r-- | src/couchdb/couch_util.erl | 10 | ||||
-rw-r--r-- | src/couchdb/couch_uuids.erl | 6 | ||||
-rw-r--r-- | src/erlang-oauth/oauth.erl | 4 | ||||
-rw-r--r-- | src/mochiweb/mochiweb_multipart.erl | 2 | ||||
-rw-r--r-- | src/my-first-couchdb-plugin/Makefile | 2 | ||||
-rw-r--r-- | test/couchdb/couch_auth_cache_tests.erl | 2 | ||||
-rw-r--r-- | test/couchdb/couch_btree_tests.erl | 8 | ||||
-rw-r--r-- | test/couchdb/couch_file_tests.erl | 4 | ||||
-rw-r--r-- | test/couchdb/couchdb_views_tests.erl | 2 |
14 files changed, 30 insertions, 30 deletions
diff --git a/src/couch_plugins/src/couch_plugins.erl b/src/couch_plugins/src/couch_plugins.erl index a4950be08..b0e0f6f92 100644 --- a/src/couch_plugins/src/couch_plugins.erl +++ b/src/couch_plugins/src/couch_plugins.erl @@ -228,7 +228,7 @@ do_verify_checksum(Filename, Checksum) -> ?LOG_DEBUG("Checking Filename: ~s", [Filename]), case file:read_file(Filename) of {ok, Data} -> - ComputedChecksum = binary_to_list(base64:encode(crypto:sha(Data))), + ComputedChecksum = binary_to_list(base64:encode(crypto:hash(sha, Data))), case ComputedChecksum of Checksum -> ok; _Else -> diff --git a/src/couch_replicator/test/couch_replicator_missing_stubs_tests.erl b/src/couch_replicator/test/couch_replicator_missing_stubs_tests.erl index 5243be5a8..6e23ba99c 100644 --- a/src/couch_replicator/test/couch_replicator_missing_stubs_tests.erl +++ b/src/couch_replicator/test/couch_replicator_missing_stubs_tests.erl @@ -153,7 +153,7 @@ db_fold_fun(FullDocInfo, {DbName, Times}) -> {ok, Db2} = couch_db:reopen(Db), NewDocVersion = Doc#doc{ revs = {Pos, [RevId]}, - body = {[{<<"value">>, base64:encode(crypto:rand_bytes(100))}]} + body = {[{<<"value">>, base64:encode(crypto:strong_rand_bytes(100))}]} }, {ok, NewRev} = couch_db:update_doc(Db2, NewDocVersion, []), NewRev diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl index 305283255..c71c99540 100644 --- a/src/couchdb/couch_httpd_auth.erl +++ b/src/couchdb/couch_httpd_auth.erl @@ -123,7 +123,7 @@ proxy_authentication_handler(Req) -> %% @deprecated proxy_authentification_handler(Req) -> proxy_authentication_handler(Req). - + proxy_auth_user(Req) -> XHeaderUserName = couch_config:get("couch_httpd_auth", "x_auth_username", "X-Auth-CouchDB-UserName"), @@ -145,7 +145,7 @@ proxy_auth_user(Req) -> nil -> Req#httpd{user_ctx=#user_ctx{name=?l2b(UserName), roles=Roles}}; Secret -> - ExpectedToken = couch_util:to_hex(crypto:sha_mac(Secret, UserName)), + ExpectedToken = couch_util:to_hex(crypto:hmac(sha, Secret, UserName)), case header_value(Req, XHeaderToken) of Token when Token == ExpectedToken -> Req#httpd{user_ctx=#user_ctx{name=?l2b(UserName), @@ -186,7 +186,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) -> UserProps -> UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<"">>), FullSecret = <<Secret/binary, UserSalt/binary>>, - ExpectedHash = crypto:sha_mac(FullSecret, User ++ ":" ++ TimeStr), + ExpectedHash = crypto:hmac(sha, FullSecret, User ++ ":" ++ TimeStr), Hash = ?l2b(HashStr), Timeout = list_to_integer( couch_config:get("couch_httpd_auth", "timeout", "600")), @@ -233,7 +233,7 @@ cookie_auth_header(_Req, _Headers) -> []. cookie_auth_cookie(Req, User, Secret, TimeStamp) -> SessionData = User ++ ":" ++ erlang:integer_to_list(TimeStamp, 16), - Hash = crypto:sha_mac(Secret, SessionData), + Hash = crypto:hmac(sha, Secret, SessionData), mochiweb_cookies:cookie("AuthSession", couch_util:encodeBase64Url(SessionData ++ ":" ++ ?b2l(Hash)), [{path, "/"}] ++ cookie_scheme(Req) ++ max_age()). diff --git a/src/couchdb/couch_passwords.erl b/src/couchdb/couch_passwords.erl index 9abf31b5c..321f89f78 100644 --- a/src/couchdb/couch_passwords.erl +++ b/src/couchdb/couch_passwords.erl @@ -23,7 +23,7 @@ %% legacy scheme, not used for new passwords. -spec simple(binary(), binary()) -> binary(). simple(Password, Salt) when is_binary(Password), is_binary(Salt) -> - ?l2b(couch_util:to_hex(crypto:sha(<<Password/binary, Salt/binary>>))). + ?l2b(couch_util:to_hex(crypto:hash(sha, <<Password/binary, Salt/binary>>))). %% CouchDB utility functions -spec hash_admin_password(binary() | list()) -> binary(). @@ -89,12 +89,12 @@ pbkdf2(_Password, _Salt, Iterations, _BlockIndex, Iteration, _Prev, Acc) when Iteration > Iterations -> Acc; pbkdf2(Password, Salt, Iterations, BlockIndex, 1, _Prev, _Acc) -> - InitialBlock = crypto:sha_mac(Password, + InitialBlock = crypto:hmac(sha, Password, <<Salt/binary,BlockIndex:32/integer>>), pbkdf2(Password, Salt, Iterations, BlockIndex, 2, InitialBlock, InitialBlock); pbkdf2(Password, Salt, Iterations, BlockIndex, Iteration, Prev, Acc) -> - Next = crypto:sha_mac(Password, Prev), + Next = crypto:hmac(sha, Password, Prev), pbkdf2(Password, Salt, Iterations, BlockIndex, Iteration + 1, Next, crypto:exor(Next, Acc)). diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 7cee0f5d6..3da4ecf33 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -128,7 +128,7 @@ is_admin(User, ClearPwd) -> case couch_config:get("admins", User) of "-hashed-" ++ HashedPwdAndSalt -> [HashedPwd, Salt] = string:tokens(HashedPwdAndSalt, ","), - couch_util:to_hex(crypto:sha(ClearPwd ++ Salt)) == HashedPwd; + couch_util:to_hex(crypto:hash(sha, ClearPwd ++ Salt)) == HashedPwd; _Else -> false end. diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index 00530848a..e2f103fb0 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -209,7 +209,7 @@ json_user_ctx(#db{name=DbName, user_ctx=Ctx}) -> % returns a random integer rand32() -> - crypto:rand_uniform(0, 16#100000000). + crypto:strong_rand_bytes(4). % given a pathname "../foo/bar/" it gives back the fully qualified % absolute pathname. @@ -415,20 +415,20 @@ verify(_X, _Y) -> false. -spec md5(Data::(iolist() | binary())) -> Digest::binary(). md5(Data) -> - try crypto:md5(Data) catch error:_ -> erlang:md5(Data) end. + try crypto:hash(md5, Data) catch error:_ -> erlang:md5(Data) end. -spec md5_init() -> Context::binary(). md5_init() -> - try crypto:md5_init() catch error:_ -> erlang:md5_init() end. + try crypto:hash_init(md5) catch error:_ -> erlang:md5_init() end. -spec md5_update(Context::binary(), Data::(iolist() | binary())) -> NewContext::binary(). md5_update(Ctx, D) -> - try crypto:md5_update(Ctx,D) catch error:_ -> erlang:md5_update(Ctx,D) end. + try crypto:hash_update(Ctx,D) catch error:_ -> erlang:md5_update(Ctx,D) end. -spec md5_final(Context::binary()) -> Digest::binary(). md5_final(Ctx) -> - try crypto:md5_final(Ctx) catch error:_ -> erlang:md5_final(Ctx) end. + try crypto:hash_final(Ctx) catch error:_ -> erlang:md5_final(Ctx) end. % linear search is faster for small lists, length() is 0.5 ms for 100k list reorder_results(Keys, SortedResults) when length(Keys) < 100 -> diff --git a/src/couchdb/couch_uuids.erl b/src/couchdb/couch_uuids.erl index 6ed75a1f4..581aba97a 100644 --- a/src/couchdb/couch_uuids.erl +++ b/src/couchdb/couch_uuids.erl @@ -30,10 +30,10 @@ new() -> gen_server:call(?MODULE, create). random() -> - list_to_binary(couch_util:to_hex(crypto:rand_bytes(16))). + list_to_binary(couch_util:to_hex(crypto:strong_rand_bytes(16))). utc_random() -> - utc_suffix(couch_util:to_hex(crypto:rand_bytes(9))). + utc_suffix(couch_util:to_hex(crypto:strong_rand_bytes(9))). utc_suffix(Suffix) -> Now = {_, _, Micro} = now(), @@ -81,7 +81,7 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}. new_prefix() -> - couch_util:to_hex((crypto:rand_bytes(13))). + couch_util:to_hex((crypto:strong_rand_bytes(13))). inc() -> crypto:rand_uniform(1, 16#ffe). diff --git a/src/erlang-oauth/oauth.erl b/src/erlang-oauth/oauth.erl index e75d5fd78..d37f715cd 100644 --- a/src/erlang-oauth/oauth.erl +++ b/src/erlang-oauth/oauth.erl @@ -77,7 +77,7 @@ signature_params(Consumer, Params, Token) -> signature_params(Consumer, Params) -> Timestamp = unix_timestamp(), - Nonce = base64:encode_to_string(crypto:rand_bytes(32)), % cf. ruby-oauth + Nonce = base64:encode_to_string(crypto:strong_rand_bytes(32)), % cf. ruby-oauth [ {"oauth_version", "1.0"} , {"oauth_nonce", Nonce} , {"oauth_timestamp", integer_to_list(Timestamp)} @@ -128,7 +128,7 @@ hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret) -> hmac_sha1_signature(BaseString, Consumer, TokenSecret) -> Key = uri_join([consumer_secret(Consumer), TokenSecret]), - base64:encode_to_string(crypto:sha_mac(Key, BaseString)). + base64:encode_to_string(crypto:hmac(sha, Key, BaseString)). hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) -> verify_in_constant_time(Signature, hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret)). diff --git a/src/mochiweb/mochiweb_multipart.erl b/src/mochiweb/mochiweb_multipart.erl index a83a88c98..85dc61376 100644 --- a/src/mochiweb/mochiweb_multipart.erl +++ b/src/mochiweb/mochiweb_multipart.erl @@ -38,7 +38,7 @@ parts_to_body([{Start, End, Body}], ContentType, Size) -> {HeaderList, Body}; parts_to_body(BodyList, ContentType, Size) when is_list(BodyList) -> parts_to_multipart_body(BodyList, ContentType, Size, - mochihex:to_hex(crypto:rand_bytes(8))). + mochihex:to_hex(crypto:strong_rand_bytes(8))). %% @spec parts_to_multipart_body([bodypart()], ContentType::string(), %% Size::integer(), Boundary::string()) -> diff --git a/src/my-first-couchdb-plugin/Makefile b/src/my-first-couchdb-plugin/Makefile index 7806bd7b4..6c0e1e6b4 100644 --- a/src/my-first-couchdb-plugin/Makefile +++ b/src/my-first-couchdb-plugin/Makefile @@ -35,4 +35,4 @@ plugin: compile @mkdir -p $(PLUGIN_DIST) @cp -r $(PLUGIN_DIRS) $(PLUGIN_DIST) @tar czf $(PLUGIN_VERSION_SLUG).tar.gz $(PLUGIN_DIST) - @$(ERL) -eval 'File = "$(PLUGIN_VERSION_SLUG).tar.gz", {ok, Data} = file:read_file(File),io:format("~s: ~s~n", [File, base64:encode(crypto:sha(Data))]),halt()' -noshell + @$(ERL) -eval 'File = "$(PLUGIN_VERSION_SLUG).tar.gz", {ok, Data} = file:read_file(File),io:format("~s: ~s~n", [File, base64:encode(crypto:hash(sha, Data))]),halt()' -noshell diff --git a/test/couchdb/couch_auth_cache_tests.erl b/test/couchdb/couch_auth_cache_tests.erl index 3b2321caa..df00bfc58 100644 --- a/test/couchdb/couch_auth_cache_tests.erl +++ b/test/couchdb/couch_auth_cache_tests.erl @@ -189,7 +189,7 @@ update_user_doc(DbName, UserName, Password, Rev) -> {ok, couch_doc:rev_to_str(NewRev)}. hash_password(Password) -> - ?l2b(couch_util:to_hex(crypto:sha(iolist_to_binary([Password, ?SALT])))). + ?l2b(couch_util:to_hex(crypto:hash(sha, iolist_to_binary([Password, ?SALT])))). shutdown_db(DbName) -> {ok, AuthDb} = couch_db:open_int(DbName, [?ADMIN_USER]), diff --git a/test/couchdb/couch_btree_tests.erl b/test/couchdb/couch_btree_tests.erl index 911640f2d..6a94d41fb 100644 --- a/test/couchdb/couch_btree_tests.erl +++ b/test/couchdb/couch_btree_tests.erl @@ -82,7 +82,7 @@ btree_open_test_() -> sorted_kvs_test_() -> Funs = kvs_test_funs(), - Sorted = [{Seq, random:uniform()} || Seq <- lists:seq(1, ?ROWS)], + Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)], { "BTree with sorted keys", { @@ -93,7 +93,7 @@ sorted_kvs_test_() -> }. rsorted_kvs_test_() -> - Sorted = [{Seq, random:uniform()} || Seq <- lists:seq(1, ?ROWS)], + Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)], Funs = kvs_test_funs(), Reversed = Sorted, { @@ -107,7 +107,7 @@ rsorted_kvs_test_() -> shuffled_kvs_test_() -> Funs = kvs_test_funs(), - Sorted = [{Seq, random:uniform()} || Seq <- lists:seq(1, ?ROWS)], + Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)], Shuffled = shuffle(Sorted), { "BTree with shuffled keys", @@ -463,7 +463,7 @@ randomize(T, List) -> end, randomize(List), lists:seq(1, (T - 1))). randomize(List) -> - D = lists:map(fun(A) -> {random:uniform(), A} end, List), + D = lists:map(fun(A) -> {couch_rand:uniform(), A} end, List), {_, D1} = lists:unzip(lists:keysort(1, D)), D1. diff --git a/test/couchdb/couch_file_tests.erl b/test/couchdb/couch_file_tests.erl index ad1338391..5ef13c9d6 100644 --- a/test/couchdb/couch_file_tests.erl +++ b/test/couchdb/couch_file_tests.erl @@ -253,13 +253,13 @@ check_header_recovery(CheckFun) -> ok. write_random_data(Fd) -> - write_random_data(Fd, 100 + random:uniform(1000)). + write_random_data(Fd, 100 + couch_rand:uniform(1000)). write_random_data(Fd, 0) -> {ok, Bytes} = couch_file:bytes(Fd), {ok, (1 + Bytes div ?BLOCK_SIZE) * ?BLOCK_SIZE}; write_random_data(Fd, N) -> Choices = [foo, bar, <<"bizzingle">>, "bank", ["rough", stuff]], - Term = lists:nth(random:uniform(4) + 1, Choices), + Term = lists:nth(couch_rand:uniform(4) + 1, Choices), {ok, _, _} = couch_file:append_term(Fd, Term), write_random_data(Fd, N - 1). diff --git a/test/couchdb/couchdb_views_tests.erl b/test/couchdb/couchdb_views_tests.erl index 6904f00ba..316029b0d 100644 --- a/test/couchdb/couchdb_views_tests.erl +++ b/test/couchdb/couchdb_views_tests.erl @@ -429,7 +429,7 @@ populate_db(Db, BatchSize, N) when N > 0 -> fun(_) -> couch_doc:from_json_obj({[ {<<"_id">>, couch_uuids:new()}, - {<<"value">>, base64:encode(crypto:rand_bytes(1000))} + {<<"value">>, base64:encode(crypto:strong_rand_bytes(1000))} ]}) end, lists:seq(1, BatchSize)), |