1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//! Algebraic failure values for local onion routing and exit wire responses.
use std::fmt;
use serde::Deserialize;
use serde::Serialize;
use crate::error::Error;
/// Local route and session failure before any user-facing rendering.
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
pub enum OnionRouteError {
/// A pipeline has no symbol application or more than the loop admits (#834 D4a).
#[error("onion pipeline has {symbols} symbol applications; a loop admits 1 to {max_symbols}")]
LoopSymbolsOutOfBounds {
/// Number of symbol applications of the pipeline.
symbols: usize,
/// Largest number of symbol applications of one loop.
max_symbols: usize,
},
/// Fewer distinct eligible hops exist than the loop's `H − 1` positions require (#834 D5).
#[error("onion loop requires {required} distinct hops but only {eligible} are eligible")]
NotEnoughLoopHops {
/// Distinct hops the loop requires.
required: usize,
/// Distinct eligible hops found.
eligible: usize,
},
/// The symbol registrants admit no assignment of pairwise distinct hops to the symbol
/// positions of a loop.
#[error("onion symbol registrants admit no distinct hop per symbol position")]
NoDistinctSymbolHops,
/// A loop draw found no candidate although its matching guaranteed one: a violated invariant
/// of loop selection, never a property of the network.
#[error("onion loop selection violated its invariant: a guaranteed draw had no candidate")]
LoopDrawInvariant,
/// Route construction could not select a first hop accepted by the caller.
#[error("no onion route has a permitted first hop")]
NoPermittedFirstHop,
/// No live exit descriptor offers the requested service.
#[error("no live onion exit offers service {service:?}")]
NoLiveExit {
/// Requested service name.
service: String,
},
/// Every live exit of the service differs from its node's current relay registration in
/// session key or process epoch: the exit registered from another process, typically before
/// a restart, and its descriptors have not converged (#834 D2).
#[error(
"every onion exit offering service {service:?} differs from its node's current relay \
registration in session key or process epoch"
)]
ExitRelayRegistrationMismatch {
/// Requested service name.
service: String,
},
/// Every live exit of the service belongs to a node that registers no `relay` (#834 D2).
#[error("every onion exit offering service {service:?} lacks a relay registration")]
ExitWithoutRelayRegistration {
/// Requested service name.
service: String,
},
/// Live exits advertise the service, but none can serve the requested proxy protocol.
#[error("no live onion exit offers service {service:?} for proxy protocol {protocol:?}")]
NoExitForProxyProtocol {
/// Requested service name.
service: String,
/// Requested proxy protocol label.
protocol: String,
},
/// Live exits advertise the service, but no policy allows the target.
#[error("no live onion exit for service {service:?} allows target {target:?}")]
NoExitAllowsTarget {
/// Requested service name.
service: String,
/// Requested target authority.
target: String,
},
/// A session's symbol does not match the service its route was selected for.
#[error(
"onion payload service {payload_service:?} does not match route service \
{route_service:?}"
)]
PayloadServiceMismatch {
/// Symbol the session applies.
payload_service: String,
/// Service label selected by the route.
route_service: String,
},
/// A queued endpoint cell lost its drain task before the overlay reported a result.
#[error("onion link send was cancelled before overlay completion")]
LinkSendCancelled,
/// An endpoint's cell found no room on its lane, or did not leave, within the send deadline.
#[error("onion link send timed out")]
LinkSendTimedOut,
/// An HTTPS response channel closed before the exit's outcome was delivered.
#[error("onion HTTPS response channel closed")]
HttpsResponseClosed,
/// The exit's `tcp` world failed at its target: a connect, read, write or shutdown of the
/// target's socket. The reason stays at the exit; the client sees only a failed session.
#[error("onion TCP target: {0}")]
TcpTarget(String),
/// The exit's connect to a `tcp` target did not complete within its open timeout.
#[error("onion TCP open timed out")]
TcpOpenTimedOut,
/// A session's driver has already ended.
#[error("onion TCP stream is closed")]
TcpStreamClosed,
/// The exit's `udp` world failed at its bound socket or frame stream. The reason stays at the
/// exit; the client sees only a failed session.
#[error("onion UDP target: {0}")]
UdpTarget(String),
/// The exit's `udp` socket bind did not complete within its open timeout.
#[error("onion UDP open timed out")]
UdpOpenTimedOut,
/// A `udp` session's driver has already ended.
#[error("onion UDP session is closed")]
UdpSessionClosed,
/// The client could not build a loop over its route (a value too wide for its class, or a
/// key failure of negligible probability).
#[error("could not build an onion loop: {0}")]
LoopBuild(String),
/// The exit answered the session's open with a refusal; the exit gives no reason (#834 D2′).
/// A session that ends locally before the exit answers reports its own error instead
/// (#1118).
#[error("the onion exit refused the session")]
ExitRefused,
/// A session failed closed: a gap in its sequence, its liveness deadline, a lost reply, or
/// the exit's abort, whether before or after the exit answered its open.
#[error("the onion session failed closed")]
SessionFailed,
/// An exit-reported failure reached the local route client.
#[error("{0}")]
ExitFailure(OnionExitFailure),
/// No live `invoke` descriptor offers `(shape, backend)`.
#[error("no live onion node registers invoke symbol ({shape}, {backend:?})")]
NoLiveSymbol {
/// Canonical `invoke` shape string.
shape: String,
/// Requested backend name.
backend: String,
},
/// Every live `invoke` registrant of `(shape, backend)` differs from its node's current relay
/// registration in session key or process epoch (#834 D2).
#[error(
"every onion registrant of ({shape}, {backend:?}) differs from its node's current relay \
registration in session key or process epoch"
)]
SymbolRelayRegistrationMismatch {
/// Canonical `invoke` shape string.
shape: String,
/// Requested backend name.
backend: String,
},
/// Every live `invoke` registrant of `(shape, backend)` lacks a relay registration (#834 D2).
#[error("every onion registrant of ({shape}, {backend:?}) lacks a relay registration")]
SymbolWithoutRelayRegistration {
/// Canonical `invoke` shape string.
shape: String,
/// Requested backend name.
backend: String,
},
/// A Kleisli pipeline's `(shape, backend)` sequence does not match the selected route's.
#[error("onion pipeline symbols do not match the selected pipeline route")]
PipelineRouteMismatch,
/// A one-shot Kleisli pipeline did not return before its loop expiry `x`.
#[error("onion Kleisli pipeline timed out before loop expiry")]
PipelineTimedOut,
/// A one-shot Kleisli pipeline failed closed (e.g., its guard link retired or dropped).
#[error("onion Kleisli pipeline failed closed")]
PipelineFailed,
}
/// Why an `https` exit returned no response: the encoded failure of a fetch outcome. It carries
/// no local diagnostic, so a failure reveals nothing of the exit beyond its class.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum OnionExitFailure {
/// The exit policy or its byte budget denied the fetch.
PermissionDenied,
/// The session's stream did not decode as a request.
MalformedRequest,
/// The fetch failed at the exit.
Internal,
}
impl OnionExitFailure {
/// Convert a local node error into a wire failure at the adapter boundary.
pub fn from_error(error: &Error) -> Self {
match error {
Error::NoPermission => Self::PermissionDenied,
_ => Self::Internal,
}
}
}
impl fmt::Display for OnionExitFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::PermissionDenied => Error::NoPermission.fmt(f),
Self::MalformedRequest => f.write_str("onion exit received a malformed HTTPS request"),
Self::Internal => f.write_str("onion exit internal failure"),
}
}
}
#[cfg(test)]
mod tests {
use super::OnionExitFailure;
use crate::error::Error;
#[test]
fn test_wire_internal_failure_does_not_expose_local_diagnostic() {
let diagnostic = "secret local filesystem and resolver detail";
let failure = OnionExitFailure::from_error(&Error::InvalidConfig(diagnostic.to_string()));
let encoded = rings_codec::serialize(&failure).expect("encode wire failure");
assert_eq!(failure, OnionExitFailure::Internal);
assert!(!failure.to_string().contains(diagnostic));
assert!(!encoded
.windows(diagnostic.len())
.any(|window| window == diagnostic.as_bytes()));
}
}