mirror of
https://github.com/luxfi/mpc.git
synced 2026-09-24 00:26:24 +00:00
- lattice v7.0.2 -> v7.1.0: types package (ComputeTrustMode, ConfidentialIOLevel, WorkloadPrivacyClass) used by pkg/registry + pkg/attestation. Was on feat/lp-137-types branch; merged + tagged. - luxfi/hsm v1.1.2 -> v1.1.3: airgap factory cases (coldcard, foundation, keystone, ngrave, gridplus, ledger, trezor, yubihsm, nitrokey, pkcs11). Unblocks TestAirgapProvidersRoundTripFactory. - mattn/go-sqlite3 v2.0.3+incompatible -> v1.14.42: json1 default-on, fixes pkg/custody json_extract failures (no build-tag dance needed). - pkg/approval/factory_test.go: yubihsm now wantError=false (v1.1.3 exposes it), removes the v1.1.2 workaround comment. - cc/attest/verifier_test.go + pkg/hsm/hsm_test.go: pre-existing minor test cleanups bundled in (stub-panic and gcp/azure-stub assertions). Build + 36/36 packages pass. Standalone integration smoke (cmd/mpcd TestStandaloneSelfQuorum, -tags integration): PASS.
132 lines
3.8 KiB
Go
132 lines
3.8 KiB
Go
package approval
|
|
|
|
import (
|
|
"context"
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestFactory_AllProviders(t *testing.T) {
|
|
prevEnv := os.Getenv("MPC_ENV")
|
|
prevFlag := os.Getenv("MPC_LOCAL_APPROVAL")
|
|
t.Cleanup(func() {
|
|
os.Setenv("MPC_ENV", prevEnv)
|
|
os.Setenv("MPC_LOCAL_APPROVAL", prevFlag)
|
|
})
|
|
os.Setenv("MPC_ENV", "test")
|
|
os.Setenv("MPC_LOCAL_APPROVAL", "true")
|
|
|
|
cases := []struct {
|
|
name string
|
|
ptype string
|
|
config map[string]string
|
|
wantError bool
|
|
}{
|
|
{"local-dev", "local-dev", nil, false},
|
|
{"mldsa", "mldsa", nil, false},
|
|
{"safe", "safe-multisig", map[string]string{
|
|
"chain_id": "1", "safe_address": "0x1234567890abcdef1234567890abcdef12345678",
|
|
}, false},
|
|
{"webauthn", "webauthn", map[string]string{
|
|
"rpid": "lux.network",
|
|
"origins": "https://approvals.lux.network",
|
|
}, false},
|
|
{"ledger-enterprise", "ledger-enterprise", map[string]string{
|
|
"endpoint": "https://vault.example.com", "api_key": "k", "workspace": "w",
|
|
}, false},
|
|
{"ledger-device", "ledger-device", nil, false},
|
|
{"aws-kms", "aws-kms", map[string]string{"region": "us-east-1"}, false},
|
|
{"gcp-kms", "gcp-kms", nil, false},
|
|
{"azure-keyvault", "azure-keyvault", map[string]string{"vault_url": "https://x.vault.azure.net"}, false},
|
|
{"zymbit", "zymbit", map[string]string{"api_addr": "http://localhost:6789"}, false},
|
|
// yubihsm available since luxfi/hsm v1.1.3 (factory exposes the
|
|
// hardware-wallet/airgap/USB providers).
|
|
{"yubihsm", "yubihsm", map[string]string{}, false},
|
|
{"unknown", "fake", nil, true},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
p, err := NewProvider(tc.ptype, tc.config)
|
|
if tc.wantError {
|
|
if err == nil {
|
|
t.Fatal("want error, got nil")
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("NewProvider(%q): %v", tc.ptype, err)
|
|
}
|
|
if p == nil {
|
|
t.Fatal("NewProvider returned nil provider with no error")
|
|
}
|
|
if p.Provider() == "" {
|
|
t.Fatal("provider name is empty")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFactory_LocalDevForbiddenInProduction(t *testing.T) {
|
|
prevEnv := os.Getenv("MPC_ENV")
|
|
t.Cleanup(func() { os.Setenv("MPC_ENV", prevEnv) })
|
|
os.Setenv("MPC_ENV", "production")
|
|
|
|
if _, err := NewProvider("local-dev", nil); err == nil {
|
|
t.Fatal("NewProvider(local-dev) in production: want error")
|
|
} else if !strings.Contains(err.Error(), "forbidden in production") {
|
|
t.Fatalf("error %q does not contain 'forbidden in production'", err)
|
|
}
|
|
}
|
|
|
|
func TestCrossProvider_ApprovalDoesNotVerify(t *testing.T) {
|
|
prevEnv := os.Getenv("MPC_ENV")
|
|
prevFlag := os.Getenv("MPC_LOCAL_APPROVAL")
|
|
t.Cleanup(func() {
|
|
os.Setenv("MPC_ENV", prevEnv)
|
|
os.Setenv("MPC_LOCAL_APPROVAL", prevFlag)
|
|
})
|
|
os.Setenv("MPC_ENV", "test")
|
|
os.Setenv("MPC_LOCAL_APPROVAL", "true")
|
|
|
|
dev, err := NewLocalDev(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mldsa, err := NewMLDSA(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pq := mldsa.(*MLDSAProvider)
|
|
if err := pq.Enroll("alice", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Pre-seed local-dev with its own key for alice.
|
|
_, sk, _ := ed25519.GenerateKey(rand.Reader)
|
|
dev.(*LocalDevProvider).Enroll("alice", sk)
|
|
|
|
intent := newTestIntent("cross-provider attack")
|
|
devSig, err := dev.ApproveIntent(context.Background(), "alice", intent)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// dev-signed approval must NOT verify against mldsa provider.
|
|
ok, _ := mldsa.VerifyApproval(context.Background(), intent, devSig)
|
|
if ok {
|
|
t.Fatal("MLDSA verified a local-dev signature — provider boundary leak")
|
|
}
|
|
|
|
// Provider-name spoofing: claim the signature is from mldsa.
|
|
spoofed := devSig
|
|
spoofed.Provider = "mldsa"
|
|
spoofed.Algorithm = AlgorithmMLDSA65
|
|
ok, _ = mldsa.VerifyApproval(context.Background(), intent, spoofed)
|
|
if ok {
|
|
t.Fatal("MLDSA verified a spoofed local-dev signature — algorithm/key not checked")
|
|
}
|
|
}
|