Skip to content

Commit

Permalink
Merge remote branch 'upstream/maint'
Browse files Browse the repository at this point in the history
  • Loading branch information
IngelaAndin committed Mar 6, 2013
2 parents 986ae53 + 5086c3e commit e67eaba
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 21 deletions.
9 changes: 8 additions & 1 deletion lib/ssl/src/ssl.erl
Expand Up @@ -612,8 +612,15 @@ handle_options(Opts0, _Role) ->

CertFile = handle_option(certfile, Opts, <<>>),

Versions = case handle_option(versions, Opts, []) of
[] ->
ssl_record:supported_protocol_versions();
Vsns ->
[ssl_record:protocol_version(Vsn) || Vsn <- Vsns]
end,

SSLOptions = #ssl_options{
versions = handle_option(versions, Opts, []),
versions = Versions,
verify = validate_option(verify, Verify),
verify_fun = VerifyFun,
fail_if_no_peer_cert = FailIfNoPeerCert,
Expand Down
4 changes: 1 addition & 3 deletions lib/ssl/src/ssl_connection.erl
Expand Up @@ -73,7 +73,6 @@
session_cache, %
session_cache_cb, %
negotiated_version, % tls_version()
supported_protocol_versions, % [atom()]
client_certificate_requested = false,
key_algorithm, % atom as defined by cipher_suite
hashsign_algorithm, % atom as defined by cipher_suite
Expand Down Expand Up @@ -659,8 +658,7 @@ cipher(#certificate_verify{signature = Signature, hashsign_algorithm = CertHashS
% client must send a next protocol message if we are expecting it
cipher(#finished{}, #state{role = server, expecting_next_protocol_negotiation = true,
next_protocol = undefined, negotiated_version = Version} = State0) ->
handle_own_alert(?ALERT_REC(?FATAL,?UNEXPECTED_MESSAGE), Version, cipher, State0),
{stop, normal, State0};
handle_own_alert(?ALERT_REC(?FATAL,?UNEXPECTED_MESSAGE), Version, cipher, State0);

cipher(#finished{verify_data = Data} = Finished,
#state{negotiated_version = Version,
Expand Down
21 changes: 7 additions & 14 deletions lib/ssl/src/ssl_handshake.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2007-2012. All Rights Reserved.
%% Copyright Ericsson AB 2007-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
Expand Down Expand Up @@ -61,11 +61,7 @@ client_hello(Host, Port, ConnectionStates,
ciphers = UserSuites
} = SslOpts,
Cache, CacheCb, Renegotiation, OwnCert) ->

Fun = fun(Version) ->
ssl_record:protocol_version(Version)
end,
Version = ssl_record:highest_protocol_version(lists:map(Fun, Versions)),
Version = ssl_record:highest_protocol_version(Versions),
Pending = ssl_record:pending_connection_state(ConnectionStates, read),
SecParams = Pending#connection_state.security_parameters,
Ciphers = available_suites(UserSuites, Version),
Expand Down Expand Up @@ -139,10 +135,11 @@ hello(#server_hello{cipher_suite = CipherSuite, server_version = Version,
compression_method = Compression, random = Random,
session_id = SessionId, renegotiation_info = Info,
hash_signs = _HashSigns} = Hello,
#ssl_options{secure_renegotiate = SecureRenegotation, next_protocol_selector = NextProtocolSelector},
#ssl_options{secure_renegotiate = SecureRenegotation, next_protocol_selector = NextProtocolSelector,
versions = SupportedVersions},
ConnectionStates0, Renegotiation) ->
%%TODO: select hash and signature algorigthm
case ssl_record:is_acceptable_version(Version) of
case ssl_record:is_acceptable_version(Version, SupportedVersions) of
true ->
case handle_renegotiation_info(client, Info, ConnectionStates0,
Renegotiation, SecureRenegotation, []) of
Expand Down Expand Up @@ -171,7 +168,7 @@ hello(#client_hello{client_version = ClientVersion, random = Random,
{Port, Session0, Cache, CacheCb, ConnectionStates0, Cert}, Renegotiation) ->
%% TODO: select hash and signature algorithm
Version = select_version(ClientVersion, Versions),
case ssl_record:is_acceptable_version(Version) of
case ssl_record:is_acceptable_version(Version, Versions) of
true ->
{Type, #session{cipher_suite = CipherSuite,
compression_method = Compression} = Session}
Expand Down Expand Up @@ -869,11 +866,7 @@ hello_security_parameters(server, Version, ConnectionState, CipherSuite, Random,
}.

