Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 6 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
[package]
authors = ["Thomas Bahn <[email protected]>"]
authors = ["Thomas Bahn <[email protected]>", "Aljaž Mur Eržen <[email protected]>"]
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"
13 changes: 7 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,7 +40,7 @@ fn parse_server_first(data: &str) -> Result<(&str, Vec<u8>, 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)));
Expand All @@ -61,7 +62,7 @@ fn parse_server_final(data: &str) -> Result<Vec<u8>, 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))),
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
}

Expand All @@ -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)));
Expand All @@ -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))
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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",",
Expand Down
8 changes: 4 additions & 4 deletions tests/client_server.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
}
}
}
Expand Down