1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-09 04:22:45 +03:00

Deny missing docs in the config crates

This commit is contained in:
Quentin Gliech
2022-02-01 10:48:38 +01:00
parent 9af8820564
commit dd7449b92e
4 changed files with 45 additions and 4 deletions

View File

@@ -14,6 +14,7 @@
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![deny(clippy::all)] #![deny(clippy::all)]
#![deny(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)] #![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)] #![allow(clippy::module_name_repetitions)]

View File

@@ -12,11 +12,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Useful JSON Schema definitions
use schemars::{ use schemars::{
gen::SchemaGenerator, gen::SchemaGenerator,
schema::{InstanceType, NumberValidation, Schema, SchemaObject}, schema::{InstanceType, NumberValidation, Schema, SchemaObject},
}; };
/// A network port
pub fn port(_gen: &mut SchemaGenerator) -> Schema { pub fn port(_gen: &mut SchemaGenerator) -> Schema {
Schema::Object(SchemaObject { Schema::Object(SchemaObject {
instance_type: Some(InstanceType::Integer.into()), instance_type: Some(InstanceType::Integer.into()),
@@ -29,6 +32,7 @@ pub fn port(_gen: &mut SchemaGenerator) -> Schema {
}) })
} }
/// A network hostname
pub fn hostname(_gen: &mut SchemaGenerator) -> Schema { pub fn hostname(_gen: &mut SchemaGenerator) -> Schema {
Schema::Object(SchemaObject { Schema::Object(SchemaObject {
instance_type: Some(InstanceType::String.into()), instance_type: Some(InstanceType::String.into()),

View File

@@ -48,24 +48,51 @@ impl From<JsonWebKeySet> for JwksOrJwksUri {
} }
} }
/// Authentication method used by clients
#[derive(JsonSchema, Serialize, Deserialize, Clone, Debug)] #[derive(JsonSchema, Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "client_auth_method", rename_all = "snake_case")] #[serde(tag = "client_auth_method", rename_all = "snake_case")]
pub enum ClientAuthMethodConfig { pub enum ClientAuthMethodConfig {
/// `none`: No authentication
None, None,
ClientSecretBasic { client_secret: String },
ClientSecretPost { client_secret: String }, /// `client_secret_basic`: `client_id` and `client_secret` used as basic
ClientSecretJwt { client_secret: String }, /// authorization credentials
ClientSecretBasic {
/// The client secret
client_secret: String,
},
/// `client_secret_post`: `client_id` and `client_secret` sent in the
/// request body
ClientSecretPost {
/// The client secret
client_secret: String,
},
/// `client_secret_basic`: a `client_assertion` sent in the request body and
/// signed using the `client_secret`
ClientSecretJwt {
/// The client secret
client_secret: String,
},
/// `client_secret_basic`: a `client_assertion` sent in the request body and
/// signed by an asymetric key
PrivateKeyJwt(JwksOrJwksUri), PrivateKeyJwt(JwksOrJwksUri),
} }
/// An OAuth 2.0 client configuration
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ClientConfig { pub struct ClientConfig {
/// The client ID
pub client_id: String, pub client_id: String,
/// Authentication method used for this client
#[serde(flatten)] #[serde(flatten)]
pub client_auth_method: ClientAuthMethodConfig, pub client_auth_method: ClientAuthMethodConfig,
/// List of allowed redirect URIs
#[serde(default)] #[serde(default)]
pub redirect_uris: Vec<Url>, pub redirect_uris: Vec<Url>,
} }
@@ -75,6 +102,7 @@ pub struct ClientConfig {
pub struct InvalidRedirectUriError; pub struct InvalidRedirectUriError;
impl ClientConfig { impl ClientConfig {
#[doc(hidden)]
pub fn resolve_redirect_uri<'a>( pub fn resolve_redirect_uri<'a>(
&'a self, &'a self,
suggested_uri: &'a Option<Url>, suggested_uri: &'a Option<Url>,
@@ -85,7 +113,7 @@ impl ClientConfig {
) )
} }
pub fn check_redirect_uri<'a>( fn check_redirect_uri<'a>(
&self, &self,
redirect_uri: &'a Url, redirect_uri: &'a Url,
) -> Result<&'a Url, InvalidRedirectUriError> { ) -> Result<&'a Url, InvalidRedirectUriError> {
@@ -97,6 +125,7 @@ impl ClientConfig {
} }
} }
/// List of OAuth 2.0/OIDC clients config
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
#[serde(transparent)] #[serde(transparent)]
pub struct ClientsConfig(Vec<ClientConfig>); pub struct ClientsConfig(Vec<ClientConfig>);

View File

@@ -34,12 +34,14 @@ use tracing::info;
use super::ConfigurationSection; use super::ConfigurationSection;
/// Helps encrypting and decrypting data
#[derive(Clone)] #[derive(Clone)]
pub struct Encrypter { pub struct Encrypter {
aead: Arc<ChaCha20Poly1305>, aead: Arc<ChaCha20Poly1305>,
} }
impl Encrypter { impl Encrypter {
/// Creates an [`Encrypter`] out of an encryption key
#[must_use] #[must_use]
pub fn new(key: &[u8; 32]) -> Self { pub fn new(key: &[u8; 32]) -> Self {
let key = GenericArray::from_slice(key); let key = GenericArray::from_slice(key);
@@ -48,12 +50,14 @@ impl Encrypter {
Self { aead } Self { aead }
} }
/// Encrypt a payload
pub fn encrypt(&self, nonce: &[u8; 12], decrypted: &[u8]) -> anyhow::Result<Vec<u8>> { pub fn encrypt(&self, nonce: &[u8; 12], decrypted: &[u8]) -> anyhow::Result<Vec<u8>> {
let nonce = GenericArray::from_slice(&nonce[..]); let nonce = GenericArray::from_slice(&nonce[..]);
let encrypted = self.aead.encrypt(nonce, decrypted)?; let encrypted = self.aead.encrypt(nonce, decrypted)?;
Ok(encrypted) Ok(encrypted)
} }
/// Decrypts a payload
pub fn decrypt(&self, nonce: &[u8; 12], encrypted: &[u8]) -> anyhow::Result<Vec<u8>> { pub fn decrypt(&self, nonce: &[u8; 12], encrypted: &[u8]) -> anyhow::Result<Vec<u8>> {
let nonce = GenericArray::from_slice(&nonce[..]); let nonce = GenericArray::from_slice(&nonce[..]);
let encrypted = self.aead.decrypt(nonce, encrypted)?; let encrypted = self.aead.decrypt(nonce, encrypted)?;
@@ -86,6 +90,7 @@ pub struct KeyConfig {
key: KeyOrPath, key: KeyOrPath,
} }
/// Application secrets
#[serde_as] #[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct SecretsConfig { pub struct SecretsConfig {
@@ -104,6 +109,7 @@ pub struct SecretsConfig {
} }
impl SecretsConfig { impl SecretsConfig {
/// Derive a signing and verifying keystore out of the config
pub async fn key_store(&self) -> anyhow::Result<StaticKeystore> { pub async fn key_store(&self) -> anyhow::Result<StaticKeystore> {
let mut store = StaticKeystore::new(); let mut store = StaticKeystore::new();
@@ -158,6 +164,7 @@ impl SecretsConfig {
Ok(store) Ok(store)
} }
/// Derive an [`Encrypter`] out of the config
#[must_use] #[must_use]
pub fn encrypter(&self) -> Encrypter { pub fn encrypter(&self) -> Encrypter {
Encrypter::new(&self.encryption) Encrypter::new(&self.encryption)