use core::time::Duration;
use crate::cert::{
CertRules, CertSignature as Sig, ExtendedKeyUsage as Eku, Extension as X, KeyUsage, SanRules,
SubjectRules,
};
use crate::ids::{CipherSuite as C, NamedGroup as G, SignatureScheme as S};
use crate::profile::{Allowed, Curve, KeyRule, Level, Profile, Revocation, VersionRules};
const HOURS_48: Duration = Duration::from_secs(48 * 3600);
const TR03116_TLS12_SUITES_MUST: &[C] =
&[C::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, C::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256];
const TR03116_TLS12_SUITES_SHOULD: &[C] =
&[C::TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, C::TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384];
const TR03116_TLS12_GROUPS: Allowed<G> = Allowed::Only {
required: &[G::SECP256R1, G::BRAINPOOLP256R1, G::BRAINPOOLP384R1],
optional: &[G::BRAINPOOLP512R1, G::SECP384R1],
};
const TR03116_TLS12_SIGS: Allowed<S> = Allowed::Only {
required: &[S::ECDSA_SECP256R1_SHA256, S::ECDSA_SECP384R1_SHA384, S::ECDSA_SECP521R1_SHA512],
optional: &[],
};
const TR03116_TLS13_SUITES_MUST: &[C] = &[C::TLS_AES_128_GCM_SHA256];
const TR03116_TLS13_SUITES_SHOULD: &[C] = &[C::TLS_AES_256_GCM_SHA384, C::TLS_AES_128_CCM_SHA256];
const TR03116_TLS13_GROUPS: Allowed<G> = Allowed::Only {
required: &[G::BRAINPOOLP256R1_TLS13, G::BRAINPOOLP384R1_TLS13, G::SECP256R1],
optional: &[G::BRAINPOOLP512R1_TLS13, G::SECP384R1],
};
const TR03116_TLS13_SIGS: Allowed<S> = Allowed::Only {
required: &[
S::ECDSA_BRAINPOOLP256R1TLS13_SHA256,
S::ECDSA_BRAINPOOLP384R1TLS13_SHA384,
S::ECDSA_BRAINPOOLP512R1TLS13_SHA512,
S::ECDSA_SECP256R1_SHA256,
S::ECDSA_SECP384R1_SHA384,
],
optional: &[],
};
const TR03116_TLS13_CERT_SIGS: Allowed<S> = Allowed::Only {
required: &[
S::ECDSA_BRAINPOOLP256R1TLS13_SHA256,
S::ECDSA_BRAINPOOLP384R1TLS13_SHA384,
S::ECDSA_BRAINPOOLP512R1TLS13_SHA512,
],
optional: &[],
};
const SM_PKI_TLS_CERT: CertRules = CertRules {
keys: Allowed::Only { required: &[KeyRule::Ec(Curve::BrainpoolP256r1)], optional: &[] },
signatures: Allowed::Only { required: &[], optional: &[Sig::EcdsaSha256, Sig::EcdsaSha384] },
max_validity_days: None,
extensions: Allowed::Only {
required: &[
X::AuthorityKeyIdentifier,
X::SubjectKeyIdentifier,
X::KeyUsage,
X::CertificatePolicies,
X::IssuerAltName,
X::BasicConstraints,
X::ExtendedKeyUsage,
X::CrlDistributionPoints,
],
optional: &[X::SubjectAltName],
},
critical: Some(&[X::KeyUsage, X::BasicConstraints, X::ExtendedKeyUsage]),
key_usage: &[KeyUsage::DigitalSignature],
extended_key_usage: Allowed::Only { required: &[Eku::ClientAuth], optional: &[Eku::ServerAuth] },
end_entity: true,
san: SanRules { wildcards: false, max_dns_names: Some(20), dns_name_for_server_auth: true, uris: None },
subject: SubjectRules {
organization: Some("SM-PKI-DE"),
organizational_unit: false,
common_name_contains: None,
},
};
const TR03116_TLS12: VersionRules = VersionRules {
support: Level::Must,
cipher_suites: Allowed::Only {
required: TR03116_TLS12_SUITES_MUST,
optional: TR03116_TLS12_SUITES_SHOULD,
},
groups: TR03116_TLS12_GROUPS,
signature_schemes: TR03116_TLS12_SIGS,
cert_signature_schemes: TR03116_TLS12_SIGS,
};
const TR03116_TLS13: VersionRules = VersionRules {
support: Level::Should,
cipher_suites: Allowed::Only {
required: TR03116_TLS13_SUITES_MUST,
optional: TR03116_TLS13_SUITES_SHOULD,
},
groups: TR03116_TLS13_GROUPS,
signature_schemes: TR03116_TLS13_SIGS,
cert_signature_schemes: TR03116_TLS13_CERT_SIGS,
};
pub const BSI_TR_03116_3: Profile = Profile {
id: "bsi-tr-03116-3",
name: "BSI TR-03116-3",
sources: &[
"BSI TR-03116-3, Stand 2025 (13.12.2024), Tab. 5, Kap. 4, Tab. 6–16",
"BSI TR-03109-4 1.2.1 (09.08.2017), Anhang A (CTLS end-user certificates)",
"BSI Certificate Policy SM-PKI 1.1.2 (25.01.2023), Anhang A",
],
tls12: Some(TR03116_TLS12),
tls13: Some(TR03116_TLS13),
cert: SM_PKI_TLS_CERT,
mutual_auth: true,
revocation: Revocation::CrlRequired,
max_session_lifetime: Some(HOURS_48),
encrypt_then_mac: Level::Must,
extended_master_secret: Level::Should,
renegotiation: Level::MustNot,
early_data: Level::MustNot,
sni: Level::May,
notes: &[
"§4.1.2: a session, resumptions included, ends after at most 48 hours; then a full handshake",
"§4.1.2: resumption, also RFC 5077 tickets, is allowed within that time; ticket keys rotated and destroyed",
"§4.2.1: clients announce curves as named curves; both sides use ec_point_formats (RFC 8422)",
"§4.2.2.2: no truncated HMAC; Encrypt-then-MAC is mandatory from 2025 (server picks GCM or uses EtM)",
"§4.3: TLS 1.3 handshake modes ECDHE, and PSK with ECDHE for resumption only",
"Tab. 5: the chain is signed with ECDSA on brainpoolP256r1/P384r1; every party must verify both",
],
};
pub const BDEW_AS4: Profile = Profile {
id: "bdew-as4",
name: "BDEW AS4",
sources: &[
"BDEW AS4-Profil 1.2 (01.04.2026, gültig ab 01.10.2026), Kap. 2.2.6.1, 2.3.4.4",
"BDEW Regelungen zum Übertragungsweg AS4 2.6 (01.04.2026), Kap. 3, 5",
"BSI TR-03116-3, Stand 2025 (13.12.2024), Kap. 4",
"BSI TR-03109-4 1.2.1 (09.08.2017), Tab. 11, Anhang A",
"BSI Certificate Policy SM-PKI 1.1.2 (25.01.2023), Kap. 4.9, Tab. 22, 23, Anhang A.7.1",
],
tls12: Some(VersionRules {
support: Level::Must,
cipher_suites: Allowed::Only {
required: &[
C::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
C::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
C::TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
C::TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
],
optional: &[],
},
..TR03116_TLS12
}),
tls13: Some(VersionRules {
support: Level::Should,
cipher_suites: Allowed::Only {
required: &[C::TLS_AES_128_GCM_SHA256, C::TLS_AES_256_GCM_SHA384, C::TLS_AES_128_CCM_SHA256],
optional: &[],
},
..TR03116_TLS13
}),
cert: CertRules {
max_validity_days: Some(731),
extensions: Allowed::Only {
required: &[
X::AuthorityKeyIdentifier,
X::SubjectKeyIdentifier,
X::KeyUsage,
X::CertificatePolicies,
X::SubjectAltName,
X::IssuerAltName,
X::BasicConstraints,
X::ExtendedKeyUsage,
X::CrlDistributionPoints,
],
optional: &[],
},
extended_key_usage: Allowed::Only { required: &[Eku::ServerAuth, Eku::ClientAuth], optional: &[] },
san: SanRules { uris: Some(1), ..SM_PKI_TLS_CERT.san },
subject: SubjectRules {
organization: Some("SM-PKI-DE"),
organizational_unit: true,
common_name_contains: Some(".EMT.MAK"),
},
..SM_PKI_TLS_CERT
},
sni: Level::Must,
notes: &[
"AS4-Profil 2.2.6.1: client authentication required; rules apply wherever TLS terminates",
"AS4-Profil 2.3.4.4: separate EC key pairs for TLS, signature and encryption, all from the SM-PKI",
"AS4-Profil 2.3.4.4: the MP-ID is in the subject and equals the PartyId",
"RzÜ AS4 5.2: the AS4 endpoint is the single URI in the SubjectAltName",
"CP SM-PKI A.7.1: no wildcards in the SubjectAltName",
"RzÜ AS4 5.4: CRL only; a CRL unreachable for 3 days means distrusting its CA until a new one is out",
"RzÜ AS4 5.3: publish the successor certificate at least 10 working days before expiry",
],
..BSI_TR_03116_3
};
const fn recommended<T>(items: &'static [T]) -> Allowed<T> {
Allowed::Only { required: &[], optional: items }
}
const TR02102_TLS13_SIGS: &[S] = &[
S::ECDSA_SECP256R1_SHA256,
S::ECDSA_SECP384R1_SHA384,
S::ECDSA_SECP521R1_SHA512,
S::ECDSA_BRAINPOOLP256R1TLS13_SHA256,
S::ECDSA_BRAINPOOLP384R1TLS13_SHA384,
S::ECDSA_BRAINPOOLP512R1TLS13_SHA512,
S::RSA_PSS_RSAE_SHA256,
S::RSA_PSS_RSAE_SHA384,
S::RSA_PSS_RSAE_SHA512,
S::RSA_PSS_PSS_SHA256,
S::RSA_PSS_PSS_SHA384,
S::RSA_PSS_PSS_SHA512,
];
const TR02102_TLS12_SIGS: &[S] = &[
S::ECDSA_SECP256R1_SHA256,
S::ECDSA_SECP384R1_SHA384,
S::ECDSA_SECP521R1_SHA512,
S::RSA_PSS_RSAE_SHA256,
S::RSA_PSS_RSAE_SHA384,
S::RSA_PSS_RSAE_SHA512,
S::RSA_PSS_PSS_SHA256,
S::RSA_PSS_PSS_SHA384,
S::RSA_PSS_PSS_SHA512,
];
pub const BSI_TR_02102_2: Profile = Profile {
id: "bsi-tr-02102-2",
name: "BSI TR-02102-2",
sources: &["BSI TR-02102-2, version 2026-01 (27.01.2026), Tab. 2–14"],
tls12: Some(VersionRules {
support: Level::May,
cipher_suites: recommended(&[
C::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
C::TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
C::TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
C::TLS_ECDHE_ECDSA_WITH_AES_256_CCM,
C::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
C::TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
C::TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
C::TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
C::TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
C::TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
C::TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
C::TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
C::TLS_DHE_RSA_WITH_AES_128_CCM,
C::TLS_DHE_RSA_WITH_AES_256_CCM,
C::TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
C::TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
]),
groups: recommended(&[
G::SECP256R1,
G::SECP384R1,
G::SECP521R1,
G::BRAINPOOLP256R1,
G::BRAINPOOLP384R1,
G::BRAINPOOLP512R1,
G::FFDHE3072,
G::FFDHE4096,
]),
signature_schemes: recommended(TR02102_TLS12_SIGS),
cert_signature_schemes: recommended(TR02102_TLS12_SIGS),
}),
tls13: Some(VersionRules {
support: Level::Should,
cipher_suites: recommended(&[
C::TLS_AES_128_GCM_SHA256,
C::TLS_AES_256_GCM_SHA384,
C::TLS_AES_128_CCM_SHA256,
]),
groups: recommended(&[
G::SECP256R1,
G::SECP384R1,
G::SECP521R1,
G::BRAINPOOLP256R1_TLS13,
G::BRAINPOOLP384R1_TLS13,
G::BRAINPOOLP512R1_TLS13,
G::FFDHE3072,
G::FFDHE4096,
]),
signature_schemes: recommended(TR02102_TLS13_SIGS),
cert_signature_schemes: recommended(TR02102_TLS13_SIGS),
}),
cert: CertRules {
keys: recommended(&[
KeyRule::Ec(Curve::P256),
KeyRule::Ec(Curve::P384),
KeyRule::Ec(Curve::P521),
KeyRule::Ec(Curve::BrainpoolP256r1),
KeyRule::Ec(Curve::BrainpoolP384r1),
KeyRule::Ec(Curve::BrainpoolP512r1),
KeyRule::RsaMin(3000),
]),
signatures: recommended(&[
Sig::EcdsaSha256,
Sig::EcdsaSha384,
Sig::EcdsaSha512,
Sig::RsaPssSha256,
Sig::RsaPssSha384,
Sig::RsaPssSha512,
]),
..CertRules::ANY
},
mutual_auth: false,
revocation: Revocation::Unspecified,
max_session_lifetime: None,
encrypt_then_mac: Level::Must,
extended_master_secret: Level::Should,
renegotiation: Level::May,
early_data: Level::ShouldNot,
sni: Level::May,
notes: &[
"Tab. 2: TLS 1.2 is recommended only until the end of 2031; prefer TLS 1.3",
"Tab. 3, 6: TLS_DHE_* suites and ffdhe groups in TLS 1.2 only until 2029",
"Tab. 10: classical (EC)DHE alone only until 2031; hybrid ML-KEM groups will follow once RFCs",
"left out: entries recommended only up to 2025 or 2026 (rsa_pkcs1, static DH, RSA_PSK, psk_ke)",
"left out: DSA and TLS_DHE_DSS (to 2029, not approved in FIPS 186-5); PSK suites (Tab. 5)",
"§3.3.4: no truncated HMAC, no Heartbeat, no compression; renegotiation only per RFC 5746",
"§3.5, §3.6: certificates per TR-02103; key lengths per TR-02102-1",
],
};
pub const ALL: &[Profile] = &[BDEW_AS4, BSI_TR_03116_3, BSI_TR_02102_2];
pub fn by_id(id: &str) -> Option<&'static Profile> {
ALL.iter().find(|p| p.id == id)
}