utility-pki 0.1.0

TLS and certificate profiles of the German energy sector (BDEW AS4, BSI TR-03116-3, BSI TR-02102-2) as Rust data: check sessions, SM-PKI certificates and OpenSSL configurations
Documentation
  • Coverage
  • 100%
    331 out of 331 items documented6 out of 91 items with examples
  • Size
  • Source code size: 210.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.4 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • hupe1980/utility-pki
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hupe1980

utility-pki

TLS and certificate profiles of the German energy sector for Rust: BDEW AS4, BSI TR-03116-3 and BSI TR-02102-2, checkable and taken table by table from the primary texts.

CI License unsafe forbidden no_std

Website and guides · API reference · Background: AS4 and the SM-PKI

AS4 market communication and the smart-metering WAN have strict TLS rules, spread across the BSI technical guidelines, the SM-PKI certificate policy and the BDEW AS4 documents. utility-pki holds those rules as Rust data and checks four things against them, one call each:

You have Call You get
an OpenSSL server or proxy profile.openssl()? a ready openssl.cnf section, every name verified against OpenSSL
a TLS configuration profile.audit(&offer) what is required but missing, and what is offered but not allowed, per TLS version
a finished handshake profile.check(&session) every violation: version, suite, group, key, mutual TLS, Encrypt-then-MAC
a certificate (DER) profile.check_certificate(&cert) every SM-PKI and AS4 certificate rule it breaks, plus its MP-ID and endpoint URI
cargo add utility-pki --features x509

Check a handshake

use utility_pki::profiles::BDEW_AS4;
use utility_pki::{CipherSuite, Curve, NamedGroup, PublicKey, Session, TlsVersion};

let session = Session {
    group: Some(NamedGroup::BRAINPOOLP256R1),
    mutual_auth: true,
    peer_key: Some(PublicKey::Ec(Curve::BrainpoolP256r1)),
    ..Session::new(TlsVersion::TLS12, CipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
};
let report = BDEW_AS4.check(&session);
assert!(report.is_ok());
for violation in report.violations() {
    eprintln!("refusing: {violation}");
}

Check a certificate (x509 feature)

use utility_pki::profiles::BDEW_AS4;
use utility_pki::x509::Certificate;

let cert = Certificate::from_der(&der)?; // strict DER, never panics
for v in BDEW_AS4.check_certificate(&cert).violations() {
    eprintln!("{v}"); // "2 URIs in SubjectAltName, exactly 1 required (the AS4 endpoint)"
}
assert_eq!(cert.mp_id(), Some(party_id)); // the OU, only if there is exactly one

The check covers the following rules:

  • Key: ECDSA on brainpoolP256r1.
  • Extensions: exactly the set TR-03109-4 lists, with the right criticality.
  • KeyUsage and ExtendedKeyUsage, and cA = FALSE.
  • Subject: O = SM-PKI-DE, which refuses test-PKI certificates; for AS4, also the MP-ID in exactly one OU.
  • SubjectAltName: no wildcards; for AS4, exactly one endpoint URI.
  • Validity: at most two years for AS4.

Every rule →

Configure OpenSSL

$ cargo run --example openssl -- bdew-as4
MinProtocol = TLSv1.2
MaxProtocol = TLSv1.3
CipherString = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384
Ciphersuites = TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_AES_128_CCM_SHA256
Groups = brainpoolP256r1tls13:brainpoolP384r1tls13:secp256r1:brainpoolP256r1:brainpoolP384r1:brainpoolP512r1tls13:secp384r1:brainpoolP512r1
SignatureAlgorithms = ecdsa_brainpoolP256r1tls13_sha256:…:ecdsa_secp521r1_sha512
Options = ServerPreference,NoRenegotiation,EncryptThenMac,ExtendedMasterSecret

OpenSSL 3.2 or later is the common library that meets BDEW AS4. rustls has no CBC, CCM or Brainpool suites.

Profiles

Profile For Primary texts
BDEW_AS4 market communication over AS4 (electricity, gas) AS4-Profil 1.2, RzÜ AS4 2.6, TR-03116-3, TR-03109-4, CP SM-PKI
BSI_TR_03116_3 the Smart Metering PKI: WAN and market communication TR-03116-3 Stand 2025, TR-03109-4 1.2.1, CP SM-PKI 1.1.2
BSI_TR_02102_2 general TLS; the crypto baseline for IEC 62443-4-2 CR 4.3 TR-02102-2 2026-01

Profiles are const data. Derive your own with struct update, for example Profile { mutual_auth: true, ..BSI_TR_02102_2 }. The guides cover the details:

Design

  • Primary texts only. Each rule cites document, version and table. What cannot be verified is left out, not guessed.
  • MUST is not SHOULD. required and optional are kept apart, per TLS version. "Anything" must be written Allowed::Any, never an empty list.
  • Unknown never passes. An unreported value, an unknown curve or extension, bytes that are not strict DER: each is a finding or an error.
  • no_std, no allocator, no dependencies, no panics, with every feature. CI scans the release build for panic paths and fuzzes the DER reader.

utility-pki judges; it does not perform TLS, verify signatures or fetch CRLs. A passing check is evidence for your conformity assessment, not a certification. See the threat model and security policy.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Not affiliated with the BSI, the BDEW, the Bundesnetzagentur or the IEC.