| 1 | package hostactors |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "github.com/carlosframework/platform/internal/hostfloor" |
| 6 | "reflect" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | func (d Directory) checkMembership(ctx context.Context, old, next Roster) error { |
| 11 | if old.Publication == "" { |
| 12 | return nil |
| 13 | } |
| 14 | if next.FloorSHA256 != old.FloorSHA256 || next.Publication == "" { |
| 15 | return ErrRoster |
| 16 | } |
| 17 | changed := !reflect.DeepEqual(old.Boxes, next.Boxes) || !reflect.DeepEqual(old.Consoles, next.Consoles) || !reflect.DeepEqual(old.Regions, next.Regions) |
| 18 | if old.Publication == "preparing" { |
| 19 | if changed { |
| 20 | return ErrRoster |
| 21 | } |
| 22 | return nil |
| 23 | } |
| 24 | if old.Publication != "published" || next.Publication != "published" { |
| 25 | return ErrRoster |
| 26 | } |
| 27 | if !changed { |
| 28 | return nil |
| 29 | } |
| 30 | f, err := hostfloor.Read(ctx, d.Store, d.PublicKey, d.Bucket) |
| 31 | if err != nil || f.Digest != old.FloorSHA256 { |
| 32 | return ErrRoster |
| 33 | } |
| 34 | e := ExactEvidence{PublicKey: d.PublicKey, Store: d.Store, Boxes: d.PrivateBoxReport} |
| 35 | for ref, b := range next.Boxes { |
| 36 | previous, exists := old.Boxes[ref] |
| 37 | if exists && !(previous.State != "active" && b.State == "active") { |
| 38 | continue |
| 39 | } |
| 40 | report, err := d.PrivateBoxReport(ctx, ref, b) |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | if err = VerifyReport(ctx, e, d.PublicKey, f, report, b.Enrollment, b.Cloud.InstanceID, time.Now()); err != nil { |
| 45 | return err |
| 46 | } |
| 47 | } |
| 48 | for id, c := range next.Consoles { |
| 49 | if previous, exists := old.Consoles[id]; exists && reflect.DeepEqual(previous, c) { |
| 50 | continue |
| 51 | } |
| 52 | report, err := e.ConsoleReport(ctx, id, c) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | if _, err := verifyCompute(ctx, Observed{Roster: next}, e, id, c, report); err != nil { |
| 57 | return err |
| 58 | } |
| 59 | if err = VerifyReport(ctx, e, d.PublicKey, f, report, c.Enrollment, id, time.Now()); err != nil { |
| 60 | return err |
| 61 | } |
| 62 | } |
| 63 | return nil |
| 64 | } |
| 65 | |