fix: improve ecies error fatal variants (#11303)

This commit is contained in:
caglarkaya
2024-09-28 15:21:20 +03:00
committed by GitHub
parent 375acdfedc
commit b090578b77
2 changed files with 28 additions and 2 deletions

View File

@ -13,6 +13,11 @@ impl ECIESError {
pub fn into_inner(self) -> ECIESErrorImpl { pub fn into_inner(self) -> ECIESErrorImpl {
*self.inner *self.inner
} }
/// Returns a reference to the inner error
pub const fn inner(&self) -> &ECIESErrorImpl {
&self.inner
}
} }
impl fmt::Display for ECIESError { impl fmt::Display for ECIESError {

View File

@ -3,6 +3,7 @@
use std::{fmt, io, io::ErrorKind, net::SocketAddr}; use std::{fmt, io, io::ErrorKind, net::SocketAddr};
use reth_dns_discovery::resolver::ResolveError; use reth_dns_discovery::resolver::ResolveError;
use reth_ecies::ECIESErrorImpl;
use reth_eth_wire::{ use reth_eth_wire::{
errors::{EthHandshakeError, EthStreamError, P2PHandshakeError, P2PStreamError}, errors::{EthHandshakeError, EthStreamError, P2PHandshakeError, P2PStreamError},
DisconnectReason, DisconnectReason,
@ -206,7 +207,17 @@ impl SessionError for PendingSessionHandshakeError {
fn merits_discovery_ban(&self) -> bool { fn merits_discovery_ban(&self) -> bool {
match self { match self {
Self::Eth(eth) => eth.merits_discovery_ban(), Self::Eth(eth) => eth.merits_discovery_ban(),
Self::Ecies(_) => true, Self::Ecies(err) => matches!(
err.inner(),
ECIESErrorImpl::TagCheckDecryptFailed |
ECIESErrorImpl::TagCheckHeaderFailed |
ECIESErrorImpl::TagCheckBodyFailed |
ECIESErrorImpl::InvalidAuthData |
ECIESErrorImpl::InvalidAckData |
ECIESErrorImpl::InvalidHeader |
ECIESErrorImpl::Secp256k1(_) |
ECIESErrorImpl::InvalidHandshake { .. }
),
Self::Timeout => false, Self::Timeout => false,
} }
} }
@ -214,7 +225,17 @@ impl SessionError for PendingSessionHandshakeError {
fn is_fatal_protocol_error(&self) -> bool { fn is_fatal_protocol_error(&self) -> bool {
match self { match self {
Self::Eth(eth) => eth.is_fatal_protocol_error(), Self::Eth(eth) => eth.is_fatal_protocol_error(),
Self::Ecies(_) => true, Self::Ecies(err) => matches!(
err.inner(),
ECIESErrorImpl::TagCheckDecryptFailed |
ECIESErrorImpl::TagCheckHeaderFailed |
ECIESErrorImpl::TagCheckBodyFailed |
ECIESErrorImpl::InvalidAuthData |
ECIESErrorImpl::InvalidAckData |
ECIESErrorImpl::InvalidHeader |
ECIESErrorImpl::Secp256k1(_) |
ECIESErrorImpl::InvalidHandshake { .. }
),
Self::Timeout => false, Self::Timeout => false,
} }
} }