oficina / home Public

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

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "bytes"
5 "crypto/elliptic"
6 "encoding/base64"
7
8 "amadan.net/oficina/home/internal/operator"
9 "amadan.net/oficina/home/roster"
10)
11
12// HOME_OPERATOR_MATERIAL: each role's own operator keys. The native command
13// (operator_command_linux.go) and the HTTP transport (operator_http.go) read
14// the same reviewed material.
15type credentialOperatorMaterial struct {
16 Version int `json:"version"`
17 Role string `json:"role"`
18 MAC string `json:"mac_key"`
19 Owner string `json:"owner_seed_key"`
20}
21type directoryOperatorMaterial struct {
22 Version int `json:"version"`
23 Role string `json:"role"`
24 MAC string `json:"mac_key"`
25 Owner string `json:"owner_seed_public"`
26 Provisioning string `json:"provisioning_key"`
27 Roster []roster.Key `json:"roster_keys"`
28}
29
30func operatorMAC(raw string) ([]byte, error) {
31 key, err := base64.StdEncoding.Strict().DecodeString(raw)
32 if err != nil || len(key) != 32 || base64.StdEncoding.EncodeToString(key) != raw || bytes.Equal(key, make([]byte, 32)) {
33 return nil, operator.ErrRefused
34 }
35 return key, nil
36}
37func operatorPublic(raw string) ([]byte, error) {
38 key, err := base64.RawURLEncoding.Strict().DecodeString(raw)
39 if err != nil || len(key) != 65 || base64.RawURLEncoding.EncodeToString(key) != raw {
40 return nil, operator.ErrRefused
41 }
42 x, _ := elliptic.Unmarshal(elliptic.P256(), key)
43 if x == nil {
44 return nil, operator.ErrRefused
45 }
46 return key, nil
47}
48func distinctOperatorKeys(keys [][]byte) bool {
49 seen := map[string]bool{}
50 for _, key := range keys {
51 if len(key) == 0 || seen[string(key)] {
52 return false
53 }
54 seen[string(key)] = true
55 }
56 return true
57}
58