mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 09:26:30 +00:00
Compare commits
1 Commits
sven_md5_a
...
levkk-fix-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4d83a6fe7 |
@@ -109,12 +109,11 @@ impl Client {
|
||||
PROTOCOL_VERSION_NUMBER => {
|
||||
trace!("Got StartupMessage");
|
||||
let parameters = parse_startup(bytes.clone())?;
|
||||
let mut user_name: String = String::new();
|
||||
match parameters.get(&"user") {
|
||||
Some(&user) => user_name = user,
|
||||
let user = match parameters.get(&String::from("user")) {
|
||||
Some(user) => user,
|
||||
None => return Err(Error::ClientBadStartup),
|
||||
}
|
||||
start_auth(&mut stream, &user_name).await?;
|
||||
};
|
||||
start_auth(&mut stream, user).await?;
|
||||
|
||||
// Generate random backend ID and secret key
|
||||
let process_id: i32 = rand::random();
|
||||
|
||||
@@ -46,11 +46,9 @@ md5(concat(md5(concat(password, username)), random-salt)))
|
||||
5. check username hash combo against file
|
||||
6. AuthenticationOk or ErrorResponse
|
||||
**/
|
||||
pub async fn start_auth(stream: &mut TcpStream, user_name: &String) -> Result<(), Error> {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
pub async fn start_auth(stream: &mut TcpStream, user: &str) -> Result<(), Error> {
|
||||
//Generate random 4 byte salt
|
||||
let salt = rng.gen::<u32>();
|
||||
let salt = rand::random::<u32>();
|
||||
|
||||
// Send AuthenticationMD5Password request
|
||||
send_md5_request(stream, salt).await?;
|
||||
@@ -63,7 +61,7 @@ pub async fn start_auth(stream: &mut TcpStream, user_name: &String) -> Result<()
|
||||
match code {
|
||||
// Password response
|
||||
'p' => {
|
||||
fetch_password_and_authenticate(stream, &user_name, &salt).await?;
|
||||
fetch_password_and_authenticate(stream, user, &salt).await?;
|
||||
Ok(auth_ok(stream).await?)
|
||||
}
|
||||
_ => {
|
||||
@@ -84,7 +82,7 @@ pub async fn send_md5_request(stream: &mut TcpStream, salt: u32) -> Result<(), E
|
||||
Ok(write_all(stream, authentication_md5password).await?)
|
||||
}
|
||||
|
||||
pub async fn fetch_password_and_authenticate(stream: &mut TcpStream, user_name: &String, salt: &u32) -> Result<(), Error> {
|
||||
pub async fn fetch_password_and_authenticate(stream: &mut TcpStream, user: &str, salt: &u32) -> Result<(), Error> {
|
||||
/**
|
||||
1. How do I store the lists of users and paswords? clear text or hash?? wtf
|
||||
2. Add auth to tests
|
||||
@@ -104,18 +102,17 @@ pub async fn fetch_password_and_authenticate(stream: &mut TcpStream, user_name:
|
||||
};
|
||||
|
||||
let user_list = get_user_list();
|
||||
let mut password: String = String::new();
|
||||
match user_list.get(&user_name) {
|
||||
Some(&p) => password = p,
|
||||
let mut password = match user_list.get(user) {
|
||||
Some(p) => p,
|
||||
None => return Err(Error::AuthenticationError),
|
||||
}
|
||||
};
|
||||
|
||||
let mut md5 = Md5::new();
|
||||
|
||||
// concat('md5', md5(concat(md5(concat(password, username)), random-salt)))
|
||||
// First pass
|
||||
md5.update(&password.as_bytes());
|
||||
md5.update(&user_name.as_bytes());
|
||||
md5.update(&user.as_bytes());
|
||||
let output = md5.finalize_reset();
|
||||
// Second pass
|
||||
md5.update(format!("{:x}", output));
|
||||
|
||||
Reference in New Issue
Block a user