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 diff --git a/Cargo.toml b/Cargo.toml index 0ecf849c..19141fda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,15 @@ [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" +version = "0.7.0" [dependencies] -base64 = "0.13.0" -rand = "0.8.0" -ring = "0.16.9" - -[badges] -maintenance = { status = "actively-developed" } -travis-ci = { repository = "https://github.com/tomprogrammer/scram", branch = "master" } +base64 = "0.22" +rand = "0.8.5" +ring = "0.17.7" diff --git a/src/client.rs b/src/client.rs index add1ed5f..3dcf0dc4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,7 +1,8 @@ use std::borrow::Cow; use std::num::NonZeroU32; -use base64; +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; @@ -39,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))); @@ -61,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))), @@ -182,15 +183,15 @@ 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, ); 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/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/src/server.rs b/src/server.rs index 37c4eea2..dc0abb58 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; -use base64; +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; @@ -195,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(); @@ -275,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 } @@ -293,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))); @@ -302,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 b7c55507..30a85fac 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,5 @@ -use base64; +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}; @@ -60,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",", diff --git a/tests/client_server.rs b/tests/client_server.rs index 9f12e94a..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 { @@ -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, } } }