From 704b2534d4c138bcf14246b17ef23ad5a9e76f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Thu, 25 Apr 2024 15:56:14 +0200 Subject: [PATCH 1/6] gitignore --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index cb14a420..3b45deaf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,13 @@ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock Cargo.lock + +# editor configs +.vscode +.idea + +# nix stuff +.envrc +flake.nix +flake.lock +.direnv From 3fddf8baa3afbfd4d1566c3e2451f7c34c6a84d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Thu, 25 Apr 2024 15:56:34 +0200 Subject: [PATCH 2/6] Apply suggested clippy lints --- src/client.rs | 5 ++--- src/server.rs | 1 - src/utils.rs | 1 - tests/client_server.rs | 4 ++-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index add1ed5f..0d73fa32 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,7 +1,6 @@ use std::borrow::Cow; use std::num::NonZeroU32; -use base64; use rand::distributions::{Distribution, Uniform}; use rand::{rngs::OsRng, Rng}; use ring::digest::SHA256_OUTPUT_LEN; @@ -182,7 +181,7 @@ impl<'a> ServerFirst<'a> { let (client_proof, server_signature): ([u8; SHA256_OUTPUT_LEN], hmac::Tag) = find_proofs( &self.gs2header, &self.client_first_bare, - &server_first, + server_first, &salted_password, nonce, ); @@ -190,7 +189,7 @@ impl<'a> ServerFirst<'a> { "c={},r={},p={}", base64::encode(self.gs2header.as_bytes()), nonce, - base64::encode(&client_proof) + base64::encode(client_proof) ); Ok(ClientFinal { server_signature, diff --git a/src/server.rs b/src/server.rs index 37c4eea2..ff47a5f1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; -use base64; use rand::distributions::{Distribution, Uniform}; use rand::{rngs::OsRng, Rng}; use ring::digest::SHA256_OUTPUT_LEN; diff --git a/src/utils.rs b/src/utils.rs index b7c55507..024d1091 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,3 @@ -use base64; use ring::digest::{self, digest, SHA256_OUTPUT_LEN}; use ring::hmac::{self, Context, Key, HMAC_SHA256}; use ring::pbkdf2::{self, PBKDF2_HMAC_SHA256 as SHA256}; diff --git a/tests/client_server.rs b/tests/client_server.rs index 9f12e94a..f5400cb1 100644 --- a/tests/client_server.rs +++ b/tests/client_server.rs @@ -18,8 +18,8 @@ impl TestProvider { let adm_iterations = NonZeroU32::new(8192).unwrap(); let admin_password = hash_password("admin_password", adm_iterations, b"messy"); TestProvider { - user_password: user_password, - admin_password: admin_password, + user_password, + admin_password, } } } From ad390f537daba5ee5400dc2650a237fc302060c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Thu, 25 Apr 2024 16:01:34 +0200 Subject: [PATCH 3/6] Update dependencies --- Cargo.toml | 6 +++--- src/client.rs | 10 ++++++---- src/server.rs | 10 ++++++---- src/utils.rs | 4 +++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ecf849c..bfb31050 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ repository = "https://github.com/tomprogrammer/scram" version = "0.6.0" [dependencies] -base64 = "0.13.0" -rand = "0.8.0" -ring = "0.16.9" +base64 = "0.21.7" +rand = "0.8.5" +ring = "0.17.7" [badges] maintenance = { status = "actively-developed" } diff --git a/src/client.rs b/src/client.rs index 0d73fa32..3dcf0dc4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,8 @@ use std::borrow::Cow; use std::num::NonZeroU32; +use base64::engine::general_purpose::STANDARD as BASE64; +use base64::Engine; use rand::distributions::{Distribution, Uniform}; use rand::{rngs::OsRng, Rng}; use ring::digest::SHA256_OUTPUT_LEN; @@ -38,7 +40,7 @@ fn parse_server_first(data: &str) -> Result<(&str, Vec, NonZeroU32), Error> } }; let salt = match parts.next() { - Some(part) if &part.as_bytes()[..2] == b"s=" => base64::decode(part[2..].as_bytes()) + Some(part) if &part.as_bytes()[..2] == b"s=" => BASE64.decode(part[2..].as_bytes()) .map_err(|_| Error::Protocol(Kind::InvalidField(Field::Salt)))?, _ => { return Err(Error::Protocol(Kind::ExpectedField(Field::Salt))); @@ -60,7 +62,7 @@ fn parse_server_final(data: &str) -> Result, Error> { return Err(Error::Protocol(Kind::ExpectedField(Field::VerifyOrError))); } match &data[..2] { - "v=" => base64::decode(&data.as_bytes()[2..]) + "v=" => BASE64.decode(&data.as_bytes()[2..]) .map_err(|_| Error::Protocol(Kind::InvalidField(Field::VerifyOrError))), "e=" => Err(Error::Authentication(data[2..].to_string())), _ => Err(Error::Protocol(Kind::ExpectedField(Field::VerifyOrError))), @@ -187,9 +189,9 @@ impl<'a> ServerFirst<'a> { ); let client_final = format!( "c={},r={},p={}", - base64::encode(self.gs2header.as_bytes()), + BASE64.encode(self.gs2header.as_bytes()), nonce, - base64::encode(client_proof) + BASE64.encode(client_proof) ); Ok(ClientFinal { server_signature, diff --git a/src/server.rs b/src/server.rs index ff47a5f1..dc0abb58 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,7 @@ use std::borrow::Cow; +use base64::engine::general_purpose::STANDARD as BASE64; +use base64::Engine; use rand::distributions::{Distribution, Uniform}; use rand::{rngs::OsRng, Rng}; use ring::digest::SHA256_OUTPUT_LEN; @@ -194,7 +196,7 @@ impl<'a, P: AuthenticationProvider> ServerFirst<'a, P> { let server_first: Cow<'static, str> = format!( "r={},s={},i={}", nonce, - base64::encode(self.password_info.salt.as_slice()), + BASE64.encode(self.password_info.salt.as_slice()), self.password_info.iterations ) .into(); @@ -274,7 +276,7 @@ impl<'a, P: AuthenticationProvider> ClientFinal<'a, P> { /// Checks that the gs2header received from the client is the same as the one we've stored fn verify_header(&self, gs2header: &str) -> bool { - let server_gs2header = base64::encode(self.gs2header.as_bytes()); + let server_gs2header = BASE64.encode(self.gs2header.as_bytes()); server_gs2header == gs2header } @@ -292,7 +294,7 @@ impl<'a, P: AuthenticationProvider> ClientFinal<'a, P> { self.hashed_password.as_slice(), &self.nonce, ); - let proof = if let Ok(proof) = base64::decode(proof.as_bytes()) { + let proof = if let Ok(proof) = BASE64.decode(proof.as_bytes()) { proof } else { return Err(Error::Protocol(Kind::InvalidField(Field::Proof))); @@ -301,7 +303,7 @@ impl<'a, P: AuthenticationProvider> ClientFinal<'a, P> { return Ok(None); } - let server_signature_string = format!("v={}", base64::encode(server_signature.as_ref())); + let server_signature_string = format!("v={}", BASE64.encode(server_signature.as_ref())); Ok(Some(server_signature_string)) } } diff --git a/src/utils.rs b/src/utils.rs index 024d1091..30a85fac 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,5 @@ +use base64::engine::general_purpose::STANDARD as BASE64; +use base64::Engine; use ring::digest::{self, digest, SHA256_OUTPUT_LEN}; use ring::hmac::{self, Context, Key, HMAC_SHA256}; use ring::pbkdf2::{self, PBKDF2_HMAC_SHA256 as SHA256}; @@ -59,7 +61,7 @@ pub fn find_proofs( } let client_final_without_proof = - format!("c={},r={}", base64::encode(gs2header.as_bytes()), nonce); + format!("c={},r={}", BASE64.encode(gs2header.as_bytes()), nonce); let auth_message = [ client_first_bare.as_bytes(), b",", From 2e45f51d726835158a66511c05fb0b143ad2d5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Wed, 8 May 2024 11:27:24 +0200 Subject: [PATCH 4/6] Update `base64` dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bfb31050..4a3aee31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/tomprogrammer/scram" version = "0.6.0" [dependencies] -base64 = "0.21.7" +base64 = "0.22" rand = "0.8.5" ring = "0.17.7" From 6d7f400f232238ff9ce0bbaba7089d7bef52ebcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Wed, 8 May 2024 11:29:09 +0200 Subject: [PATCH 5/6] Fork the crate to scram-2 --- Cargo.toml | 8 ++------ src/lib.rs | 4 ++-- tests/client_server.rs | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a3aee31..428835d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] -authors = ["Thomas Bahn "] +authors = ["Thomas Bahn ", "Aljaž Mur Eržen "] description = "A SCRAM provider library." documentation = "https://docs.rs/scram" keywords = [ "scram", "authentication"] license = "MIT" -name = "scram" +name = "scram-2" readme = "README.md" repository = "https://github.com/tomprogrammer/scram" version = "0.6.0" @@ -13,7 +13,3 @@ version = "0.6.0" base64 = "0.22" rand = "0.8.5" ring = "0.17.7" - -[badges] -maintenance = { status = "actively-developed" } -travis-ci = { repository = "https://github.com/tomprogrammer/scram", branch = "master" } diff --git a/src/lib.rs b/src/lib.rs index a31cff57..fdbeb6ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ //! but processing server messages can result in failure. //! //! ``` rust,no_run -//! use scram::ScramClient; +//! use scram_2::ScramClient; //! //! // This function represents your I/O implementation. //! # #[allow(unused_variables)] @@ -79,7 +79,7 @@ //! if authentication was successful or not. //! //! ```rust,no_run -//! use scram::{ScramServer, AuthenticationStatus, AuthenticationProvider, PasswordInfo}; +//! use scram_2::{ScramServer, AuthenticationStatus, AuthenticationProvider, PasswordInfo}; //! //! // Create a dummy authentication provider //! struct ExampleProvider; diff --git a/tests/client_server.rs b/tests/client_server.rs index f5400cb1..1c02ff50 100644 --- a/tests/client_server.rs +++ b/tests/client_server.rs @@ -1,9 +1,9 @@ extern crate rand; extern crate ring; -extern crate scram; +extern crate scram_2; use ring::digest::SHA256_OUTPUT_LEN; -use scram::*; +use scram_2::*; use std::num::NonZeroU32; struct TestProvider { From 103f35fac202fdb4f100931636be33f8df430a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Wed, 8 May 2024 11:29:33 +0200 Subject: [PATCH 6/6] Version 0.7.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 428835d3..19141fda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" name = "scram-2" readme = "README.md" repository = "https://github.com/tomprogrammer/scram" -version = "0.6.0" +version = "0.7.0" [dependencies] base64 = "0.22"