aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-07-02 21:53:59 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-07-02 21:53:59 +0200
commitf903e653d59fa923210f5a583f7f8adc663a5dd5 (patch)
tree1af992782b624170e5b7c47f107675721bda5b17
parentf2156e21b830ebc3cfd0f9eab4e7e01112e023b4 (diff)
This doesn't work
-rw-r--r--Cargo.lock17
-rw-r--r--lockchain-core/src/users/auth.rs52
-rw-r--r--lockchain-http/src/handlers.rs51
-rw-r--r--lockchain-http/src/lib.rs8
-rw-r--r--lockchain-http/src/models/inputs.rs7
-rw-r--r--lockchain-http/src/models/responses.rs22
-rw-r--r--lockchain-server/src/main.rs2
7 files changed, 67 insertions, 92 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f4275fe..ae40581 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -470,15 +470,6 @@ dependencies = [
]
[[package]]
-name = "diceware"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "digest"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -659,11 +650,6 @@ dependencies = [
]
[[package]]
-name = "getopts"
-version = "0.2.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -850,7 +836,6 @@ dependencies = [
"bcrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "diceware 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"keybob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pam-auth 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1992,7 +1977,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum crypto-mac 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7afa06d05a046c7a47c3a849907ec303504608c927f4e85f7bfff22b7180d971"
"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
"checksum dbl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "920e117b69060a961c4164ccf83af573292cb167ccdd918950bcf0f5afc32c1c"
-"checksum diceware 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40ae2a903b5091f517c51370d36234a5ec344732b946ba8443850acb530753bf"
"checksum digest 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3cae2388d706b52f2f2f9afe280f9d768be36544bd71d1b8120cb34ea6450b55"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
@@ -2016,7 +2000,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
-"checksum getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "b900c08c1939860ce8b54dc6a89e26e00c04c380fd0e09796799bd7f12861e05"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6229ac66d3392dd83288fe04defd4b353354b15bbe07820d53dda063a736afcc"
"checksum hmac 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "efb895368093a17d136b1d9eecdb607c7aa038a452e646c74e37ded2da106285"
diff --git a/lockchain-core/src/users/auth.rs b/lockchain-core/src/users/auth.rs
index 538bd04..ad25757 100644
--- a/lockchain-core/src/users/auth.rs
+++ b/lockchain-core/src/users/auth.rs
@@ -6,7 +6,7 @@
// use nix::sys::wait::*;
// use nix::unistd::{fork, ForkResult};
-// use pam_auth::{self, Authenticator, PamError, Result as PamResult};
+use pam_auth::{self, Authenticator, PamError, Result as PamResult};
#[derive(Debug)]
pub enum AuthError {
@@ -30,7 +30,7 @@ pub enum AuthError {
/// yet due to issues in the `pam-auth` dependency.
#[allow(unused_variables)]
pub fn pam_authenticate(username: &str, password: &str) -> Result<(), AuthError> {
- Err(AuthError::FailedPAM)
+ // Err(AuthError::FailedPAM)
// match fork().map_err(|_| AuthError::FailedFork)? {
@@ -41,33 +41,35 @@ pub fn pam_authenticate(username: &str, password: &str) -> Result<(), AuthError>
// ForkResult::Child => {
// let mut auth = Authenticator::new("lockchain").ok_or(AuthError::FailedPAM)?;
- // use std::error::Error;
- // let service = "login";
+ use std::error::Error;
+ let service = "lockchain-core";
- // println!("Username: {}", username);
- // println!("Password: {}", password);
- // println!("Service: {}", service);
+ println!("Username: {}", username);
+ println!("Password: {}", password);
+ println!("Service: {}", service);
- // let mut auth = Authenticator::new(service).unwrap();
- // auth.set_credentials(username, password);
+ let mut auth = Authenticator::new(service).unwrap();
+ auth.set_credentials(username, password);
- // match auth.authenticate() {
- // Ok(()) => println!("authenticate() OK!"),
- // Err(e) => {
- // println!("authenticate() FAILED!");
- // println!("{}", e.description());
- // println!("{:#?}", e.cause());
- // }
- // }
+ match auth.authenticate() {
+ Ok(()) => println!("authenticate() OK!"),
+ Err(e) => {
+ println!("authenticate() FAILED!");
+ println!("{}", e.description());
+ println!("{:#?}", e.cause());
+ }
+ }
- // match auth.open_session() {
- // Ok(()) => println!("open_session() OK!"),
- // Err(e) => {
- // println!("open_session() FAILED!");
- // println!("{}", e.description());
- // println!("{:#?}", e.cause());
- // }
- // }
+ match auth.open_session() {
+ Ok(()) => println!("open_session() OK!"),
+ Err(e) => {
+ println!("open_session() FAILED!");
+ println!("{}", e.description());
+ println!("{:#?}", e.cause());
+ }
+ }
+
+ Ok(())
// auth.set_credentials(username, password);
// auth.authenticate().map_err(|_| AuthError::InvalidUser)?;
diff --git a/lockchain-http/src/handlers.rs b/lockchain-http/src/handlers.rs
index 369f888..2b220a2 100644
--- a/lockchain-http/src/handlers.rs
+++ b/lockchain-http/src/handlers.rs
@@ -174,43 +174,38 @@ where
}
/// PUT /authenticate
-pub fn authenticate<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
-where
- B: Body,
- V: Vault<B>,
-{
- Json(OperationFailed {
- reason: "Not implemented".into(),
- code: 255,
- })
-}
-
-/// PUT /de-authenticate
-pub fn deauthenticate<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+pub fn authenticate<B, V>(
+ (item, req): (Json<Authenticate>, HttpRequestState<ApiState<B, V>>),
+) -> impl Responder
where
B: Body,
V: Vault<B>,
{
- Json(OperationFailed {
- reason: "Not implemented".into(),
- code: 255,
- })
-}
+ use lockchain::users::*;
+ let Authenticate { username, password } = item.into_inner();
-/// PUT /de-authenticate
-pub fn register<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
-where
- B: Body,
- V: Vault<B>,
-{
- Json(OperationFailed {
- reason: "Not implemented".into(),
- code: 255,
+ Json(match pam_authenticate(&username, &password) {
+ Ok(()) => CarrierMessage {
+ error: Ok(()),
+ data: Some(TokenMessage {
+ username,
+ token: String::new(),
+ }),
+ },
+ Err(e) => CarrierMessage {
+ error: Err(e.into()),
+ data: Some(OperationFailed {
+ reason: "Meh!".into(),
+ code: 1,
+ }),
+ },
})
}
/// PUT /de-authenticate
-pub fn get_all_users<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+pub fn deauthenticate<B, V>(
+ (item, req): (Json<Deauthenticate>, HttpRequestState<ApiState<B, V>>),
+) -> impl Responder
where
B: Body,
V: Vault<B>,
diff --git a/lockchain-http/src/lib.rs b/lockchain-http/src/lib.rs
index 95d27d2..dfe1211 100644
--- a/lockchain-http/src/lib.rs
+++ b/lockchain-http/src/lib.rs
@@ -114,14 +114,6 @@ where
// Hand-in active auth token
r.method(http::Method::POST).with(handlers::deauthenticate)
})
- .resource("/users/register", |r| {
- // Register a new user (if allowed)
- r.method(http::Method::POST).with(handlers::register);
- })
- .resource("/users/", |r| {
- // Get all available users
- r.method(http::Method::GET).with(handlers::get_all_users);
- })
.resource("/api", |r| {
r.method(http::Method::GET).with(handlers::api_data);
}),
diff --git a/lockchain-http/src/models/inputs.rs b/lockchain-http/src/models/inputs.rs
index 172b204..4e1ae79 100644
--- a/lockchain-http/src/models/inputs.rs
+++ b/lockchain-http/src/models/inputs.rs
@@ -76,10 +76,3 @@ pub struct Authenticate {
pub struct Deauthenticate {
pub token: String,
}
-
-#[derive(Serialize, Deserialize)]
-pub struct Register {
- pub username: String,
- pub password: String,
- pub requested_role: Option<Role>,
-}
diff --git a/lockchain-http/src/models/responses.rs b/lockchain-http/src/models/responses.rs
index ac4e74b..436d3e6 100644
--- a/lockchain-http/src/models/responses.rs
+++ b/lockchain-http/src/models/responses.rs
@@ -1,7 +1,5 @@
-
-
-use lockchain::errors::Error as LockError;
use serde::{de::DeserializeOwned, Serialize};
+use std::error::Error;
/// A generic container that json/error wraps lockchain-types
///
@@ -9,8 +7,13 @@ use serde::{de::DeserializeOwned, Serialize};
/// to send both encrypted and cleartext data via the API endpoint, using
/// the same code.
#[derive(Serialize, Deserialize)]
-pub struct CarrierMessage<T: Serialize + DeserializeOwned> {
- pub error: Result<(), LockError>,
+pub struct CarrierMessage<T, E>
+where
+ T: Serialize + DeserializeOwned,
+ E: Error + Serialize + DeserializeOwned,
+{
+ #[serde(bound(deserialize = "E: Serialize + DeserializeOwned"))]
+ pub error: Result<(), E>,
#[serde(bound(deserialize = "T: Serialize + DeserializeOwned"))]
pub data: Option<T>,
}
@@ -22,6 +25,13 @@ pub struct OperationFailed {
pub code: u32,
}
+/// Message that returns a token
+#[derive(Serialize, Deserialize)]
+pub struct TokenMessage {
+ pub username: String,
+ pub token: String,
+}
+
/// **Returns** Api information
#[derive(Serialize, Deserialize)]
pub struct ApiInformation {
@@ -44,4 +54,4 @@ pub struct VaultCreateResponse {
pub name: String,
pub created: bool,
pub error: Option<String>,
-} \ No newline at end of file
+}
diff --git a/lockchain-server/src/main.rs b/lockchain-server/src/main.rs
index 1e4840f..f23cf71 100644
--- a/lockchain-server/src/main.rs
+++ b/lockchain-server/src/main.rs
@@ -6,7 +6,7 @@ extern crate lockchain_core as core;
extern crate lockchain_files as files;
extern crate lockchain_http as http;
-use core::{traits::*, EncryptedBody};
+use core::EncryptedBody;
use files::DataVault;
use http::{create_server, state::ApiState};