select_version(ClientVersion, Versions) ->
Fun = fun(Version) ->
ssl_record:protocol_version(Version)
end,
ServerVersion = ssl_record:highest_protocol_version(lists:map(Fun,
Versions)),
ServerVersion = ssl_record:highest_protocol_version(Versions),
ssl_record:lowest_protocol_version(ClientVersion, ServerVersion).

select_cipher_suite([], _) ->
Expand Down
12 changes: 10 additions & 2 deletions lib/ssl/src/ssl_record.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2007-2012. All Rights Reserved.
%% Copyright Ericsson AB 2007-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
Expand Down Expand Up @@ -56,7 +56,7 @@
%% Misc.
-export([protocol_version/1, lowest_protocol_version/2,
highest_protocol_version/1, supported_protocol_versions/0,
is_acceptable_version/1]).
is_acceptable_version/1, is_acceptable_version/2]).

-export([compressions/0]).

Expand Down Expand Up @@ -475,15 +475,23 @@ supported_protocol_versions([_|_] = Vsns) ->

%%--------------------------------------------------------------------
-spec is_acceptable_version(tls_version()) -> boolean().
-spec is_acceptable_version(tls_version(), Supported :: [tls_version()]) -> boolean().
%%
%% Description: ssl version 2 is not acceptable security risks are too big.
%%
%%--------------------------------------------------------------------
is_acceptable_version({N,_})
when N >= ?LOWEST_MAJOR_SUPPORTED_VERSION ->
true;
is_acceptable_version(_) ->
false.

is_acceptable_version({N,_} = Version, Versions)
when N >= ?LOWEST_MAJOR_SUPPORTED_VERSION ->
lists:member(Version, Versions);
is_acceptable_version(_,_) ->
false.

%%--------------------------------------------------------------------
-spec compressions() -> [binary()].
%%
Expand Down
39 changes: 38 additions & 1 deletion lib/ssl/test/ssl_basic_SUITE.erl
Expand Up @@ -126,7 +126,8 @@ api_tests() ->
hibernate,
listen_socket,
ssl_accept_timeout,
ssl_recv_timeout
ssl_recv_timeout,
versions_option
].

session_tests() ->
Expand Down Expand Up @@ -2659,6 +2660,42 @@ session_cache_process_mnesia(Config) when is_list(Config) ->
session_cache_process(mnesia,Config).

%%--------------------------------------------------------------------

versions_option() ->
[{doc,"Test API versions option to connect/listen."}].
versions_option(Config) when is_list(Config) ->
ClientOpts = ?config(client_opts, Config),
ServerOpts = ?config(server_opts, Config),

Supported = proplists:get_value(supported, ssl:versions()),
Available = proplists:get_value(available, ssl:versions()),
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0},
{from, self()},
{mfa, {ssl_test_lib, send_recv_result_active, []}},
{options, [{versions, Supported} | ServerOpts]}]),
Port = ssl_test_lib:inet_port(Server),

Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
{host, Hostname},
{from, self()},
{mfa, {ssl_test_lib, send_recv_result_active, []}},
{options, ClientOpts}]),

ssl_test_lib:check_result(Server, ok, Client, ok),
Server ! listen,

ErrClient = ssl_test_lib:start_client_error([{node, ClientNode}, {port, Port},
{host, Hostname},
{from, self()},
{options, [{versions , Available -- Supported} | ClientOpts]}]),
receive
{Server, _} ->
ok
end,

ssl_test_lib:check_result(ErrClient, {error, {tls_alert, "protocol version"}}).
%%--------------------------------------------------------------------
%% Internal functions ------------------------------------------------
%%--------------------------------------------------------------------
send_recv_result(Socket) ->
Expand Down

0 comments on commit e67eaba

Please sign in to comment.