Download this file
| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "context" |
| 6 | "crypto/ed25519" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/hostactors" |
| 9 | "github.com/carlosframework/platform/internal/hostbox" |
| 10 | ) |
| 11 | |
| 12 | // ConfigureStopEvidence is called by the deployment ClaimFactory after it has |
| 13 | // built the guarded stop coordinator and enrolled the private box evidence key. |
| 14 | func ConfigureStopEvidence(ctx context.Context, c *ClaimStopCoordinator, directory hostactors.Directory, box, enrollment string, private ed25519.PrivateKey) error { |
| 15 | if c == nil || c.Now == nil || len(private) != ed25519.PrivateKeySize { |
| 16 | return ErrClaimStopUnavailable |
| 17 | } |
| 18 | roster, err := directory.Read(ctx) |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | actor, ok := roster.Roster.Boxes[box] |
| 23 | if !ok || actor.State != "active" || actor.Enrollment != enrollment || roster.Roster.RequestLimitNS != int64(hostbox.RequestLimit) || !bytes.Equal(actor.CensusPublicKey, private.Public().(ed25519.PublicKey)) { |
| 24 | return ErrClaimStopIdentity |
| 25 | } |
| 26 | fenced, err := directory.TerminationFence(ctx, roster, box, c.Now()) |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | if fenced { |
| 31 | return ErrClaimStopIdentity |
| 32 | } |
| 33 | c.EvidenceSigner = append(ed25519.PrivateKey(nil), private...) |
| 34 | c.RequestLimit = hostbox.RequestLimit |
| 35 | return nil |
| 36 | } |
| 37 | |