@@ -26,18 +26,18 @@ impl MssqlConnection {
2626
2727 log:: debug!( "Sending T-SQL PRELOGIN with encryption: {:?}" , encryption) ;
2828
29- stream. write_packet (
30- PacketType :: PreLogin ,
31- PreLogin {
32- version : Version :: default ( ) ,
33- encryption ,
34- instance : options . instance . clone ( ) ,
35-
36- .. Default :: default ( )
37- } ,
38- ) ;
39-
40- stream . flush ( ) . await ?;
29+ stream
30+ . write_packet_and_flush (
31+ PacketType :: PreLogin ,
32+ PreLogin {
33+ version : Version :: default ( ) ,
34+ encryption ,
35+ instance : options . instance . clone ( ) ,
36+
37+ .. Default :: default ( )
38+ } ,
39+ )
40+ . await ?;
4141
4242 let ( _, packet) = stream. recv_packet ( ) . await ?;
4343 let prelogin_response = PreLogin :: decode ( packet) ?;
@@ -47,31 +47,36 @@ impl MssqlConnection {
4747 Encrypt :: Required | Encrypt :: On
4848 ) {
4949 stream. setup_encryption ( ) . await ?;
50+ } else if encryption == Encrypt :: Required {
51+ return Err ( Error :: Tls ( Box :: new ( std:: io:: Error :: new (
52+ std:: io:: ErrorKind :: Other ,
53+ "TLS encryption required but not supported by server" ,
54+ ) ) ) ) ;
5055 }
5156
5257 // LOGIN7 defines the authentication rules for use between client and server
5358
54- stream. write_packet (
55- PacketType :: Tds7Login ,
56- Login7 {
57- // FIXME: use a version constant
58- version : 0x74000004 , // SQL Server 2012 - SQL Server 2019
59- client_program_version : options . client_program_version ,
60- client_pid : options. client_pid ,
61- packet_size : options . requested_packet_size , // max allowed size of TDS packet
62- hostname : & options. hostname ,
63- username : & options. username ,
64- password : options. password . as_deref ( ) . unwrap_or_default ( ) ,
65- app_name : & options. app_name ,
66- server_name : & options. server_name ,
67- client_interface_name : & options. client_interface_name ,
68- language : & options. language ,
69- database : & * options. database ,
70- client_id : [ 0 ; 6 ] ,
71- } ,
72- ) ;
73-
74- stream . flush ( ) . await ?;
59+ stream
60+ . write_packet_and_flush (
61+ PacketType :: Tds7Login ,
62+ Login7 {
63+ // FIXME: use a version constant
64+ version : 0x74000004 , // SQL Server 2012 - SQL Server 2019
65+ client_program_version : options. client_program_version ,
66+ client_pid : options . client_pid ,
67+ packet_size : options. requested_packet_size , // max allowed size of TDS packet
68+ hostname : & options. hostname ,
69+ username : & options. username ,
70+ password : options. password . as_deref ( ) . unwrap_or_default ( ) ,
71+ app_name : & options. app_name ,
72+ server_name : & options. server_name ,
73+ client_interface_name : & options. client_interface_name ,
74+ language : & options. language ,
75+ database : & * options . database ,
76+ client_id : [ 0 ; 6 ] ,
77+ } ,
78+ )
79+ . await ?;
7580
7681 loop {
7782 // NOTE: we should receive an [Error] message if something goes wrong, otherwise,
0 commit comments