2021-11-10 09:53:37 +00:00
|
|
|
#![forbid(non_ascii_idents)]
|
2021-07-05 08:00:13 +00:00
|
|
|
#![allow(clippy::nonstandard_macro_braces)]
|
2021-05-13 17:32:29 +00:00
|
|
|
use chrono::prelude::*;
|
2021-06-08 20:23:46 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-05-13 17:32:29 +00:00
|
|
|
use std::collections::HashSet;
|
2022-02-20 18:08:19 +00:00
|
|
|
use std::fmt;
|
2021-05-09 09:52:53 +00:00
|
|
|
|
2021-06-08 20:23:46 +00:00
|
|
|
pub mod opaque;
|
|
|
|
|
2022-02-20 18:08:19 +00:00
|
|
|
/// The messages for the 3-step OPAQUE and simple login process.
|
2021-06-16 17:12:41 +00:00
|
|
|
pub mod login {
|
|
|
|
use super::*;
|
|
|
|
|
2021-06-23 18:33:36 +00:00
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ServerData {
|
|
|
|
pub username: String,
|
|
|
|
pub server_login: opaque::server::login::ServerLogin,
|
|
|
|
}
|
|
|
|
|
2021-06-16 17:12:41 +00:00
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ClientLoginStartRequest {
|
|
|
|
pub username: String,
|
|
|
|
pub login_start_request: opaque::server::login::CredentialRequest,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ServerLoginStartResponse {
|
2021-06-23 18:33:36 +00:00
|
|
|
/// Base64, encrypted ServerData to be passed back to the server.
|
|
|
|
pub server_data: String,
|
2021-06-16 17:12:41 +00:00
|
|
|
pub credential_response: opaque::client::login::CredentialResponse,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ClientLoginFinishRequest {
|
2021-06-23 18:33:36 +00:00
|
|
|
/// Encrypted ServerData from the previous step.
|
|
|
|
pub server_data: String,
|
2021-06-16 17:12:41 +00:00
|
|
|
pub credential_finalization: opaque::client::login::CredentialFinalization,
|
|
|
|
}
|
2022-02-20 18:08:19 +00:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ClientSimpleLoginRequest {
|
|
|
|
pub username: String,
|
|
|
|
pub password: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for ClientSimpleLoginRequest {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_struct("ClientSimpleLoginRequest")
|
|
|
|
.field("username", &self.username)
|
|
|
|
.field("password", &"***********")
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ServerLoginResponse {
|
|
|
|
pub token: String,
|
|
|
|
#[serde(rename = "refreshToken", skip_serializing_if = "Option::is_none")]
|
|
|
|
pub refresh_token: Option<String>,
|
|
|
|
}
|
2021-06-16 17:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The messages for the 3-step OPAQUE registration process.
|
2021-06-24 16:23:23 +00:00
|
|
|
/// It is used to reset a user's password.
|
2021-06-16 17:12:41 +00:00
|
|
|
pub mod registration {
|
|
|
|
use super::*;
|
|
|
|
|
2021-06-23 18:33:36 +00:00
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ServerData {
|
|
|
|
pub username: String,
|
|
|
|
}
|
|
|
|
|
2021-06-16 17:12:41 +00:00
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ClientRegistrationStartRequest {
|
|
|
|
pub username: String,
|
|
|
|
pub registration_start_request: opaque::server::registration::RegistrationRequest,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ServerRegistrationStartResponse {
|
2021-06-23 18:33:36 +00:00
|
|
|
/// Base64, encrypted ServerData to be passed back to the server.
|
|
|
|
pub server_data: String,
|
2021-06-16 17:12:41 +00:00
|
|
|
pub registration_response: opaque::client::registration::RegistrationResponse,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ClientRegistrationFinishRequest {
|
2021-06-23 18:33:36 +00:00
|
|
|
/// Encrypted ServerData from the previous step.
|
|
|
|
pub server_data: String,
|
2021-06-16 17:12:41 +00:00
|
|
|
pub registration_upload: opaque::server::registration::RegistrationUpload,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 18:08:19 +00:00
|
|
|
/// The messages for the 3-step OPAQUE registration process.
|
|
|
|
/// It is used to reset a user's password.
|
|
|
|
pub mod password_reset {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ServerPasswordResetResponse {
|
|
|
|
#[serde(rename = "userId")]
|
|
|
|
pub user_id: String,
|
|
|
|
pub token: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 17:32:29 +00:00
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
pub struct JWTClaims {
|
|
|
|
pub exp: DateTime<Utc>,
|
2021-05-20 15:40:30 +00:00
|
|
|
pub iat: DateTime<Utc>,
|
2021-05-13 17:32:29 +00:00
|
|
|
pub user: String,
|
|
|
|
pub groups: HashSet<String>,
|
|
|
|
}
|