mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-31 03:50:37 +00:00
Our rust-postgres fork is getting messy. Mostly because proxy wants more
control over the raw protocol than tokio-postgres provides. As such,
it's diverging more and more. Storage and compute also make use of
rust-postgres, but in more normal usage, thus they don't need our crazy
changes.
Idea:
* proxy maintains their subset
* other teams use a minimal patch set against upstream rust-postgres
Reviewing this code will be difficult. To implement it, I
1. Copied tokio-postgres, postgres-protocol and postgres-types from
00940fcdb5
2. Updated their package names with the `2` suffix to make them compile
in the workspace.
3. Updated proxy to use those packages
4. Copied in the code from tokio-postgres-rustls 0.13 (with some patches
applied https://github.com/jbg/tokio-postgres-rustls/pull/32
https://github.com/jbg/tokio-postgres-rustls/pull/33)
5. Removed as much dead code as I could find in the vendored libraries
6. Updated the tokio-postgres-rustls code to use our existing channel
binding implementation
38 lines
939 B
Rust
38 lines
939 B
Rust
//! Authentication protocol support.
|
|
use md5::{Digest, Md5};
|
|
|
|
pub mod sasl;
|
|
|
|
/// Hashes authentication information in a way suitable for use in response
|
|
/// to an `AuthenticationMd5Password` message.
|
|
///
|
|
/// The resulting string should be sent back to the database in a
|
|
/// `PasswordMessage` message.
|
|
#[inline]
|
|
pub fn md5_hash(username: &[u8], password: &[u8], salt: [u8; 4]) -> String {
|
|
let mut md5 = Md5::new();
|
|
md5.update(password);
|
|
md5.update(username);
|
|
let output = md5.finalize_reset();
|
|
md5.update(format!("{:x}", output));
|
|
md5.update(salt);
|
|
format!("md5{:x}", md5.finalize())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn md5() {
|
|
let username = b"md5_user";
|
|
let password = b"password";
|
|
let salt = [0x2a, 0x3d, 0x8f, 0xe0];
|
|
|
|
assert_eq!(
|
|
md5_hash(username, password, salt),
|
|
"md562af4dd09bbb41884907a838a3233294"
|
|
);
|
|
}
|
|
}
|