Certificates
Check SM-PKI and BDEW AS4 TLS certificates from DER in Rust: brainpoolP256r1, extensions, MP-ID, endpoint URI, wildcards and validity, each by its table.
Usage
Enable the feature. It adds no dependency and no allocator:
utility-pki = { version = "0.1", features = ["x509"] }use utility_pki::profiles::BDEW_AS4;
use utility_pki::x509::Certificate;
let cert = Certificate::from_der(&der)?; // strict DER, never panics
let report = BDEW_AS4.check_certificate(&cert);
for v in report.violations() {
eprintln!("{v}");
}Check your own certificate before you deploy it, and the partner's after each handshake. A file is checked in one command (convert PEM with openssl x509 -in cert.pem -outform DER -out cert.der):
cargo run --example certificate --features x509 -- cert.derThe facts you get
| Method | Returns |
|---|---|
mp_id() | the OU, only if there is exactly one: compare it with the AS4 PartyId |
endpoint_uri() | the SubjectAltName URI, only if there is exactly one: the AS4 endpoint |
public_key() | PublicKey::Ec(Curve::BrainpoolP256r1), Rsa(bits), …; None if unknown |
validity_days() | notAfter − notBefore, rounded up |
signature() | the issuer's algorithm, e.g. CertSignature::EcdsaSha256 |
common_name(), organization() | the single CN or O |
dns_names(), uris() | every SubjectAltName entry of that type |
public_key() and validity_days() also fill the session check.
The rules
SM-PKI TLS certificate (BSI_TR_03116_3, every role)
| Rule | Source |
|---|---|
| X.509 v3, serial ≤ 20 octets | TR-03109-4 Tab. 15; RFC 5280 |
| Key id-ecPublicKey, named curve brainpoolP256r1 | TR-03116-3 Tab. 6; TR-03109-4 A.1.2 |
| Signed with ecdsa-with-SHA256 or -SHA384 | TR-03116-3 Tab. 5 |
| Exactly these extensions: AKI, SKI, KeyUsage, CertificatePolicies, IssuerAltName, BasicConstraints, ExtendedKeyUsage, CRLDistributionPoints, and SubjectAltName (not for the SMGW) | TR-03109-4 A.2, Tab. 18/19 |
| KeyUsage, BasicConstraints and ExtendedKeyUsage critical; the others not | TR-03109-4 A.2 |
| KeyUsage digitalSignature | TR-03109-4 Tab. 22 |
| cA = FALSE | TR-03109-4 Tab. 25 |
| ExtendedKeyUsage clientAuth; serverAuth allowed | TR-03109-4 Tab. 26 |
| No wildcards; ≤ 20 DNS names; a DNS name for server certificates | CP SM-PKI A.7.1 |
O = SM-PKI-DE | CP SM-PKI Tab. 20–27 |
AS4 market participant (BDEW_AS4), in addition
| Rule | Source |
|---|---|
| SubjectAltName required | TR-03109-4 Tab. 18 |
| ExtendedKeyUsage serverAuth and clientAuth | TR-03109-4 Tab. 26 (CTLS(EMT)) |
| Exactly one URI in SubjectAltName: the AS4 endpoint | RzÜ AS4 §5.2 |
| Exactly one OU: the MP-ID | CP SM-PKI Tab. 23; RzÜ AS4 §5.2 |
CN contains .EMT.MAK | CP SM-PKI Tab. 23 |
| Validity ≤ 2 years (731 days) | TR-03109-4 Tab. 11 |
TR-02102-2 (BSI_TR_02102_2)
Only keys (Tab. 14) and the issuer's signature algorithm (Tab. 12): ECDSA or RSA-PSS with SHA-2. PKCS#1 v1.5 was recommended only up to 2025. The rest of the certificate profile is TR-02103's, which is not encoded.
Always
These hold for every profile:
- RFC 5280: v3, serial ≤ 20 octets, no extension twice, notBefore ≤ notAfter.
- An unknown curve, signature algorithm or extension is a finding that carries its OID. It is never silently accepted.
The test PKI
The production profiles reject SM-Test-PKI certificates (O = SM-Test-PKI-DE). For onboarding, derive a test profile:
use utility_pki::profiles::BDEW_AS4;
use utility_pki::{CertRules, Profile, SubjectRules};
const AS4_TEST_PKI: Profile = Profile {
id: "bdew-as4-test",
cert: CertRules {
subject: SubjectRules { organization: Some("SM-Test-PKI-DE"), ..BDEW_AS4.cert.subject },
..BDEW_AS4.cert
},
..BDEW_AS4
};What it does not check
- Signatures, chains and revocation. These are your PKI stack's job. The check judges one certificate's content.
- The SubjectKeyIdentifier value. Only its presence is checked; recomputing it would need SHA-1.
- Policy OIDs. They differ per Sub-CA.
- The order of the DN attributes.
How the reader is hardened
- Strict DER only. It accepts only minimal definite lengths, no trailing bytes, the DER forms of BOOLEAN and INTEGER, and Zulu times. CN, O and OU must be UTF8String, PrintableString or IA5String. Anything else is a
ParseErrorwith its byte offset. - No recursion. It walks the fixed certificate schema, at most seven levels deep.
- No panics. It never indexes, CI scans the release build for panic paths, and the reader is fuzzed.
- Safe messages. Strings from the certificate are escaped in finding messages, so a hostile SAN cannot forge log lines.