@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use super::dkim::Algorithm;
|
||||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use jmap_client::client::Credentials;
|
||||
use mail_parser::DateTime;
|
||||
@@ -44,6 +45,11 @@ pub enum Commands {
|
||||
#[clap(subcommand)]
|
||||
Group(GroupCommands),
|
||||
*/
|
||||
|
||||
/// Manage DKIM signatures
|
||||
#[clap(subcommand)]
|
||||
Dkim(DkimCommands),
|
||||
|
||||
/// Import JMAP accounts and Maildir/mbox mailboxes
|
||||
#[clap(subcommand)]
|
||||
Import(ImportCommands),
|
||||
@@ -345,6 +351,27 @@ pub enum DomainCommands {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum DkimCommands {
|
||||
/// Create DKIM signature
|
||||
Create {
|
||||
/// Algorithm to use
|
||||
algorithm: Algorithm,
|
||||
/// Domain name for which to create
|
||||
domain: String,
|
||||
/// Id
|
||||
signature_id: Option<String>,
|
||||
/// Selector
|
||||
selector: Option<String>,
|
||||
},
|
||||
|
||||
/// Get DKIM public key
|
||||
GetPublicKey {
|
||||
/// Signature id
|
||||
signature_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum ImportCommands {
|
||||
/// Import messages and folders
|
||||
|
||||
70
crates/cli/src/modules/dkim.rs
Normal file
70
crates/cli/src/modules/dkim.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use super::cli::{Client, DkimCommands};
|
||||
use clap::ValueEnum;
|
||||
use reqwest::Method;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ValueEnum)]
|
||||
pub enum Algorithm {
|
||||
/// RSA
|
||||
#[default]
|
||||
Rsa,
|
||||
/// ED25519
|
||||
Ed25519,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
|
||||
struct DkimSignature {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
|
||||
pub algorithm: Algorithm,
|
||||
|
||||
pub domain: String,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub selector: Option<String>,
|
||||
}
|
||||
|
||||
impl DkimCommands {
|
||||
pub async fn exec(self, client: Client) {
|
||||
match self {
|
||||
DkimCommands::Create {
|
||||
signature_id,
|
||||
algorithm,
|
||||
domain,
|
||||
selector,
|
||||
} => {
|
||||
let signature_req = DkimSignature {
|
||||
id: signature_id,
|
||||
algorithm,
|
||||
domain: domain.clone(),
|
||||
selector,
|
||||
};
|
||||
client
|
||||
.http_request::<Value, _>(Method::POST, "/api/dkim", Some(signature_req))
|
||||
.await;
|
||||
eprintln!("Successfully created {algorithm:?} signature for domain {domain:?}");
|
||||
}
|
||||
DkimCommands::GetPublicKey { signature_id } => {
|
||||
let response = client
|
||||
.http_request::<Value, String>(
|
||||
Method::GET,
|
||||
&format!("/api/dkim/{signature_id}"),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
|
||||
eprintln!();
|
||||
eprintln!("Public DKIM key for signature {signature_id}: {response}");
|
||||
eprintln!();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub mod account;
|
||||
pub mod cli;
|
||||
pub mod database;
|
||||
pub mod dkim;
|
||||
pub mod domain;
|
||||
pub mod export;
|
||||
pub mod group;
|
||||
|
||||
Reference in New Issue
Block a user