@@ -75,7 +75,9 @@ groups() ->
75
75
{tls , [parallel ], auth_bind_pipelined_cases () ++
76
76
protocol_test_cases () ++
77
77
cipher_test_cases ()},
78
- {just_tls , tls_groups ()},
78
+ {verify_peer , [], [verify_peer_disconnects_when_client_has_no_cert ,
79
+ verify_peer_ignores_when_client_has_no_cert ]},
80
+ {just_tls , [{group , verify_peer } | tls_groups ()]},
79
81
{fast_tls , tls_groups ()},
80
82
{session_replacement , [], [same_resource_replaces_session ,
81
83
clean_close_of_replaced_session ,
@@ -207,6 +209,10 @@ end_per_testcase(replaced_session_cannot_terminate_different_nodes = CaseName, C
207
209
distributed_helper :remove_node_from_cluster (mim2 (), Config ),
208
210
mongoose_helper :restore_config (Config ),
209
211
escalus :end_per_testcase (CaseName , Config );
212
+ end_per_testcase (verify_peer_disconnects_when_client_has_no_cert , Config ) ->
213
+ mongoose_helper :restore_config (Config ),
214
+ catch escalus_event :stop (Config ),
215
+ catch escalus_cleaner :stop (Config );
210
216
end_per_testcase (CaseName , Config ) ->
211
217
mongoose_helper :restore_config (Config ),
212
218
escalus :end_per_testcase (CaseName , Config ).
@@ -215,6 +221,46 @@ end_per_testcase(CaseName, Config) ->
215
221
% % Tests
216
222
% %--------------------------------------------------------------------
217
223
224
+ verify_peer_disconnects_when_client_has_no_cert (Config ) ->
225
+ % % Server disconnects only when `disconnect_on_failure` is set to `true`.
226
+ % % It is true by default, so we make sure `disconnect_on_failure` is not in config.
227
+ % % `verify_mode` needs to be set to `peer`.
228
+ ServerTLSOpts0 = tls_opts (starttls_required , Config ),
229
+ ServerTLSOpts = maps :remove (disconnect_on_failure , ServerTLSOpts0 #{verify_mode => peer }),
230
+ configure_c2s_listener (Config , #{tls => ServerTLSOpts }),
231
+ process_flag (trap_exit , true ),
232
+ UserSpec0 = escalus_users :get_userspec (Config , ? SECURE_USER ),
233
+ UserSpec = [{ssl_opts , [{verify , verify_none }]}|UserSpec0 ],
234
+ try
235
+ escalus_connection :start (UserSpec ) of
236
+ {error , {connection_step_failed , {{escalus_session , maybe_use_ssl }, _ , _ }, _ }} ->
237
+ ok ;
238
+ _Result ->
239
+ error ({client_connected , Config })
240
+ catch
241
+ C :E ->
242
+ error ({C , E , Config })
243
+ end .
244
+
245
+ verify_peer_ignores_when_client_has_no_cert (Config ) ->
246
+ % % Server bypasses TLS client cert verification when `disconnect_on_failure` is set to `false`.
247
+ ServerTLSOpts0 = tls_opts (starttls_required , Config ),
248
+ ServerTLSOpts = ServerTLSOpts0 #{disconnect_on_failure => false },
249
+ configure_c2s_listener (Config , #{tls => ServerTLSOpts }),
250
+ process_flag (trap_exit , true ),
251
+ UserSpec0 = escalus_users :get_userspec (Config , ? SECURE_USER ),
252
+ UserSpec = [{ssl_opts , [{verify , verify_none }]}|UserSpec0 ],
253
+ try
254
+ escalus_connection :start (UserSpec ) of
255
+ {ok , _ , _ } ->
256
+ ok ;
257
+ Other ->
258
+ error ({client_disconnected , Config , Other })
259
+ catch
260
+ C :E ->
261
+ error ({C , E , Config })
262
+ end .
263
+
218
264
bad_xml (Config ) ->
219
265
% % given
220
266
Spec = escalus_users :get_userspec (Config , alice ),
@@ -709,7 +755,8 @@ configure_c2s_listener(Config, ExtraC2SOpts, RemovedC2SKeys) ->
709
755
mongoose_helper :restart_listener (mim (), NewC2SListener ).
710
756
711
757
tls_opts (Mode , Config ) ->
712
- ExtraOpts = #{mode => Mode , cacertfile => ? CACERT_FILE , certfile => ? CERT_FILE , dhfile => ? DH_FILE },
758
+ ExtraOpts = #{mode => Mode , verify_mode => none ,
759
+ cacertfile => ? CACERT_FILE , certfile => ? CERT_FILE , dhfile => ? DH_FILE },
713
760
Module = proplists :get_value (tls_module , Config , fast_tls ),
714
761
maps :merge (default_c2s_tls (Module ), ExtraOpts ).
715
762
0 commit comments