Skip to content

Upgrade dependencies #340

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

Merged
merged 3 commits into from
Apr 15, 2018
Merged
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
23 changes: 10 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
restore_registry: &RESTORE_REGISTRY
restore_cache:
key: registry

save_registry: &SAVE_REGISTRY
save_cache:
key: registry-{{ .BuildNum }}
paths:
- /usr/local/cargo/registry/index

- /usr/local/cargo/registry/index
deps_key: &DEPS_KEY
key: deps-1.19.0-{{ checksum "Cargo.lock" }}

key: deps-{{ checksum "~/rust-version" }}-{{ checksum "Cargo.lock" }}
restore_deps: &RESTORE_DEPS
restore_cache:
<<: *DEPS_KEY

save_deps: &SAVE_DEPS
save_cache:
<<: *DEPS_KEY
paths:
- target
- /usr/local/cargo/registry/cache
- target
- /usr/local/cargo/registry/cache

version: 2
jobs:
build:
working_directory: ~/build
docker:
- image: rust:1.20.0
- image: rust:1.21.0
environment:
RUSTFLAGS: -D warnings
- image: sfackler/rust-postgres-test:3
steps:
- checkout
- run: apt-get update
- run: DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends jq
- <<: *RESTORE_REGISTRY
- *RESTORE_REGISTRY
- run: cargo generate-lockfile
- <<: *SAVE_REGISTRY
- <<: *RESTORE_DEPS
- *SAVE_REGISTRY
- run: rustc --version > ~/rust-version
- *RESTORE_DEPS
- run: cargo test --all
- run: cargo test --manifest-path=postgres/Cargo.toml --features "$(cargo read-manifest --manifest-path=postgres/Cargo.toml | jq -r '.features|keys|map(select(. != "with-security-framework" and . != "with-schannel"))|join(" ")')"
- run: cargo test --manifest-path=tokio-postgres/Cargo.toml --all-features
- <<: *SAVE_DEPS
- *SAVE_DEPS
10 changes: 5 additions & 5 deletions postgres-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ repository = "https://github.com/sfackler/rust-postgres-protocol"
readme = "../README.md"

[dependencies]
base64 = "0.6"
base64 = "0.9"
byteorder = "1.0"
bytes = "0.4"
fallible-iterator = "0.1"
generic-array = "0.9"
hmac = "0.5"
generic-array = "0.11"
hmac = "0.6"
md5 = "0.3"
memchr = "1.0"
rand = "0.3"
memchr = "2.0"
rand = "0.4"
sha2 = "0.7"
stringprep = "0.1"
71 changes: 33 additions & 38 deletions postgres-protocol/src/authentication/sasl.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! SASL-based authentication support.

use base64;
use generic_array::GenericArray;
use generic_array::typenum::U32;
use generic_array::GenericArray;
use hmac::{Hmac, Mac};
use sha2::{Sha256, Digest};
use rand::{OsRng, Rng};
use sha2::{Digest, Sha256};
use std::fmt::Write;
use std::io;
use std::iter;
use std::mem;
use std::str;
use rand::{OsRng, Rng};
use stringprep;

const NONCE_LENGTH: usize = 24;
Expand All @@ -34,16 +34,15 @@ fn normalize(pass: &[u8]) -> Vec<u8> {
}

fn hi(str: &[u8], salt: &[u8], i: u32) -> GenericArray<u8, U32> {
let mut hmac = Hmac::<Sha256>::new(str)
.expect("HMAC is able to accept all key sizes");
let mut hmac = Hmac::<Sha256>::new_varkey(str).expect("HMAC is able to accept all key sizes");
hmac.input(salt);
hmac.input(&[0, 0, 0, 1]);
let mut prev = hmac.result().code();

let mut hi = GenericArray::<u8, U32>::clone_from_slice(&prev);

for _ in 1..i {
let mut hmac = Hmac::<Sha256>::new(str).expect("already checked above");
let mut hmac = Hmac::<Sha256>::new_varkey(str).expect("already checked above");
hmac.input(prev.as_slice());
prev = hmac.result().code();

Expand All @@ -56,7 +55,10 @@ fn hi(str: &[u8], salt: &[u8], i: u32) -> GenericArray<u8, U32> {
}

enum State {
Update { nonce: String, password: Vec<u8> },
Update {
nonce: String,
password: Vec<u8>,
},
Finish {
salted_password: GenericArray<u8, U32>,
auth_message: String,
Expand Down Expand Up @@ -134,9 +136,8 @@ impl ScramSha256 {
_ => return Err(io::Error::new(io::ErrorKind::Other, "invalid SCRAM state")),
};

let message = str::from_utf8(message).map_err(|e| {
io::Error::new(io::ErrorKind::InvalidInput, e)
})?;
let message =
str::from_utf8(message).map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;

let parsed = Parser::new(message).server_first_message()?;

Expand All @@ -151,7 +152,7 @@ impl ScramSha256 {

let salted_password = hi(&password, &salt, parsed.iteration_count);

let mut hmac = Hmac::<Sha256>::new(&salted_password)
let mut hmac = Hmac::<Sha256>::new_varkey(&salted_password)
.expect("HMAC is able to accept all key sizes");
hmac.input(b"Client Key");
let client_key = hmac.result().code();
Expand All @@ -165,8 +166,8 @@ impl ScramSha256 {

let auth_message = format!("n=,r={},{},{}", client_nonce, message, self.message);

let mut hmac = Hmac::<Sha256>::new(&stored_key)
.expect("HMAC is able to accept all key sizes");
let mut hmac =
Hmac::<Sha256>::new_varkey(&stored_key).expect("HMAC is able to accept all key sizes");
hmac.input(auth_message.as_bytes());
let client_signature = hmac.result();

Expand Down Expand Up @@ -197,9 +198,8 @@ impl ScramSha256 {
_ => return Err(io::Error::new(io::ErrorKind::Other, "invalid SCRAM state")),
};

let message = str::from_utf8(message).map_err(|e| {
io::Error::new(io::ErrorKind::InvalidInput, e)
})?;
let message =
str::from_utf8(message).map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;

let parsed = Parser::new(message).server_final_message()?;

Expand All @@ -218,18 +218,16 @@ impl ScramSha256 {
Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidInput, e)),
};

let mut hmac = Hmac::<Sha256>::new(&salted_password)
let mut hmac = Hmac::<Sha256>::new_varkey(&salted_password)
.expect("HMAC is able to accept all key sizes");
hmac.input(b"Server Key");
let server_key = hmac.result();

let mut hmac = Hmac::<Sha256>::new(&server_key.code())
let mut hmac = Hmac::<Sha256>::new_varkey(&server_key.code())
.expect("HMAC is able to accept all key sizes");
hmac.input(auth_message.as_bytes());
hmac.verify(&verifier).map_err(|_| io::Error::new(
io::ErrorKind::InvalidInput,
"SCRAM verification error",
))
hmac.verify(&verifier)
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "SCRAM verification error"))
}
}

