Skip to content

Commit 0605cf0

Browse files
fix(sspi): TLS 1.3 support in TSSSP module (#536)
* Adds `CipherSuite::TLS13_AES_256_GCM_SHA384` support. * Fixes TLS packet header validation: TLS 1.3 uses TLS 1.2 version in the packet header.
1 parent 40785e3 commit 0605cf0

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/credssp/sspi_cred_ssp/cipher_block_size.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub(super) fn get_cipher_block_size(cipher: CipherSuite) -> Result<u32> {
4545
CipherSuite::TLS_PSK_WITH_AES_128_GCM_SHA256 => Ok(AES_BLOCK_SIZE),
4646
CipherSuite::TLS_PSK_WITH_AES_256_CBC_SHA384 => Ok(AES_BLOCK_SIZE),
4747
CipherSuite::TLS_PSK_WITH_AES_128_CBC_SHA256 => Ok(AES_BLOCK_SIZE),
48+
CipherSuite::TLS13_AES_256_GCM_SHA384 => Ok(AES_BLOCK_SIZE),
4849
// Stream ciphers
4950
CipherSuite::TLS13_CHACHA20_POLY1305_SHA256 => Ok(0),
5051
CipherSuite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 => Ok(0),

src/credssp/sspi_cred_ssp/tls_connection.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)