package host import ( "bytes" "context" "crypto/ed25519" "github.com/carlosframework/platform/internal/hostactors" "github.com/carlosframework/platform/internal/hostbox" ) // ConfigureStopEvidence is called by the deployment ClaimFactory after it has // built the guarded stop coordinator and enrolled the private box evidence key. func ConfigureStopEvidence(ctx context.Context, c *ClaimStopCoordinator, directory hostactors.Directory, box, enrollment string, private ed25519.PrivateKey) error { if c == nil || c.Now == nil || len(private) != ed25519.PrivateKeySize { return ErrClaimStopUnavailable } roster, err := directory.Read(ctx) if err != nil { return err } actor, ok := roster.Roster.Boxes[box] if !ok || actor.State != "active" || actor.Enrollment != enrollment || roster.Roster.RequestLimitNS != int64(hostbox.RequestLimit) || !bytes.Equal(actor.CensusPublicKey, private.Public().(ed25519.PublicKey)) { return ErrClaimStopIdentity } fenced, err := directory.TerminationFence(ctx, roster, box, c.Now()) if err != nil { return err } if fenced { return ErrClaimStopIdentity } c.EvidenceSigner = append(ed25519.PrivateKey(nil), private...) c.RequestLimit = hostbox.RequestLimit return nil }