tauri_macos_sign/
certificate.rsuse anyhow::{Context, Result};
use apple_codesign::create_self_signed_code_signing_certificate;
use x509_certificate::{EcdsaCurve, KeyAlgorithm};
pub use apple_codesign::CertificateProfile;
pub struct SelfSignedCertificateRequest {
pub algorithm: String,
pub profile: CertificateProfile,
pub team_id: String,
pub person_name: String,
pub country_name: String,
pub validity_days: i64,
pub password: String,
}
pub fn generate_self_signed(request: SelfSignedCertificateRequest) -> Result<Vec<u8>> {
let algorithm = match request.algorithm.as_str() {
"ecdsa" => KeyAlgorithm::Ecdsa(EcdsaCurve::Secp256r1),
"ed25519" => KeyAlgorithm::Ed25519,
"rsa" => KeyAlgorithm::Rsa,
value => panic!("algorithm values should have been validated by arg parser: {value}"),
};
let validity_duration = chrono::Duration::days(request.validity_days);
let (cert, key_pair) = create_self_signed_code_signing_certificate(
algorithm,
request.profile,
&request.team_id,
&request.person_name,
&request.country_name,
validity_duration,
)?;
let pfx = p12::PFX::new(
&cert.encode_der()?,
&key_pair.to_pkcs8_one_asymmetric_key_der(),
None,
&request.password,
"code-signing",
)
.context("failed to create PFX structure")?;
let der = pfx.to_der();
Ok(der)
}