feat(transport): optional detached bundle signing with a pluggable key source (ScadaBridge#45)
Exports can now carry a detached ECDSA P-256 signature over the exact
manifest.json bytes in a new optional manifest.sig zip entry. The manifest
already pins the content hash, so a verified signature covers the whole
bundle, including the plaintext source environment the confirm step relies
on. Off by default (ScadaBridge:Transport:Signing): with the defaults,
exports are unsigned and imports accept signed and unsigned bundles.
- The bundle format does not change: bundleFormatVersion stays 1,
manifest.json and the AES-GCM associated data are untouched, and older
importers open entries by name and ignore manifest.sig. Three entries fit
within the default MaxBundleEntryCount of 4.
- Import policy runs after the content-hash check and before any passphrase
work. A signature that fails to verify against a trusted key is always
refused. RequireSignedBundles additionally refuses unsigned bundles and
bundles signed by an untrusted key. A refusal is BundleSignatureException
(Commons), shown on the UI upload step and on CLI preview/import.
- The signature status, key id and signer are recorded on BundleSession and
shown in the import wizard. They are also returned on PreviewBundleResult
and recorded on the BundleImported audit row. BundleExported records
Signed/SigningKeyId.
- Key material is pluggable. IBundleSigningKeySource and IBundleTrustStore
are TryAdd'd; the defaults read Signing:PrivateKey (meant to be a
${secret:} reference) and Signing:TrustedKeys. Key ids are SPKI
fingerprints. Startup validation rejects unparseable or non-P-256 keys.
- Compatibility proof: the checked-in fixtures pre-signing-plaintext and
pre-signing-encrypted were exported by origin/main 3ff463b6, before this
change, and are imported end to end with signing off and with signing
configured.
The design leaves key-per-env vs per-org, trust distribution and rotation,
and the production default for RequireSignedBundles open. These are listed
in Component-Transport.md.
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -935,6 +935,74 @@ public class TransportImportPageTests : BunitContext
|
||||
// widening the surface of the production class with test-only accessors.
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// ScadaBridge#45: a signature-policy refusal is shown as its own reason and is NOT
|
||||
/// counted as a wrong passphrase (the importer checks the signature before decrypting).
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Signature_rejection_shows_reason_without_counting_a_failed_unlock()
|
||||
{
|
||||
_importer.LoadAsync(Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<CancellationToken>(), Arg.Any<string?>())
|
||||
.Throws(new BundleSignatureException("Bundle is not signed, and this cluster requires signed bundles."));
|
||||
|
||||
var cut = Render<TransportImportPage>();
|
||||
await cut.InvokeAsync(() =>
|
||||
{
|
||||
SeedAtPassphraseStep(cut.Instance, new byte[] { 0x01, 0x02 });
|
||||
SetField(cut.Instance, "_passphrase", "any");
|
||||
});
|
||||
await cut.InvokeAsync(async () => await InvokeAsyncMethod(cut.Instance, "SubmitPassphraseAsync"));
|
||||
|
||||
Assert.Equal(0, GetField<int>(cut.Instance, "_failedUnlockAttempts"));
|
||||
var error = GetField<string?>(cut.Instance, "_errorMessage");
|
||||
Assert.NotNull(error);
|
||||
Assert.Contains("Bundle signature rejected", error);
|
||||
Assert.Contains("requires signed bundles", error);
|
||||
}
|
||||
|
||||
/// <summary>ScadaBridge#45: the upload step's manifest summary shows the bundle's signature status.</summary>
|
||||
/// <param name="status">The session's signature status.</param>
|
||||
/// <param name="expected">Text the Signature row must contain.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Theory]
|
||||
[InlineData(BundleSignatureStatus.Verified, "Verified")]
|
||||
[InlineData(BundleSignatureStatus.UntrustedKey, "untrusted key")]
|
||||
[InlineData(BundleSignatureStatus.Unsigned, "Unsigned")]
|
||||
public async Task Manifest_summary_shows_signature_status(BundleSignatureStatus status, string expected)
|
||||
{
|
||||
var cut = Render<TransportImportPage>();
|
||||
var session = BuildEncryptedSession();
|
||||
session = new BundleSession
|
||||
{
|
||||
SessionId = session.SessionId,
|
||||
Manifest = session.Manifest,
|
||||
DecryptedContent = session.DecryptedContent,
|
||||
ExpiresAt = session.ExpiresAt,
|
||||
SignatureStatus = status,
|
||||
SignerKeyId = status == BundleSignatureStatus.Unsigned ? null : "sha256:feed",
|
||||
SignerName = status == BundleSignatureStatus.Verified ? "dev-cluster" : null,
|
||||
};
|
||||
await cut.InvokeAsync(() =>
|
||||
{
|
||||
SeedAtPassphraseStep(cut.Instance, new byte[] { 0x01 });
|
||||
SetField(cut.Instance, "_step", TransportImportPage.ImportWizardStep.Upload);
|
||||
SetField(cut.Instance, "_session", session);
|
||||
});
|
||||
cut.Render();
|
||||
|
||||
var row = cut.Find("[data-testid=manifest-signature]");
|
||||
Assert.Contains(expected, row.TextContent);
|
||||
if (status == BundleSignatureStatus.Verified)
|
||||
{
|
||||
Assert.Contains("dev-cluster", row.TextContent);
|
||||
}
|
||||
if (status == BundleSignatureStatus.UntrustedKey)
|
||||
{
|
||||
Assert.Contains("sha256:feed", row.TextContent);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetField(object obj, string name, object? value)
|
||||
{
|
||||
var field = obj.GetType().GetField(
|
||||
|
||||
Reference in New Issue
Block a user