Path: redb-route/redb.Route.As2/As2ConnectionFactory.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.As2/As2ConnectionFactory.cs ---- using System.Security.Cryptography.X509Certificates; using redb.Route.Core; namespace redb.Route.As2; /// /// Describes an AS2 trading partner: our key material, the partner's certificate, identifiers and the /// agreed profile (algorithms, MDN mode). Registered by name in the route context registry and referenced /// from a URI via connectionFactory=name — so certificates never live in the URI. This mirrors the /// framework-wide ConnectionFactory pattern (RabbitMQ/Telegram/...). /// public sealed class As2ConnectionFactory { // ── Key material ───────────────────────────────────────────────────────── /// Our certificate incl. private key — signs outgoing messages and decrypts incoming ones. public X509Certificate2? OurCertificate { get; set; } /// Partner's public certificate — encrypts outgoing messages and verifies their signature. public X509Certificate2? PartnerCertificate { get; set; } // ── Identity ───────────────────────────────────────────────────────────── /// Our AS2 identifier (AS2-From). public string As2From { get; set; } = ""; /// Partner AS2 identifier (AS2-To). public string As2To { get; set; } = ""; /// Partner endpoint URL the producer POSTs to. public string PartnerUrl { get; set; } = ""; // ── Profile ────────────────────────────────────────────────────────────── /// Sign outgoing messages. Default true. public bool Sign { get; set; } = true; /// Encrypt outgoing messages. Default true. public bool Encrypt { get; set; } = true; /// Compress the payload. Default false. public bool Compress { get; set; } /// Signature digest algorithm. Default sha-256. public string SignAlg { get; set; } = "sha-256"; /// Encryption algorithm. Default aes-128-cbc. public string EncryptAlg { get; set; } = "aes-128-cbc"; /// MDN mode. Default . public As2MdnMode MdnMode { get; set; } = As2MdnMode.Sync; /// Require/produce a signed MDN. Default true. public bool SignedMdn { get; set; } = true; /// /// When true, a send whose MDN is negative, has a MIC mismatch, or lacks a required valid signature throws /// (the transfer is treated as not confirmed) instead of only logging. Default false: the outcome is /// surfaced on redbAs2.mdn* headers for the route to act on. /// public bool RequireValidMdn { get; set; } /// URL the partner posts asynchronous MDNs to (our receiver). public string? AsyncMdnUrl { get; set; } /// /// Receive side: the hosts (DNS names or IP literals, compared case-insensitively) an asynchronous MDN may be /// posted to. The address comes from the partner's Receipt-Delivery-Option header; a receipt is posted /// only when the message authenticated, is , and the /// address's host is listed here. Required for a receive endpoint whose is async. /// public IList AsyncMdnAllowedHosts { get; set; } = []; // ── Transport security ─────────────────────────────────────────────────── /// /// PFX certificate our receive server presents to the partner over TLS. Distinct from /// , which is the S/MIME key for the payload: one secures the /// connection, the other the message. Lives here so its password stays out of the route URI. /// public string? SslCertPath { get; set; } /// Password for . [Sensitive] public string? SslCertPassword { get; set; } /// /// Permits the legacy algorithms sha-1 (broken collision resistance) and 3des (a 64-bit block, /// SWEET32) for and . Only for a partner that still requires them; /// default false, so a new agreement does not inherit weak cryptography by copy and paste. /// public bool AllowLegacyAlgorithms { get; set; } /// /// Checks the agreement; throws naming and what is /// missing or wrong: both identifiers, supported (and, unless allowed, non-legacy) algorithms, our certificate with /// its private key and the partner's certificate wherever something is signed or encrypted, and absolute http(s) /// URLs. Every endpoint naming the factory calls it when it starts; what only one side needs (a partner URL on a /// send, receipt hosts on an async receive) that side checks itself. /// public void Validate(string name) => As2Profile.From(this).Validate($"AS2 connection factory '{name}'"); }