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
//! An implementation of the World of Warcraft flavor of SRP6 used for authentication with the Login Server.
//! It is only tested and verified on 1.12.1, but should work for other versions.
//!
//! The implementation is intended to abstract away as much of the protocol as possible,
//! and limits itself to the specific requirements of the World of Warcraft implementation.
//! For example, all key sizes are limited to exactly [32 bytes](LARGE_SAFE_PRIME_LENGTH) since
//! the network packet fields describing public keys are of a fixed size in the protocol
//! and key sizes of any other sizes are not possible.
//!
//! This crate does not deal with parsing the network packets necessary to obtain the required parameters.
//! The [WoWDev wiki](https://wowdev.wiki/Login_Packet) ([archive]) contains a reference list of packets
//! and the examples implement the required functionality.
//!
//! **THIS SHOULD NOT BE USED FOR ANYTHING OTHER THAN WORLD OF WARCRAFT EMULATION.
//! THE CODE IS NOT CRYPTOGRAPHICALLY VERIFIED, HAS VERY LOW KEY SIZES BECAUSE OF
//! PACKET REQUIREMENTS AND MOST LIKELY CONTAINS EXPLOITS.**
//!
//! # Usage
//!
//! The crate is split into:
//! * A [`server`] module containing structs for use on the server.
//! * A [`client`] module containing structs for use on the client.
//! * A [`header_crypto`] module containing structs and traits for decrypting world packets.
//! * An [`error`] module for errors that are shared by all modules.
//! * A [`normalized_string`] module used for all modules to correctly handle strings.
//!
//! A server example can be found in `examples/server.rs`
//! and a client example can be found in `examples/client.rs`.
//! These examples will perform the full SRP6 connection and reconnection.
//! The server will work with a 1.12.1 client,
//! using the username and password `a` and `a`.
//! The client will work not with any other server since it ignores everything
//! that is not absolutely necessary for showcasing the crate.
//!
//! ## Running the examples
//!
//! 1. Clone the repo with `git clone https://github.com/gtker/wow_srp`.
//! 2. Run the server with `cargo run --example server` inside the directory.
//! This runs a simple authentication server that accepts the username "a" and the password "a". Anything else panics.
//! 3. Run a real client with the realmlist set to `localhost`
//! or run the client example with `cargo run --example client`.
//!
//! ## Usage
//!
//! Add the following to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! wow_srp = { version = "0.4.1" }
//! ```
//!
//! Then go to either the [`client`] module or [`server`] module for specific instructions.
//!
//! ## Features
//!
//! Two different arbitrary precision integer libraries can be used, either:
//!
//! * [num-bigint](https://crates.io/crates/num-bigint). A slow pure Rust implementation without
//! external dependencies. This is enabled by default, and requires no opt in.
//!
//! * [rug](https://crates.io/crates/rug). A fast wrapper around the [GMP library](https://gmplib.org/)
//! with external dependencies, as described in the [gmp_mpfr_sys documentation](https://docs.rs/gmp-mpfr-sys/1.4.6/gmp_mpfr_sys/index.html#building-on-gnulinux).
//! This is enabled with the `fast-math` feature and disabling default features.
//! So **instead** of the above do this:
//!
//! ```toml
//! [dependencies]
//! wow_srp = { version = "0.4.1", default-features = false, features = ["fast-math"] }
//! ```
//!
//! The `fast-math` feature leads to a 50% decrease in total time. It is highly recommended to enable
//! this feature for production usage since it also theoretically has better security.
//!
//! To see the performance difference on your setup you can run `cargo bench` for the default version,
//! and `cargo bench --features fast-math --no-default-features` for the `fast-math` version.
//!
//! # MSRV
//!
//! `wow_srp` has a Minimum Supported Rust Version (MSRV) of 1.48.0.
//! The MSRV may be increased in `PATCH` versions before `wow_srp` reaches `1.0.0` (`MAJOR.MINOR.PATCH`).
//!
//! # Other implementations
//!
//! * [Ember](https://github.com/EmberEmu/Ember/tree/development/src/libs/srp6) is a C++ implementation for 1.12 with a clean, tested implementation of the protocol.
//! * [ArcEmu](https://github.com/arcemu/arcemu/blob/00355000cac5d0b9bce42bf6d03d4aeda9e396ea/src/logon/Auth/AuthSocket.cpp#L74) is a C++ implementation for 3.3.5.
//! * [vMangos](https://github.com/vmangos/core/blob/fa9351de7e832510309209351c17f5c53f3155ef/src/realmd/AuthSocket.cpp#L350) is a C++ implementation.
//! * [WoWCore](https://github.com/RomanRom2/WoWCore/blob/92b7646c2bafb22ad6dca0acc9496a35561292c4/05875_1.12.1/pas/sandbox/AuthServer.pas#L133) is a Pascal implementation that has 1.12, 2.4.3 and 3.3.5 versions.
//! * [Shadowburn](https://gitlab.com/shadowburn/shadowburn/-/blob/ac905fabf56579b3bda6f16689c74f544da043e2/apps/common/lib/accounts/accounts.ex#L88) is an Elixir implementation.
//!
//! [archive]: https://web.archive.org/web/20210620154707/https://wowdev.wiki/Login_Packet

#![doc(html_root_url = "https://docs.rs/wow_srp/0.4.1")]
#![forbid(unsafe_code)]
#![warn(
    clippy::perf,
    clippy::correctness,
    clippy::style,
    clippy::missing_const_for_fn,
    clippy::missing_errors_doc,
    clippy::missing_panics_doc,
    clippy::doc_markdown,
    clippy::unseparated_literal_suffix,
    missing_docs
)]

pub use key::PublicKey;
pub use key::PASSWORD_VERIFIER_LENGTH;
pub use key::PROOF_LENGTH;
pub use key::PUBLIC_KEY_LENGTH;
pub use key::RECONNECT_CHALLENGE_DATA_LENGTH;
pub use key::SALT_LENGTH;
pub use key::SESSION_KEY_LENGTH;
pub use primes::GENERATOR;
pub use primes::GENERATOR_LENGTH;
pub use primes::LARGE_SAFE_PRIME_BIG_ENDIAN;
pub use primes::LARGE_SAFE_PRIME_LENGTH;
pub use primes::LARGE_SAFE_PRIME_LITTLE_ENDIAN;

pub(crate) mod bigint;
pub mod client;
pub mod error;
pub mod header_crypto;
mod key;
pub mod normalized_string;
pub(crate) mod primes;
pub mod server;
pub(crate) mod srp_internal;
pub(crate) mod srp_internal_client;

#[cfg(test)]
pub(crate) mod hex;