Skip to content

Commit

Permalink
Returning an alert when PSK authentication fails. (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Jun 22, 2024
1 parent 4007076 commit 1a9bfce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions rtc-dtls/src/alert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub(crate) enum AlertDescription {
UserCanceled = 90,
NoRenegotiation = 100,
UnsupportedExtension = 110,
UnknownPskIdentity = 115,
Invalid,
}

Expand Down Expand Up @@ -93,6 +94,7 @@ impl fmt::Display for AlertDescription {
AlertDescription::UserCanceled => write!(f, "UserCanceled"),
AlertDescription::NoRenegotiation => write!(f, "NoRenegotiation"),
AlertDescription::UnsupportedExtension => write!(f, "UnsupportedExtension"),
AlertDescription::UnknownPskIdentity => write!(f, "UnknownPskIdentity"),
_ => write!(f, "Invalid alert description"),
}
}
Expand Down Expand Up @@ -126,6 +128,7 @@ impl From<u8> for AlertDescription {
90 => AlertDescription::UserCanceled,
100 => AlertDescription::NoRenegotiation,
110 => AlertDescription::UnsupportedExtension,
115 => AlertDescription::UnknownPskIdentity,
_ => AlertDescription::Invalid,
}
}
Expand Down
15 changes: 14 additions & 1 deletion rtc-dtls/src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,20 @@ impl DTLSConn {
Ok(pkt) => pkt,
Err(err) => {
debug!("{}: decrypt failed: {}", srv_cli_str(self.is_client), err);
return (false, None, None);

// If we get an error for PSK we need to return an error.
if cipher_suite.is_psk() {
return (
false,
Some(Alert {
alert_level: AlertLevel::Fatal,
alert_description: AlertDescription::UnknownPskIdentity,
}),
None,
);
} else {
return (false, None, None);
}
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion rtc-dtls/src/extension/renegotiation_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use shared::error::Error;
const RENEGOTIATION_INFO_HEADER_SIZE: usize = 5;

/// RenegotiationInfo allows a Client/Server to
/// communicate their renegotation support
/// communicate their renegotiation support
/// https://tools.ietf.org/html/rfc5746
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ExtensionRenegotiationInfo {
Expand Down

0 comments on commit 1a9bfce

Please sign in to comment.