1use std::io;
2use std::path::PathBuf;
3
4use thiserror::Error;
5use tonic::metadata::errors::InvalidMetadataValue;
6
7#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum Error {
11 #[error("failed to read credential at {path}: {source}")]
13 CredentialRead {
14 path: PathBuf,
16 #[source]
18 source: io::Error,
19 },
20
21 #[error("invalid certificate at {path}: {reason}")]
23 InvalidCertificate {
24 path: PathBuf,
26 reason: &'static str,
28 },
29
30 #[error("invalid private key at {path}: {reason}")]
32 InvalidPrivateKey {
33 path: PathBuf,
35 reason: &'static str,
37 },
38
39 #[error("gRPC transport error: {0}")]
41 Transport(#[from] tonic::transport::Error),
42
43 #[error("gRPC request failed: {0}")]
45 GrpcStatus(#[from] tonic::Status),
46
47 #[error("invalid runtime API gateway address")]
49 InvalidGatewayAddress,
50
51 #[error("invalid LazyCat device API URL")]
53 InvalidDeviceUrl,
54
55 #[error("unsupported application private key for device authentication")]
57 UnsupportedAuthSigningKey,
58
59 #[error("failed to sign the application identity")]
61 AuthSigning,
62
63 #[error("device auth token response has no deadline")]
65 MissingTokenDeadline,
66
67 #[error("device auth token response has an invalid deadline")]
69 InvalidTokenDeadline,
70
71 #[error("device auth token is not a valid gRPC metadata value")]
73 InvalidAuthTokenMetadata,
74
75 #[error("device service-status query is unsupported")]
77 ServiceStatusUnsupported,
78
79 #[error("HPortalSys returned an invalid RemoteSocks endpoint")]
81 InvalidRemoteSocksEndpoint,
82
83 #[error("failed to resolve host.lzcapp: {source}")]
85 ServiceAddressLookup {
86 #[source]
88 source: io::Error,
89 },
90
91 #[error("no usable route to host.lzcapp")]
93 ServiceAddressNoRoute {
94 #[source]
96 source: Option<io::Error>,
97 },
98
99 #[error("invalid SOCKS address")]
101 InvalidSocksAddress,
102
103 #[error("SOCKS address is longer than 255 bytes")]
105 SocksAddressTooLong,
106
107 #[error("unsupported SOCKS address type {address_type:#04x}")]
109 UnsupportedSocksAddressType {
110 address_type: u8,
112 },
113
114 #[error("RemoteSocks network error: {0}")]
116 RemoteSocksIo(#[from] io::Error),
117
118 #[error("RemoteSocks connection timed out")]
120 RemoteSocksTimeout,
121
122 #[error("unexpected SOCKS protocol version {version}")]
124 UnexpectedSocksVersion {
125 version: u8,
127 },
128
129 #[error("SOCKS proxy rejected all authentication methods")]
131 SocksNoAcceptableAuthentication,
132
133 #[error("unsupported SOCKS authentication method {method:#04x}")]
135 UnsupportedSocksAuthentication {
136 method: u8,
138 },
139
140 #[error("invalid SOCKS reserved byte {reserved:#04x}")]
142 InvalidSocksReservedByte {
143 reserved: u8,
145 },
146
147 #[error("SOCKS proxy command failed with reply code {code:#04x}")]
149 SocksReply {
150 code: u8,
152 },
153
154 #[error("invalid SOCKS UDP datagram header")]
156 InvalidSocksUdpHeader,
157
158 #[error("SOCKS UDP fragmentation is unsupported (fragment {fragment})")]
160 UnsupportedSocksUdpFragment {
161 fragment: u8,
163 },
164
165 #[error("RemoteSocks UDP payload is too large")]
167 SocksUdpPayloadTooLarge,
168
169 #[error("RemoteSocks UDP socket has no connected peer")]
171 SocksUdpNotConnected,
172
173 #[error("RemoteSocks UDP control stream closed")]
175 RemoteSocksControlClosed,
176
177 #[error("invalid RemoteSocks UDP socket address")]
179 InvalidSocksUdpAddress,
180
181 #[error("invalid gRPC metadata value")]
183 InvalidMetadataValue(#[source] InvalidMetadataValue),
184
185 #[error("peer is not authenticated with a TLS client certificate")]
187 UnauthenticatedPeer,
188
189 #[error("expected exactly one peer certificate, got {count}")]
191 InvalidPeerCertificateCount {
192 count: usize,
194 },
195
196 #[error("invalid peer certificate")]
198 InvalidPeerCertificate,
199}