Skip to content

Commit

Permalink
changes for R16B01
Browse files Browse the repository at this point in the history
In R16B01, crypto:sha/1 is deprecated in favor of crypto:hash/2, but the
latter is not available prior to R15B02. Change the configure script and
rebar support to look for crypto:hash/2 and use it if found, otherwise fall
back to crypto:sha/1.

Also in R16B01 the public_key application, used by some of the tests, now
requires the asn1 application to be started first. Change the tests to
accommodate that.
  • Loading branch information
vinoski committed Jun 20, 2013
1 parent 91d25e0 commit 98db40b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
10 changes: 9 additions & 1 deletion configure.in
Expand Up @@ -320,7 +320,7 @@ esac

AC_ARG_ENABLE(sendfile, AS_HELP_STRING([--disable-sendfile], [disables use of sendfile system call]),
[ test "$enableval" = no && HAVE_YAWS_SENDFILE=false ])
file_sendfile=`"${ERL}" -noshell -eval 'io:format("~p~n",[[erlang:function_exported(file, sendfile, 5)]]), erlang:halt().' | tail -1`
file_sendfile=`"${ERL}" -noshell -eval 'code:load_file(file), io:format("~p~n",[[erlang:function_exported(file,sendfile,5)]]), erlang:halt().' | tail -1`
if test "$file_sendfile" = true -a \
'(' $ERTS_MAJOR -gt 5 -o \
'(' $ERTS_MAJOR -eq 5 -a $ERTS_MINOR -gt 9 ')' -o \
Expand All @@ -330,6 +330,14 @@ if test "$file_sendfile" = true -a \
fi
AC_SUBST(HAVE_YAWS_SENDFILE)

HAVE_CRYPTO_HASH=false
crypto_hash=`"${ERL}" -noshell -eval 'code:load_file(crypto), io:format("~p~n",[[erlang:function_exported(crypto,hash,2)]]), erlang:halt().' | tail -1`
if test "$crypto_hash" = true; then
HAVE_CRYPTO_HASH=true
AC_MSG_NOTICE(found crypto:hash/2)
fi
AC_SUBST(HAVE_CRYPTO_HASH)

YTOP=`pwd`
AC_SUBST(YTOP)
AC_OUTPUT(include.mk)
Expand Down
1 change: 1 addition & 0 deletions include.mk.in
Expand Up @@ -26,6 +26,7 @@ EXTRAINCLUDE = @EXTRAINCLUDE@
ERLBINDIR = @ERLBINDIR@
HAVE_YAWS_SENDFILE = @HAVE_YAWS_SENDFILE@
BITS_SUPPORT = @BITS_SUPPORT@
HAVE_CRYPTO_HASH = @HAVE_CRYPTO_HASH@

