Skip to content

Commit

Permalink
Use constant-time token verification in API (mimblewimble#1690)
Browse files Browse the repository at this point in the history
Fixes mimblewimble#1641. The size of the token can be leaked, even if we pad or cut user's input we can't make it indistinguishable form the normal case.
  • Loading branch information
hashmap authored and quentinlesceller committed Oct 9, 2018
1 parent 7e7697b commit 8ee8043
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ failure_derive = "0.1.1"
hyper = "0.12"
lazy_static = "1"
regex = "1"
ring = "0.13"
serde = "1"
serde_derive = "1"
serde_json = "1"
Expand Down
7 changes: 5 additions & 2 deletions api/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use futures::future::ok;
use hyper::header::{HeaderValue, AUTHORIZATION, WWW_AUTHENTICATE};
use hyper::{Body, Request, Response, StatusCode};
use ring::constant_time::verify_slices_are_equal;
use router::{Handler, HandlerObj, ResponseFuture};

// Basic Authentication Middleware
Expand All @@ -38,8 +39,10 @@ impl Handler for BasicAuthMiddleware {
req: Request<Body>,
mut handlers: Box<Iterator<Item = HandlerObj>>,
) -> ResponseFuture {
if req.headers().contains_key(AUTHORIZATION)
&& req.headers()[AUTHORIZATION] == self.api_basic_auth
if req.headers().contains_key(AUTHORIZATION) && verify_slices_are_equal(
req.headers()[AUTHORIZATION].as_bytes(),
&self.api_basic_auth.as_bytes(),
).is_ok()
{
handlers.next().unwrap().call(req, handlers)
} else {
Expand Down
1 change: 1 addition & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern crate hyper;
#[macro_use]
extern crate lazy_static;
extern crate regex;
extern crate ring;
extern crate serde;
#[macro_use]
extern crate serde_derive;
Expand Down

0 comments on commit 8ee8043

Please sign in to comment.