Updated dependencies to use u2f crate directly, and some style changes

This commit is contained in:
Daniel García
2019-01-04 00:25:38 +01:00
parent c8af62ed48
commit 5f49ecd7f3
7 changed files with 110 additions and 114 deletions

182
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -34,9 +34,9 @@ rmpv = "0.4.0"
chashmap = "2.2.0"
# A generic serialization/deserialization framework
serde = "1.0.83"
serde_derive = "1.0.83"
serde_json = "1.0.33"
serde = "1.0.84"
serde_derive = "1.0.84"
serde_json = "1.0.34"
# Logging
log = "0.4.6"
@@ -63,13 +63,13 @@ chrono = "0.4.6"
oath = "0.10.2"
# Data encoding library
data-encoding = "2.1.1"
data-encoding = "2.1.2"
# JWT library
jsonwebtoken = "5.0.1"
# U2F library
u2f = "0.1.2"
u2f = "0.1.4"
# Yubico Library
yubico = { version = "=0.4.0", features = ["online"], default-features = false }
@@ -103,8 +103,5 @@ rmp = { git = 'https://github.com/dani-garcia/msgpack-rust' }
lettre = { git = 'https://github.com/lettre/lettre', rev = 'c988b1760ad81' }
lettre_email = { git = 'https://github.com/lettre/lettre', rev = 'c988b1760ad81' }
# Version 0.1.2 from crates.io lacks a commit that fixes a certificate error
u2f = { git = 'https://github.com/wisespace-io/u2f-rs', rev = '75b9fa5afb4c5' }
# Allows optional libusb support
yubico = { git = 'https://github.com/dani-garcia/yubico-rs' }

View File

@@ -78,7 +78,7 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult {
};
let claims: InviteJWTClaims = decode_invite_jwt(&token)?;
if &claims.email == &data.Email {
if claims.email == data.Email {
user
} else {
err!("Registration email does not match invite email")

View File

@@ -287,23 +287,22 @@ struct EnableU2FData {
}
// This struct is copied from the U2F lib
// because challenge is not always sent
// to add an optional error code
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct RegisterResponseCopy {
pub registration_data: String,
pub version: String,
pub challenge: Option<String>,
pub error_code: Option<NumberOrString>,
pub client_data: String,
pub error_code: Option<NumberOrString>,
}
impl RegisterResponseCopy {
fn into_response(self, challenge: String) -> RegisterResponse {
fn into_response(self) -> RegisterResponse {
RegisterResponse {
registration_data: self.registration_data,
version: self.version,
challenge,
client_data: self.client_data,
}
}
@@ -336,7 +335,7 @@ fn activate_u2f(data: JsonUpcase<EnableU2FData>, headers: Headers, conn: DbConn)
err!("Error registering U2F token")
}
let response = response_copy.into_response(challenge.challenge.clone());
let response = response_copy.into_response();
let registration = U2F.register_response(challenge.clone(), response)?;
// TODO: Allow more than one U2F device

View File

@@ -68,12 +68,12 @@ struct Cached<R>(R, &'static str);
impl<R> Cached<R> {
fn long(r: R) -> Cached<R> {
// 7 days
Cached(r, "public, max-age=604800".into())
Cached(r, "public, max-age=604800")
}
fn short(r: R) -> Cached<R> {
// 10 minutes
Cached(r, "public, max-age=600".into())
Cached(r, "public, max-age=600")
}
}

View File

@@ -76,17 +76,17 @@ impl Error {
}
}
pub trait MapResult<S, E> {
fn map_res(self, msg: &str) -> Result<S, E>;
pub trait MapResult<S> {
fn map_res(self, msg: &str) -> Result<S, Error>;
}
impl<S, E: Into<Error>> MapResult<S, Error> for Result<S, E> {
impl<S, E: Into<Error>> MapResult<S> for Result<S, E> {
fn map_res(self, msg: &str) -> Result<S, Error> {
self.map_err(|e| e.into().with_msg(msg))
}
}
impl<E: Into<Error>> MapResult<(), Error> for Result<usize, E> {
impl<E: Into<Error>> MapResult<()> for Result<usize, E> {
fn map_res(self, msg: &str) -> Result<(), Error> {
self.and(Ok(())).map_res(msg)
}

View File

@@ -332,9 +332,9 @@ impl Config {
attachments_folder: get_env_or("ATTACHMENTS_FOLDER", format!("{}/{}", &df, "attachments")),
// icon_cache_ttl defaults to 30 days (30 * 24 * 60 * 60 seconds)
icon_cache_ttl: get_env_or("ICON_CACHE_TTL", 2592000u64),
icon_cache_ttl: get_env_or("ICON_CACHE_TTL", 2_592_000),
// icon_cache_negttl defaults to 3 days (3 * 24 * 60 * 60 seconds)
icon_cache_negttl: get_env_or("ICON_CACHE_NEGTTL", 259200u64),
icon_cache_negttl: get_env_or("ICON_CACHE_NEGTTL", 259_200),
private_rsa_key: format!("{}.der", &key),
private_rsa_key_pem: format!("{}.pem", &key),