Expand All @@ -252,9 +250,7 @@ impl<'a> Parser<'a> {
Some((i, c)) => {
let m = format!(
"unexpected character at byte {}: expected `{}` but got `{}",
i,
target,
c
i, target, c
);
Err(io::Error::new(io::ErrorKind::InvalidInput, m))
}
Expand Down Expand Up @@ -316,9 +312,8 @@ impl<'a> Parser<'a> {
'0'...'9' => true,
_ => false,
})?;
n.parse().map_err(
|e| io::Error::new(io::ErrorKind::InvalidInput, e),
)
n.parse()
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))
}

fn iteration_count(&mut self) -> io::Result<u32> {
Expand All @@ -329,12 +324,10 @@ impl<'a> Parser<'a> {

fn eof(&mut self) -> io::Result<()> {
match self.it.peek() {
Some(&(i, _)) => {
Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("unexpected trailing data at byte {}", i),
))
}
Some(&(i, _)) => Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("unexpected trailing data at byte {}", i),
)),
None => Ok(()),
}
}
Expand Down Expand Up @@ -419,10 +412,12 @@ mod test {
let nonce = "9IZ2O01zb9IgiIZ1WJ/zgpJB";

let client_first = "n,,n=,r=9IZ2O01zb9IgiIZ1WJ/zgpJB";
let server_first = "r=9IZ2O01zb9IgiIZ1WJ/zgpJBjx/oIRLs02gGSHcw1KEty3eY,s=fs3IXBy7U7+IvVjZ,i\
=4096";
let client_final = "c=biws,r=9IZ2O01zb9IgiIZ1WJ/zgpJBjx/oIRLs02gGSHcw1KEty3eY,p=AmNKosjJzS3\
1NTlQYNs5BTeQjdHdk7lOflDo5re2an8=";
let server_first =
"r=9IZ2O01zb9IgiIZ1WJ/zgpJBjx/oIRLs02gGSHcw1KEty3eY,s=fs3IXBy7U7+IvVjZ,i\
=4096";
let client_final =
"c=biws,r=9IZ2O01zb9IgiIZ1WJ/zgpJBjx/oIRLs02gGSHcw1KEty3eY,p=AmNKosjJzS3\
1NTlQYNs5BTeQjdHdk7lOflDo5re2an8=";
let server_final = "v=U+ppxD5XUKtradnv8e2MkeupiA8FU87Sg8CXzXHDAzw=";

let mut scram = ScramSha256::new_inner(password.as_bytes(), nonce.to_string()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion postgres-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ with-time = ["time"]
with-uuid = ["uuid"]

[dependencies]
hex = "0.2"
hex = "0.3"
fallible-iterator = "0.1.3"
phf = "=0.7.21"
postgres-protocol = { version = "0.3", path = "../postgres-protocol" }
Expand Down
4 changes: 2 additions & 2 deletions postgres-shared/src/types/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use self::serde_json::Value;
use std::error::Error;
use std::io::{Read, Write};

use types::{FromSql, ToSql, IsNull, Type, JSON, JSONB};
use types::{FromSql, IsNull, ToSql, Type, JSON, JSONB};

impl FromSql for Value {
fn from_sql(ty: &Type, mut raw: &[u8]) -> Result<Value, Box<Error + Sync + Send>> {
Expand All @@ -23,7 +23,7 @@ impl FromSql for Value {
}

impl ToSql for Value {
fn to_sql(&self, ty: &Type, mut out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
if *ty == JSONB {
out.push(1);
}
Expand Down
2 changes: 1 addition & 1 deletion postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ postgres-protocol = { version = "0.3.0", path = "../postgres-protocol" }
postgres-shared = { version = "0.4.1", path = "../postgres-shared" }

[dev-dependencies]
hex = "0.2"
hex = "0.3"
url = "1.0"

bit-vec = "0.4"
Expand Down