ifdef debug
ERLC_FLAGS+=-Ddebug
Expand Down
37 changes: 27 additions & 10 deletions rebar.config.script
Expand Up @@ -5,15 +5,32 @@ SoapDeps = [{erlsom, ".*", {git, "git://github.com/willemdj/erlsom.git", {branch
{ibrowse, ".*", {git, "git://github.com/cmullaparthi/ibrowse.git"}, {branch, "master"}},
{xmlrpc, ".*", {git, "git://github.com/rwbr/exmlrpc.git", {branch, "master"}}}],

case os:getenv("YAWS_SOAP") of
false ->
CONFIG;
_ ->
case lists:keysearch(deps, 1, CONFIG) of
{value, {deps, Deps}} ->
NDeps = Deps ++ SoapDeps,
lists:keyreplace(deps, 1, CONFIG, {deps, NDeps});
Cfg0 = case os:getenv("YAWS_SOAP") of
false ->
CONFIG;
_ ->
case lists:keysearch(deps, 1, CONFIG) of
{value, {deps, Deps}} ->
NDeps = Deps ++ SoapDeps,
lists:keyreplace(deps, 1, CONFIG, {deps, NDeps});
false ->
CONFIG ++ [{deps, SoapDeps}]
end
end,
code:load_file(crypto),
case erlang:function_exported(crypto,hash,2) of
true ->
case lists:keysearch(erl_opts, 1, Cfg0) of
{value, {erl_opts, Opts}} ->
case lists:any(fun({d,'HAVE_CRYPTO_HASH'}) -> true; (_) -> false end, Opts) of
true ->
Cfg0;
false ->
lists:keyreplace(erl_opts,1,Cfg0,{erl_opts,Opts++[{d,'HAVE_CRYPTO_HASH'}]})
end;
false ->
CONFIG ++ [{deps, SoapDeps}]
end
Cfg0 ++ [{erl_opts,[{d,'HAVE_CRYPTO_HASH'}]}]
end;
false ->
Cfg0
end.
7 changes: 4 additions & 3 deletions src/Makefile
Expand Up @@ -82,9 +82,10 @@ yaws_generated.erl: yaws_generated.template ../vsn.mk
$(MAKE) IS_LOCAL_INSTALL=true gen_yaws_generated

yaws_configure.hrl: ../vsn.mk ../include.mk
if [ $(HAVE_YAWS_SENDFILE) = "true" ]; then \
echo "-define(HAVE_YAWS_SENDFILE, true)." > yaws_configure.hrl; \
else touch yaws_configure.hrl; fi
rm -f $@
[ $(HAVE_YAWS_SENDFILE) = true ] && echo '-define(HAVE_YAWS_SENDFILE, true).' > $@; \
[ $(HAVE_CRYPTO_HASH) = true ] && echo '-define(HAVE_CRYPTO_HASH, true).' >> $@; \
[ -f $@ ] || touch $@

mime_types.erl: ../priv/charset.def ../priv/mime.types \
../ebin/yaws_generated.$(EMULATOR) ../ebin/mime_type_c.$(EMULATOR)
Expand Down
9 changes: 8 additions & 1 deletion src/yaws_websockets.erl
Expand Up @@ -13,6 +13,7 @@

-include("../include/yaws.hrl").
-include("../include/yaws_api.hrl").
-include("yaws_configure.hrl").

-include_lib("kernel/include/file.hrl").

Expand Down Expand Up @@ -1246,7 +1247,13 @@ query_header(HeaderName, Headers) ->
query_header(Header, Headers, Default) ->
yaws_api:get_header(Headers, Header, Default).

-ifdef(HAVE_CRYPTO_HASH).
-define(CRYPTO_HASH(V), crypto:hash(sha,V)).
-else.
-define(CRYPTO_HASH(V), crypto:sha(V)).
-endif.

hash_nonce(Nonce) ->
Salted = Nonce ++ "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
HashBin = crypto:hash(sha, Salted),
HashBin = ?CRYPTO_HASH(Salted),
base64:encode_to_string(HashBin).
2 changes: 2 additions & 0 deletions test/t10/app_test.erl
Expand Up @@ -1627,6 +1627,7 @@ test_secure_websocket() ->
WSPath = "/websockets_example_endpoint.yaws",

ok = application:start(crypto),
ok = application:start(asn1),
ok = application:start(public_key),
ok = application:start(ssl),

Expand All @@ -1646,6 +1647,7 @@ test_secure_websocket() ->

ok = application:stop(ssl),
ok = application:stop(public_key),
ok = application:stop(asn1),
ok = application:stop(crypto),
ok.

Expand Down
2 changes: 2 additions & 0 deletions test/t2/app_test.erl
Expand Up @@ -829,6 +829,7 @@ test_sslaccept_timeout() ->
test_ssl_multipart_post() ->
io:format("ssl_multipart_post_test\n", []),
ok = application:start(crypto),
ok = application:start(asn1),
ok = application:start(public_key),
ok = application:start(ssl),
Boundary = "----------------------------3e9876546ecf\r\n",
Expand All @@ -844,6 +845,7 @@ test_ssl_multipart_post() ->
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Headers, post, Data, Options),
ok = application:stop(ssl),
ok = application:stop(public_key),
ok = application:stop(asn1),
ok = application:stop(crypto),
ok.

Expand Down

1 comment on commit 98db40b

@klacke
Copy link
Collaborator

@klacke klacke commented on 98db40b Jun 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh, that was a lot of stuff. Necessary though. This goes to show the cost of poorly defined APIs that later get changed.

Please sign in to comment.