Skip to content

Commit bf68589

Browse files
authored
Returning an alert when PSK authentication fails. (webrtc-rs#458)
1 parent c472e6d commit bf68589

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

dtls/src/alert/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub(crate) enum AlertDescription {
6262
UserCanceled = 90,
6363
NoRenegotiation = 100,
6464
UnsupportedExtension = 110,
65+
UnknownPskIdentity = 115,
6566
Invalid,
6667
}
6768

@@ -93,6 +94,7 @@ impl fmt::Display for AlertDescription {
9394
AlertDescription::UserCanceled => write!(f, "UserCanceled"),
9495
AlertDescription::NoRenegotiation => write!(f, "NoRenegotiation"),
9596
AlertDescription::UnsupportedExtension => write!(f, "UnsupportedExtension"),
97+
AlertDescription::UnknownPskIdentity => write!(f, "UnknownPskIdentity"),
9698
_ => write!(f, "Invalid alert description"),
9799
}
98100
}
@@ -126,6 +128,7 @@ impl From<u8> for AlertDescription {
126128
90 => AlertDescription::UserCanceled,
127129
100 => AlertDescription::NoRenegotiation,
128130
110 => AlertDescription::UnsupportedExtension,
131+
115 => AlertDescription::UnknownPskIdentity,
129132
_ => AlertDescription::Invalid,
130133
}
131134
}

dtls/src/conn/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,20 @@ impl DTLSConn {
968968
Ok(pkt) => pkt,
969969
Err(err) => {
970970
debug!("{}: decrypt failed: {}", srv_cli_str(ctx.is_client), err);
971-
return (false, None, None);
971+
972+
// If we get an error for PSK we need to return an error.
973+
if cipher_suite.is_psk() {
974+
return (
975+
false,
976+
Some(Alert {
977+
alert_level: AlertLevel::Fatal,
978+
alert_description: AlertDescription::UnknownPskIdentity,
979+
}),
980+
None,
981+
);
982+
} else {
983+
return (false, None, None);
984+
}
972985
}
973986
};
974987
}

0 commit comments

Comments
 (0)