oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package provisioner
4
5import (
6 "amadan.net/oficina/home/internal/operator"
7 "github.com/go-json-experiment/json"
8)
9
10type schemaTargetV2 struct {
11 InstallationTarget
12 SchemaProfile string `json:"schema_profile"`
13 SchemaManifestDigest string `json:"schema_manifest_digest"`
14}
15type schemaPlanV2 struct {
16 Version int `json:"version"`
17 Installation string `json:"installation"`
18 BaselineOperation string `json:"baseline_operation"`
19 Credential schemaTargetV2 `json:"credential"`
20 Directory schemaTargetV2 `json:"directory"`
21}
22
23// This decoder does not enroll, sign or persist a plan. The v1 journal refuses it.
24func decodeSchemaPlanV2(raw []byte) (schemaPlanV2, error) {
25 var p schemaPlanV2
26 if len(raw) == 0 || len(raw) > 64<<10 || json.Unmarshal(raw, &p, json.RejectUnknownMembers(true)) != nil || p.Version != 2 {
27 return schemaPlanV2{}, ErrRefused
28 }
29 old := InstallationPlan{1, p.Installation, p.BaselineOperation, p.Credential.InstallationTarget, p.Directory.InstallationTarget}
30 if !old.valid() || !operator.CanonicalToken(p.Installation) || p.Credential.SchemaProfile != "credential-current-v1" ||
31 (p.Directory.SchemaProfile != "directory-current-v1" && p.Directory.SchemaProfile != "directory-historical-empty-v1") ||
32 !validHex(p.Credential.SchemaManifestDigest, 64) || !validHex(p.Directory.SchemaManifestDigest, 64) {
33 return schemaPlanV2{}, ErrRefused
34 }
35 return p, nil
36}
37