1
1
//! Implements SOCKS in the flavors provided by Tor.
2
//!
3
//! # Overview
4
//!
5
//! SOCKS is an old and somewhat janky protocol for telling a TCP
6
//! proxy where to connect.  Versions 4, 4a, and 5 are sometimes
7
//! encountered in the wild.
8
//!
9
//! The `tor-socksproto` crate tries to hide the actual details of the
10
//! protocol, and expose a stateful handshake type that eventually
11
//! provides a [`SocksRequest`] or an error.  It is part of
12
//! [Arti](https://gitlab.torproject.org/tpo/core/arti/), a project to
13
//! implement [Tor](https://www.torproject.org/) in Rust.
14
//! At present, it is only used to provide a
15
//! SOCKS proxy _over_ the Tor network, but eventually it may be used
16
//! to implement support for connecting to the Tor network over a
17
//! SOCKS proxy.
18
//!
19
//! This crate may be a good choice for you if you need a SOCKS
20
//! implementation that "behaves like Tor", but otherwise it is
21
//! probably better to use some other SOCKS crate.
22
//!
23
//! For more information about SOCKS:
24
//!
25
//!   * SOCKS5 (which is preferred) is specified in
26
//!     [RFC 1928](https://tools.ietf.org/html/rfc1928), and see also
27
//!     [RFC 1929](https://tools.ietf.org/html/rfc1929) for
28
//!     Username/Password authentication in SOCKS5.
29
//!   * [The wikipedia article](https://en.wikipedia.org/wiki/SOCKS)
30
//!     is the best surviving documentation for SOCKS4 and SOCKS4a.
31
//!   * See
32
//!     [socks-extensions.txt](https://spec.torproject.org/socks-extensions)
33
//!     for a description of Tor's extensions and restrictions on the
34
//!     SOCKS protocol.
35
//!
36
//! ## Design notes
37
//!
38
//! Arti uses this crate instead of some other SOCKS implementation,
39
//! for two reasons:
40
//!
41
//!  * First, because we need to support Tor SOCKS extensions.
42
//!  * Second, and because we sometimes need to see particular details
43
//!    of the individual handshakes that most other SOCKS
44
//!    implementations don't expose.  (For example, if we are told to
45
//!    connect to a raw IP address, the type of the handshake can help
46
//!    us guess whether that IP address came from a DNS response–in
47
//!    which case we should warn about a possible DNS leak.)
48
//!
49
//! Currently, `tor-socksproto` does no networking code: it _only_
50
//! implements the server (proxy) side of the SOCKS handshake by
51
//! handling a series of bytes.  We may (or may not) want to add
52
//! network functionality to this crate or elsewhere in the future.
53
//! We'll definitely want to add client functionality.
54
//!
55
//! Possibly, this approach will prove useful for other uses.  If it
56
//! does, We can put the tor-only functionality behind a Cargo build
57
//! feature, so that others can use this crate more safely.
58

            
59
#![deny(missing_docs)]
60
#![warn(noop_method_call)]
61
#![deny(unreachable_pub)]
62
#![warn(clippy::all)]
63
#![deny(clippy::await_holding_lock)]
64
#![deny(clippy::cargo_common_metadata)]
65
#![deny(clippy::cast_lossless)]
66
#![deny(clippy::checked_conversions)]
67
#![warn(clippy::cognitive_complexity)]
68
#![deny(clippy::debug_assert_with_mut_call)]
69
#![deny(clippy::exhaustive_enums)]
70
#![deny(clippy::exhaustive_structs)]
71
#![deny(clippy::expl_impl_clone_on_copy)]
72
#![deny(clippy::fallible_impl_from)]
73
#![deny(clippy::implicit_clone)]
74
#![deny(clippy::large_stack_arrays)]
75
#![warn(clippy::manual_ok_or)]
76
#![deny(clippy::missing_docs_in_private_items)]
77
#![deny(clippy::missing_panics_doc)]
78
#![warn(clippy::needless_borrow)]
79
#![warn(clippy::needless_pass_by_value)]
80
#![warn(clippy::option_option)]
81
#![warn(clippy::rc_buffer)]
82
#![deny(clippy::ref_option_ref)]
83
#![warn(clippy::semicolon_if_nothing_returned)]
84
#![warn(clippy::trait_duplication_in_bounds)]
85
#![deny(clippy::unnecessary_wraps)]
86
#![warn(clippy::unseparated_literal_suffix)]
87
#![deny(clippy::unwrap_used)]
88

            
89
mod err;
90
mod handshake;
91
mod msg;
92

            
93
pub use err::Error;
94
pub use handshake::{Action, SocksHandshake};
95
pub use msg::{SocksAddr, SocksAuth, SocksCmd, SocksRequest, SocksStatus, SocksVersion};
96
pub use tor_error::Truncated;
97

            
98
/// A Result type for the tor_socksproto crate.
99
pub type Result<T> = std::result::Result<T, Error>;
100

            
101
/// A Result type for the tor_socksproto crate, including the possibility of a
102
/// truncated message.
103
///
104
/// This is a separate type from Result because a truncated message is not a
105
/// true error: it just means that you need to read more bytes and try again.
106
pub type TResult<T> = std::result::Result<Result<T>, Truncated>;