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