Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::registry::mapping::{
|
||||
ObjectResponse, RegistrySetResponse, ValidationResult, principal::validate_tenant_quota,
|
||||
};
|
||||
use common::config::smtp::auth::DkimSigners;
|
||||
use jmap_proto::error::set::SetError;
|
||||
use registry::schema::{enums::TenantStorageQuota, structs::DkimSignature};
|
||||
|
||||
pub(crate) async fn validate_dkim_signature(
|
||||
set: &RegistrySetResponse<'_>,
|
||||
key: &mut DkimSignature,
|
||||
old_key: Option<&DkimSignature>,
|
||||
) -> ValidationResult {
|
||||
let response = if old_key.is_none() {
|
||||
match validate_tenant_quota(
|
||||
set.server,
|
||||
set.access_token,
|
||||
TenantStorageQuota::MaxDkimKeys,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
return Ok(Err(err));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ObjectResponse::default()
|
||||
};
|
||||
|
||||
if old_key.is_none_or(|old_key| old_key.private_key() != key.private_key())
|
||||
&& let Err(err) = DkimSigners::default()
|
||||
.insert("example.com".to_string(), key.clone())
|
||||
.await
|
||||
{
|
||||
return Ok(Err(SetError::invalid_properties().with_description(
|
||||
format!("Failed to validate DKIM signature: {err}"),
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(Ok(response))
|
||||
}
|
||||
Reference in New Issue
Block a user