You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/06/20 17:43:47 UTC
couch commit: updated refs/heads/fix-deprecations to 103e756
Repository: couchdb-couch
Updated Branches:
refs/heads/fix-deprecations [created] 103e75683
fix deprecations
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/103e7568
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/103e7568
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/103e7568
Branch: refs/heads/fix-deprecations
Commit: 103e7568384a50cd44dad2a26f6029005fdd0eb1
Parents: 04312dc
Author: Robert Newson <rn...@apache.org>
Authored: Sat Jun 20 16:43:35 2015 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Sat Jun 20 16:43:35 2015 +0100
----------------------------------------------------------------------
src/couch_hotp.erl | 12 +-----------
src/couch_httpd_auth.erl | 6 +++---
src/couch_passwords.erl | 6 +++---
src/couch_server.erl | 2 +-
src/couch_util.erl | 8 ++++----
5 files changed, 12 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/103e7568/src/couch_hotp.erl
----------------------------------------------------------------------
diff --git a/src/couch_hotp.erl b/src/couch_hotp.erl
index 896c52a..9a620fa 100644
--- a/src/couch_hotp.erl
+++ b/src/couch_hotp.erl
@@ -16,7 +16,7 @@
generate(Alg, Key, Counter, OutputLen)
when is_atom(Alg), is_binary(Key), is_integer(Counter), is_integer(OutputLen) ->
- Hmac = hmac(Alg, Key, <<Counter:64>>),
+ Hmac = crypto:hmac(Alg, Key, <<Counter:64>>),
Offset = binary:last(Hmac) band 16#f,
Code =
((binary:at(Hmac, Offset) band 16#7f) bsl 24) +
@@ -28,13 +28,3 @@ generate(Alg, Key, Counter, OutputLen)
7 -> Code rem 10000000;
8 -> Code rem 100000000
end.
-
-hmac(Alg, Key, Data) ->
- case {Alg, erlang:function_exported(crypto, hmac, 3)} of
- {_, true} ->
- crypto:hmac(Alg, Key, Data);
- {sha, false} ->
- crypto:sha_mac(Key, Data);
- {Alg, false} ->
- throw({unsupported, Alg})
- end.
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/103e7568/src/couch_httpd_auth.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_auth.erl b/src/couch_httpd_auth.erl
index 01453d8..cacf3bf 100644
--- a/src/couch_httpd_auth.erl
+++ b/src/couch_httpd_auth.erl
@@ -162,7 +162,7 @@ proxy_auth_user(Req) ->
undefined ->
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),
@@ -206,7 +206,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req, AuthModule) ->
{ok, UserProps, _AuthCtx} ->
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(
config:get("couch_httpd_auth", "timeout", "600")),
@@ -254,7 +254,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()).
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/103e7568/src/couch_passwords.erl
----------------------------------------------------------------------
diff --git a/src/couch_passwords.erl b/src/couch_passwords.erl
index 2ab7cc3..31a58ae 100644
--- a/src/couch_passwords.erl
+++ b/src/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)).
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/103e7568/src/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_server.erl b/src/couch_server.erl
index 6c718ce..562677d 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -157,7 +157,7 @@ is_admin(User, ClearPwd) ->
case 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.
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/103e7568/src/couch_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_util.erl b/src/couch_util.erl
index 742ab70..4e105bd 100644
--- a/src/couch_util.erl
+++ b/src/couch_util.erl
@@ -404,20 +404,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(md5,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(md5,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 ->