@@ -4946,3 +4946,54 @@ fn test_client_removes_tls12_session_if_server_sends_undecryptable_first_message
4946
4946
ClientStorageOp :: RemoveTls12Session ( _)
4947
4947
) ) ;
4948
4948
}
4949
+
4950
+ #[ test]
4951
+ fn test_complete_io_errors_if_close_notify_received_too_early ( ) {
4952
+ let mut server = ServerConnection :: new ( Arc :: new ( make_server_config ( KeyType :: Rsa ) ) ) . unwrap ( ) ;
4953
+ let client_hello_followed_by_close_notify_alert = b"\
4954
+ \x16 \x03 \x01 \x00 \xc8 \x01 \x00 \x00 \xc4 \x03 \x03 \xec \x12 \xdd \x17 \x64 \
4955
+ \xa4 \x39 \xfd \x7e \x8c \x85 \x46 \xb8 \x4d \x1e \xa0 \x6e \xb3 \xd7 \xa0 \x51 \
4956
+ \xf0 \x3c \xb8 \x17 \x47 \x0d \x4c \x54 \xc5 \xdf \x72 \x00 \x00 \x1c \xea \xea \
4957
+ \xc0 \x2b \xc0 \x2f \xc0 \x2c \xc0 \x30 \xcc \xa9 \xcc \xa8 \xc0 \x13 \xc0 \x14 \
4958
+ \x00 \x9c \x00 \x9d \x00 \x2f \x00 \x35 \x00 \x0a \x01 \x00 \x00 \x7f \xda \xda \
4959
+ \x00 \x00 \xff \x01 \x00 \x01 \x00 \x00 \x00 \x00 \x16 \x00 \x14 \x00 \x00 \x11 \
4960
+ \x77 \x77 \x77 \x2e \x77 \x69 \x6b \x69 \x70 \x65 \x64 \x69 \x61 \x2e \x6f \x72 \
4961
+ \x67 \x00 \x17 \x00 \x00 \x00 \x23 \x00 \x00 \x00 \x0d \x00 \x14 \x00 \x12 \x04 \
4962
+ \x03 \x08 \x04 \x04 \x01 \x05 \x03 \x08 \x05 \x05 \x01 \x08 \x06 \x06 \x01 \x02 \
4963
+ \x01 \x00 \x05 \x00 \x05 \x01 \x00 \x00 \x00 \x00 \x00 \x12 \x00 \x00 \x00 \x10 \
4964
+ \x00 \x0e \x00 \x0c \x02 \x68 \x32 \x08 \x68 \x74 \x74 \x70 \x2f \x31 \x2e \x31 \
4965
+ \x75 \x50 \x00 \x00 \x00 \x0b \x00 \x02 \x01 \x00 \x00 \x0a \x00 \x0a \x00 \x08 \
4966
+ \x1a \x1a \x00 \x1d \x00 \x17 \x00 \x18 \x1a \x1a \x00 \x01 \x00 \
4967
+ \x15 \x03 \x03 \x00 \x02 \x01 \x00 ";
4968
+
4969
+ let mut stream = FakeStream ( client_hello_followed_by_close_notify_alert) ;
4970
+ assert_eq ! (
4971
+ server
4972
+ . complete_io( & mut stream)
4973
+ . unwrap_err( )
4974
+ . kind( ) ,
4975
+ io:: ErrorKind :: UnexpectedEof
4976
+ ) ;
4977
+ }
4978
+
4979
+ struct FakeStream < ' a > ( & ' a [ u8 ] ) ;
4980
+
4981
+ impl < ' a > io:: Read for FakeStream < ' a > {
4982
+ fn read ( & mut self , b : & mut [ u8 ] ) -> io:: Result < usize > {
4983
+ let take = core:: cmp:: min ( b. len ( ) , self . 0 . len ( ) ) ;
4984
+ let ( taken, remain) = self . 0 . split_at ( take) ;
4985
+ b[ ..take] . copy_from_slice ( taken) ;
4986
+ self . 0 = remain;
4987
+ Ok ( take)
4988
+ }
4989
+ }
4990
+
4991
+ impl < ' a > io:: Write for FakeStream < ' a > {
4992
+ fn write ( & mut self , b : & [ u8 ] ) -> io:: Result < usize > {
4993
+ Ok ( b. len ( ) )
4994
+ }
4995
+
4996
+ fn flush ( & mut self ) -> io:: Result < ( ) > {
4997
+ Ok ( ( ) )
4998
+ }
4999
+ }
0 commit comments