File 0219-ssl-Fix-whitespace-errors.patch of Package erlang
From b98fd42686e763c53f17bc57a8edfd59782fab05 Mon Sep 17 00:00:00 2001
From: Ingela Anderton Andin <ingela@erlang.org>
Date: Wed, 21 Jan 2026 16:52:23 +0100
Subject: [PATCH 1/2] ssl: Fix whitespace errors
---
lib/ssl/src/tls_server_session_ticket.erl | 96 +++++++++++------------
lib/ssl/src/tls_socket.erl | 93 +++++++++++-----------
2 files changed, 96 insertions(+), 93 deletions(-)
diff --git a/lib/ssl/src/tls_server_session_ticket.erl b/lib/ssl/src/tls_server_session_ticket.erl
index 3e8667b870..9a40c99766 100644
--- a/lib/ssl/src/tls_server_session_ticket.erl
+++ b/lib/ssl/src/tls_server_session_ticket.erl
@@ -21,7 +21,7 @@
%%
%%----------------------------------------------------------------------
-%% Purpose: Handle server side TLS-1.3 session ticket storage
+%% Purpose: Handle server side TLS-1.3 session ticket storage
%%----------------------------------------------------------------------
-module(tls_server_session_ticket).
@@ -80,14 +80,14 @@ new(Pid, Prf, MasterSecret, PeerCert) ->
gen_server:call(Pid, {new_session_ticket, Prf, MasterSecret, PeerCert}, infinity).
use(Pid, Identifiers, Prf, HandshakeHist) ->
- gen_server:call(Pid, {use_ticket, Identifiers, Prf, HandshakeHist},
+ gen_server:call(Pid, {use_ticket, Identifiers, Prf, HandshakeHist},
infinity).
%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
--spec init(Args :: term()) -> {ok, State :: term()}.
+-spec init(Args :: term()) -> {ok, State :: term()}.
init([Listener | Args]) ->
process_flag(trap_exit, true),
proc_lib:set_label({tls_13_server_session_tickets, Listener}),
@@ -98,41 +98,41 @@ init([Listener | Args]) ->
-spec handle_call(Request :: term(), From :: {pid(), term()}, State :: term()) ->
{reply, Reply :: term(), NewState :: term()} .
handle_call({new_session_ticket, Prf, MasterSecret, PeerCert}, _From,
- #state{nonce = Nonce,
+ #state{nonce = Nonce,
lifetime = LifeTime,
max_early_data_size = MaxEarlyDataSize,
- stateful = #{id_generator := IdGen}} = State0) ->
+ stateful = #{id_generator := IdGen}} = State0) ->
Id = stateful_psk_ticket_id(IdGen),
PSK = tls_v1:pre_shared_key(MasterSecret, ticket_nonce(Nonce), Prf),
SessionTicket = new_session_ticket(Id, Nonce, LifeTime, MaxEarlyDataSize),
State = stateful_ticket_store(Id, SessionTicket, Prf, PSK, PeerCert, State0),
{reply, SessionTicket, State};
handle_call({new_session_ticket, Prf, MasterSecret, PeerCert}, _From,
- #state{nonce = Nonce,
- stateless = #{}} = State) ->
+ #state{nonce = Nonce,
+ stateless = #{}} = State) ->
BaseSessionTicket = new_session_ticket_base(State),
- SessionTicket = generate_stateless_ticket(BaseSessionTicket, Prf,
+ SessionTicket = generate_stateless_ticket(BaseSessionTicket, Prf,
MasterSecret, PeerCert, State),
{reply, SessionTicket, State#state{nonce = Nonce+1}};
-handle_call({use_ticket, Identifiers, Prf, HandshakeHist}, _From,
- #state{stateful = #{}} = State0) ->
- {Result, State} = stateful_use(Identifiers, Prf,
+handle_call({use_ticket, Identifiers, Prf, HandshakeHist}, _From,
+ #state{stateful = #{}} = State0) ->
+ {Result, State} = stateful_use(Identifiers, Prf,
HandshakeHist, State0),
{reply, Result, State};
-handle_call({use_ticket, Identifiers, Prf, HandshakeHist}, _From,
- #state{stateless = #{}} = State0) ->
- {Result, State} = stateless_use(Identifiers, Prf,
+handle_call({use_ticket, Identifiers, Prf, HandshakeHist}, _From,
+ #state{stateless = #{}} = State0) ->
+ {Result, State} = stateless_use(Identifiers, Prf,
HandshakeHist, State0),
{reply, Result, State}.
-spec handle_cast(Request :: term(), State :: term()) ->
- {noreply, NewState :: term()}.
+ {noreply, NewState :: term()}.
handle_cast(_Request, State) ->
{noreply, State}.
-spec handle_info(Info :: timeout() | term(), State :: term()) ->
{noreply, NewState :: term()}.
-handle_info(rotate_bloom_filters,
+handle_info(rotate_bloom_filters,
#state{stateless = #{bloom_filter := BloomFilter0,
warm_up_windows_remaining := WarmUp0,
window := Window} = Stateless} = State) ->
@@ -191,7 +191,7 @@ initial_state([stateful, Lifetime, TicketStoreSize, MaxEarlyDataSize|_]) ->
#state{lifetime = Lifetime,
max_early_data_size = MaxEarlyDataSize,
nonce = 0,
- stateful = #{db => stateful_store(),
+ stateful = #{db => stateful_store(),
max => TicketStoreSize,
ref_index => #{},
id_generator => crypto:strong_rand_bytes(16)
@@ -241,18 +241,18 @@ validate_binder(Binder, HandshakeHist, PSK, Prf, AlertDetail) ->
end.
%%%===================================================================
-%%% Stateful store
+%%% Stateful store
%%%===================================================================
stateful_store() ->
gb_trees:empty().
stateful_ticket_store(Ref, NewSessionTicket, Hash, Psk, PeerCert,
- #state{nonce = Nonce,
- stateful = #{db := Tree0,
+ #state{nonce = Nonce,
+ stateful = #{db := Tree0,
max := Max,
- ref_index := Index0} = Stateful}
- = State0) ->
+ ref_index := Index0} = Stateful}
+ = State0) ->
Id = {erlang:monotonic_time(), erlang:unique_integer([monotonic])},
StatefulTicket = {NewSessionTicket, Hash, Psk, PeerCert},
case gb_trees:size(Tree0) of
@@ -262,46 +262,46 @@ stateful_ticket_store(Ref, NewSessionTicket, Hash, Psk, PeerCert,
= gb_trees:take_smallest(Tree0),
Tree = gb_trees:insert(Id, StatefulTicket, Tree1),
Index = maps:without([OldRef], Index0),
- State0#state{nonce = Nonce+1, stateful =
- Stateful#{db => Tree,
+ State0#state{nonce = Nonce+1, stateful =
+ Stateful#{db => Tree,
ref_index => Index#{Ref => Id}}};
_ ->
Tree = gb_trees:insert(Id, StatefulTicket, Tree0),
- State0#state{nonce = Nonce+1, stateful =
- Stateful#{db => Tree,
- ref_index => Index0#{Ref => Id}}}
+ State0#state{nonce = Nonce+1, stateful =
+ Stateful#{db => Tree,
+ ref_index => Index0#{Ref => Id}}}
end.
stateful_use(#offered_psks{
identities = Identities,
binders = Binders
- }, Prf, HandshakeHist, State) ->
+ }, Prf, HandshakeHist, State) ->
stateful_use(Identities, Binders, Prf, HandshakeHist, 0, State).
stateful_use([], [], _, _, _, State) ->
{{ok, undefined}, State};
-stateful_use([#psk_identity{identity = Ref} | Refs], [Binder | Binders],
- Prf, HandshakeHist, Index,
- #state{stateful = #{db := Tree0,
+stateful_use([#psk_identity{identity = Ref} | Refs], [Binder | Binders],
+ Prf, HandshakeHist, Index,
+ #state{stateful = #{db := Tree0,
ref_index := RefIndex0} = Stateful} = State) ->
try maps:get(Ref, RefIndex0) of
Key ->
- case stateful_usable_ticket(Key, Prf, Binder,
+ case stateful_usable_ticket(Key, Prf, Binder,
HandshakeHist, Tree0) of
true ->
RefIndex = maps:without([Ref], RefIndex0),
{{_,_, PSK, PeerCert}, Tree} = gb_trees:take(Key, Tree0),
{{ok, {Index, PSK, PeerCert}},
- State#state{stateful = Stateful#{db => Tree,
+ State#state{stateful = Stateful#{db => Tree,
ref_index => RefIndex}}};
false ->
- stateful_use(Refs, Binders, Prf,
+ stateful_use(Refs, Binders, Prf,
HandshakeHist, Index + 1, State);
{error, _} = Error ->
{Error, State}
end
catch
- _:{badkey, Ref} ->
+ _:{badkey, Ref} ->
stateful_use(Refs, Binders, Prf, HandshakeHist, Index + 1, State)
end.
@@ -314,13 +314,13 @@ stateful_usable_ticket(Key, Prf, Binder, HandshakeHist, Tree) ->
true ->
validate_binder(Binder, HandshakeHist, PSK, Prf, stateful);
_ ->
- false
+ false
end;
_ ->
false
end.
-stateful_living_ticket({TimeStamp,_},
+stateful_living_ticket({TimeStamp,_},
#new_session_ticket{ticket_lifetime = LifeTime}) ->
Now = erlang:monotonic_time(),
Lived = erlang:convert_time_unit(Now-TimeStamp, native, seconds),
@@ -336,11 +336,11 @@ stateful_psk_ticket_id(Key) ->
crypto:crypto_one_time(aes_128_ecb, Key, <<Unique:128>>, true).
%%%===================================================================
-%%% Stateless ticket
+%%% Stateless ticket
%%%===================================================================
-generate_stateless_ticket(#new_session_ticket{ticket_nonce = Nonce,
+generate_stateless_ticket(#new_session_ticket{ticket_nonce = Nonce,
ticket_age_add = TicketAgeAdd,
- ticket_lifetime = Lifetime}
+ ticket_lifetime = Lifetime}
= Ticket, Prf, MasterSecret, PeerCert,
#state{stateless = #{seed := {IV, Shard}}}) ->
PSK = tls_v1:pre_shared_key(MasterSecret, Nonce, Prf),
@@ -358,14 +358,14 @@ generate_stateless_ticket(#new_session_ticket{ticket_nonce = Nonce,
stateless_use(#offered_psks{
identities = Identities,
binders = Binders
- }, Prf, HandshakeHist, State) ->
+ }, Prf, HandshakeHist, State) ->
stateless_use(Identities, Binders, Prf, HandshakeHist, 0, State).
stateless_use([], [], _, _, _, State) ->
{{ok, undefined}, State};
stateless_use([#psk_identity{identity = Encrypted,
- obfuscated_ticket_age = ObfAge} | Ids],
- [Binder | Binders], Prf, HandshakeHist, Index,
+ obfuscated_ticket_age = ObfAge} | Ids],
+ [Binder | Binders], Prf, HandshakeHist, Index,
#state{stateless = #{seed := {IV, Shard},
window := Window}} = State) ->
case ssl_cipher:decrypt_ticket(Encrypted, Shard, IV) of
@@ -377,7 +377,7 @@ stateless_use([#psk_identity{identity = Encrypted,
true ->
stateless_anti_replay(Index, PSK, Binder, PeerCert, State);
false ->
- stateless_use(Ids, Binders, Prf, HandshakeHist,
+ stateless_use(Ids, Binders, Prf, HandshakeHist,
Index+1, State);
{error, _} = Error ->
{Error, State}
@@ -390,12 +390,12 @@ stateless_usable_ticket(#stateless_ticket{hash = Prf,
ticket_age_add = TicketAgeAdd,
lifetime = Lifetime,
timestamp = Timestamp,
- pre_shared_key = PSK}, ObfAge,
+ pre_shared_key = PSK}, ObfAge,
Binder, HandshakeHist, Window) ->
- case stateless_living_ticket(ObfAge, TicketAgeAdd, Lifetime,
+ case stateless_living_ticket(ObfAge, TicketAgeAdd, Lifetime,
Timestamp, Window) of
true ->
- validate_binder(Binder, HandshakeHist, PSK, Prf, stateless);
+ validate_binder(Binder, HandshakeHist, PSK, Prf, stateless);
false ->
false
end.
@@ -458,7 +458,7 @@ stateless_anti_replay(_Index, _PSK, _Binder, _PeerCert,
%% long as any portion of their recording window overlaps the startup time."
{{ok, undefined}, State};
stateless_anti_replay(Index, PSK, Binder, PeerCert,
- #state{stateless = #{bloom_filter := BloomFilter0}
+ #state{stateless = #{bloom_filter := BloomFilter0}
= Stateless} = State) ->
case tls_bloom_filter:contains(BloomFilter0, Binder) of
true ->
diff --git a/lib/ssl/src/tls_socket.erl b/lib/ssl/src/tls_socket.erl
index 27f8e1df14..67a0755135 100644
--- a/lib/ssl/src/tls_socket.erl
+++ b/lib/ssl/src/tls_socket.erl
@@ -29,16 +29,16 @@
-include("ssl_record.hrl").
-export([send/3, send/4,
- listen/3,
- accept/3,
+ listen/3,
+ accept/3,
socket/6,
- connect/4,
+ connect/4,
upgrade/4,
- setopts/3,
- getopts/3,
- getstat/3,
- peername/2,
- sockname/2,
+ setopts/3,
+ getopts/3,
+ getstat/3,
+ peername/2,
+ sockname/2,
port/2,
close/2,
monitor_socket/1]).
@@ -50,24 +50,24 @@
emulated_options/2,
internal_inet_values/1,
default_inet_values/1,
- init/1,
- start_link/3,
- terminate/2,
- inherit_tracker/3,
- emulated_socket_options/2,
- get_emulated_opts/1,
- set_emulated_opts/2,
- get_all_opts/1,
- handle_call/3,
+ init/1,
+ start_link/3,
+ terminate/2,
+ inherit_tracker/3,
+ emulated_socket_options/2,
+ get_emulated_opts/1,
+ set_emulated_opts/2,
+ get_all_opts/1,
+ handle_call/3,
handle_cast/2,
- handle_info/2,
+ handle_info/2,
code_change/3]).
-export([update_active_n/2]).
-record(state, {
emulated_opts,
- listen_monitor,
+ listen_monitor,
ssl_opts
}).
@@ -84,8 +84,8 @@ send(tls_socket_tcp, Socket, Data, Handle) ->
send(Transport, Socket, Data, _Handle) ->
Transport:send(Socket, Data).
-listen(Transport, Port, #config{transport_info = {Transport, _, _, _, _},
- inet_user = Options,
+listen(Transport, Port, #config{transport_info = {Transport, _, _, _, _},
+ inet_user = Options,
ssl = SslOpts, emulated = EmOpts} = Config) ->
case Transport:listen(Port, Options ++ internal_inet_values(Transport)) of
{ok, ListenSocket} ->
@@ -95,7 +95,8 @@ listen(Transport, Port, #config{transport_info = {Transport, _, _, _, _},
MaxEarlyDataSize = ssl_config:get_max_early_data_size(),
%% TLS-1.3 session handling
{ok, SessionHandler} =
- session_tickets_tracker(ListenSocket, LifeTime, TicketStoreSize, MaxEarlyDataSize, SslOpts),
+ session_tickets_tracker(ListenSocket, LifeTime,
+ TicketStoreSize, MaxEarlyDataSize, SslOpts),
%% PRE TLS-1.3 session handling
{ok, SessionIdHandle} = session_id_tracker(ListenSocket, SslOpts),
Trackers = [{option_tracker, Tracker}, {session_tickets_tracker, SessionHandler},
@@ -110,7 +111,7 @@ listen(Transport, Port, #config{transport_info = {Transport, _, _, _, _},
accept(ListenSocket, #config{transport_info = {Transport,_,_,_,_} = CbInfo,
ssl = SslOpts,
- trackers = Trackers}, Timeout) ->
+ trackers = Trackers}, Timeout) ->
case Transport:accept(ListenSocket, Timeout) of
{ok, Socket} ->
Tracker = proplists:get_value(option_tracker, Trackers),
@@ -171,14 +172,14 @@ socket([Receiver, Sender], Transport, Socket, ConnectionCb, Tab, Trackers) ->
tab = Tab,
listener_config = Trackers}.
-setopts(gen_tcp, Socket = #sslsocket{socket_handle = ListenSocket,
+setopts(gen_tcp, Socket = #sslsocket{socket_handle = ListenSocket,
listener_config = #config{trackers = Trackers}}, Options) ->
Tracker = proplists:get_value(option_tracker, Trackers),
{SockOpts, EmulatedOpts} = split_options(gen_tcp, Options),
ok = set_emulated_opts(Tracker, EmulatedOpts),
check_active_n(EmulatedOpts, Socket),
inet:setopts(ListenSocket, SockOpts);
-setopts(Transport, Socket = #sslsocket{socket_handle = ListenSocket,
+setopts(Transport, Socket = #sslsocket{socket_handle = ListenSocket,
listener_config = #config{transport_info = Info,
trackers = Trackers}}, Options) ->
Transport = element(1, Info),
@@ -187,7 +188,8 @@ setopts(Transport, Socket = #sslsocket{socket_handle = ListenSocket,
ok = set_emulated_opts(Tracker, EmulatedOpts),
check_active_n(EmulatedOpts, Socket),
Transport:setopts(ListenSocket, SockOpts);
-%%% Following clauses will not be called for emulated options, they are handled in the connection process
+%%% Following clauses will not be called for emulated options, they
+%%% are handled in the connection process
setopts(gen_tcp, Socket, Options) ->
inet:setopts(Socket, Options);
setopts(Transport, Socket, Options) ->
@@ -219,21 +221,22 @@ check_active_n(EmulatedOpts, Socket = #sslsocket{listener_config = #config{track
ok
end.
-getopts(gen_tcp, #sslsocket{socket_handle = ListenSocket,
+getopts(gen_tcp, #sslsocket{socket_handle = ListenSocket,
listener_config = #config{trackers = Trackers}}, Options) ->
Tracker = proplists:get_value(option_tracker, Trackers),
{SockOptNames, EmulatedOptNames} = split_options(gen_tcp, Options),
EmulatedOpts = get_emulated_opts(Tracker, EmulatedOptNames),
SocketOpts = get_socket_opts(ListenSocket, SockOptNames, inet),
- {ok, EmulatedOpts ++ SocketOpts};
-getopts(Transport, #sslsocket{socket_handle = ListenSocket,
+ {ok, EmulatedOpts ++ SocketOpts};
+getopts(Transport, #sslsocket{socket_handle = ListenSocket,
listener_config = #config{trackers = Trackers}}, Options) ->
Tracker = proplists:get_value(option_tracker, Trackers),
{SockOptNames, EmulatedOptNames} = split_options(Transport, Options),
EmulatedOpts = get_emulated_opts(Tracker, EmulatedOptNames),
SocketOpts = get_socket_opts(ListenSocket, SockOptNames, Transport),
- {ok, EmulatedOpts ++ SocketOpts};
-%%% Following clauses will not be called for emulated options, they are handled in the connection process
+ {ok, EmulatedOpts ++ SocketOpts};
+%%% Following clauses will not be called for emulated options, they
+%%% are handled in the connection process
getopts(gen_tcp, Socket, Options) ->
inet:getopts(Socket, Options);
getopts(Transport, Socket, Options) ->
@@ -331,12 +334,12 @@ session_id_tracker(ssl_unknown_listener, _) ->
ssl_upgrade_server_session_cache_sup:start_child(normal);
session_id_tracker(ListenSocket, _) ->
ssl_server_session_cache_sup:start_child(ListenSocket).
-
-get_emulated_opts(TrackerPid) ->
+
+get_emulated_opts(TrackerPid) ->
call(TrackerPid, get_emulated_opts).
-set_emulated_opts(TrackerPid, InetValues) ->
+set_emulated_opts(TrackerPid, InetValues) ->
call(TrackerPid, {set_emulated_opts, InetValues}).
-get_all_opts(TrackerPid) ->
+get_all_opts(TrackerPid) ->
call(TrackerPid, get_all_opts).
%%====================================================================
@@ -348,8 +351,8 @@ start_link(Port, SockOpts, SslOpts) ->
%%--------------------------------------------------------------------
-spec init(list()) -> {ok, #state{}}.
-%% Possible return values not used now.
-%% | {ok, #state{}, timeout()} | ignore | {stop, term()}.
+%% Possible return values not used now.
+%% | {ok, #state{}, timeout()} | ignore | {stop, term()}.
%%
%% Description: Initiates the server
%%--------------------------------------------------------------------
@@ -357,13 +360,13 @@ init([Listen, Opts, SslOpts]) ->
process_flag(trap_exit, true),
proc_lib:set_label({tls_listen_tracker, Listen}),
Monitor = monitor_socket(Listen),
- {ok, #state{emulated_opts = do_set_emulated_opts(Opts, []),
+ {ok, #state{emulated_opts = do_set_emulated_opts(Opts, []),
listen_monitor = Monitor,
ssl_opts = SslOpts}}.
%%--------------------------------------------------------------------
-spec handle_call(term(), gen_server:from(), #state{}) -> {reply, Reply::term(), #state{}}.
-%% Possible return values not used now.
+%% Possible return values not used now.
%% {reply, term(), #state{}, timeout()} |
%% {noreply, #state{}} |
%% {noreply, #state{}, timeout()} |
@@ -386,13 +389,13 @@ handle_call(get_all_opts, _From,
%%--------------------------------------------------------------------
-spec handle_cast(term(), #state{}) -> {noreply, #state{}}.
-%% Possible return values not used now.
+%% Possible return values not used now.
%% | {noreply, #state{}, timeout()} |
%% {stop, reason(), #state{}}.
%%
%% Description: Handling cast messages
%%--------------------------------------------------------------------
-handle_cast(_, State)->
+handle_cast(_, State)->
{noreply, State}.
%%--------------------------------------------------------------------
@@ -400,7 +403,7 @@ handle_cast(_, State)->
%% Possible return values not used now.
%% {noreply, #state{}}.
%% |{noreply, #state{}, timeout()} |
-%%
+%%
%%
%% Description: Handling all non call/cast messages
%%-------------------------------------------------------------------
@@ -410,7 +413,7 @@ handle_info({'DOWN', Monitor, _, _, _}, #state{listen_monitor = Monitor} = State
%%--------------------------------------------------------------------
-spec terminate(ssl:reason(), #state{}) -> ok.
-%%
+%%
%% Description: This function is called by a gen_server when it is about to
%% terminate. It should be the opposite of Module:init/1 and do any necessary
%% cleaning up. When it returns, the gen_server terminates with Reason.
@@ -420,7 +423,7 @@ terminate(_Reason, _State) ->
ok.
%%--------------------------------------------------------------------
--spec code_change(term(), #state{}, list()) -> {ok, #state{}}.
+-spec code_change(term(), #state{}, list()) -> {ok, #state{}}.
%%
%% Description: Convert process state when code is changed
%%--------------------------------------------------------------------
@@ -499,7 +502,7 @@ get_socket_opts(ListenSocket, SockOptNames, Cb) ->
{ok, Opts} = Cb:getopts(ListenSocket, SockOptNames),
Opts.
-get_emulated_opts(TrackerPid, EmOptNames) ->
+get_emulated_opts(TrackerPid, EmOptNames) ->
{ok, EmOpts} = get_emulated_opts(TrackerPid),
lists:map(fun(Name) -> {value, Value} = lists:keysearch(Name, 1, EmOpts),
Value end,
--
2.51.0