@@ -186,16 +186,28 @@ impl TlsConnection {
186186 // try to decrypt it -- it will just return a SEC_E_DECRYPT_FAILURE code."
187187 let mut tls_packet_start = vec ! [ TLS_APPLICATION_DATA_CONTENT_TYPE ] ;
188188
189- let tls_version: u16 = connection
189+ let tls_version = connection
190190 . protocol_version ( )
191- . ok_or_else ( || Error :: new ( ErrorKind :: InternalError , "can not query negotiated TLS version" ) ) ?
192- . into ( ) ;
191+ . ok_or_else ( || Error :: new ( ErrorKind :: InternalError , "can not query negotiated TLS version" ) ) ?;
192+ let tls_version = u16:: from ( if tls_version == ProtocolVersion :: TLSv1_3 {
193+ // TLS 1.3 uses the same version number as TLS 1.2 in the record layer.
194+ ProtocolVersion :: TLSv1_2
195+ } else {
196+ tls_version
197+ } ) ;
193198
194199 tls_packet_start. extend_from_slice ( & tls_version. to_be_bytes ( ) ) ;
195200
196201 // Safe: payload length is checked above.
197202 if payload[ 0 ..1 /* ContentType */ + 2 /* ProtocolVersion */ ] != tls_packet_start {
198- return Err ( Error :: new ( ErrorKind :: InvalidToken , "invalid TLS packet header." ) ) ;
203+ return Err ( Error :: new (
204+ ErrorKind :: InvalidToken ,
205+ format ! (
206+ "invalid TLS packet header: expected {:?} but got {:?}" ,
207+ tls_packet_start,
208+ & payload[ 0 ..3 ]
209+ ) ,
210+ ) ) ;
199211 }
200212
201213 // Safe: payload length is checked above.
@@ -231,16 +243,28 @@ impl TlsConnection {
231243 // try to decrypt it -- it will just return a SEC_E_DECRYPT_FAILURE code."
232244 let mut tls_packet_start = vec ! [ TLS_APPLICATION_DATA_CONTENT_TYPE ] ;
233245
234- let tls_version: u16 = connection
246+ let tls_version = connection
235247 . protocol_version ( )
236- . ok_or_else ( || Error :: new ( ErrorKind :: InternalError , "can not query negotiated TLS version" ) ) ?
237- . into ( ) ;
248+ . ok_or_else ( || Error :: new ( ErrorKind :: InternalError , "can not query negotiated TLS version" ) ) ?;
249+ let tls_version = u16:: from ( if tls_version == ProtocolVersion :: TLSv1_3 {
250+ // TLS 1.3 uses the same version number as TLS 1.2 in the record layer.
251+ ProtocolVersion :: TLSv1_2
252+ } else {
253+ tls_version
254+ } ) ;
238255
239256 tls_packet_start. extend_from_slice ( & tls_version. to_be_bytes ( ) ) ;
240257
241258 // Safe: payload length is checked above.
242259 if payload[ 0 ..1 /* ContentType */ + 2 /* ProtocolVersion */ ] != tls_packet_start {
243- return Err ( Error :: new ( ErrorKind :: InvalidToken , "invalid TLS packet header." ) ) ;
260+ return Err ( Error :: new (
261+ ErrorKind :: InvalidToken ,
262+ format ! (
263+ "invalid TLS packet header: expected {:?} but got {:?}" ,
264+ tls_packet_start,
265+ & payload[ 0 ..3 ] ,
266+ ) ,
267+ ) ) ;
244268 }
245269
246270 // Safe: payload length is checked above.
0 commit comments