forked from u-root/u-root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectors.go
58 lines (50 loc) · 1.46 KB
/
collectors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2019 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package measurement provides different collectors to hash files, disks, dmi info and cpuid info.
package measurement
import (
"encoding/json"
"fmt"
)
/*
* pcr number where all measurements taken by securelaunch pkg
* will be stored.
*/
const (
pcr = uint32(22)
)
/*
* all collectors (storage, dmi, cpuid, files) should satisfy this
* collectors get information and store the hash of that information in pcr
* owned by the tpm device.
*/
type Collector interface {
Collect() error
}
var supportedCollectors = map[string]func([]byte) (Collector, error){
"storage": NewStorageCollector,
"dmi": NewDmiCollector,
"files": NewFileCollector,
"cpuid": NewCPUIDCollector,
}
/*
* GetCollector calls the appropriate init handlers for a particular
* collector JSON object argument and returns a new Collector Interface.
* - error is returned if unmarshalling fails or an unsupported collector is
* passed as an argument.
*/
func GetCollector(config []byte) (Collector, error) {
var header struct {
Type string `json:"type"`
}
err := json.Unmarshal(config, &header)
if err != nil {
fmt.Printf("Measurement: Unmarshal error\n")
return nil, err
}
if init, ok := supportedCollectors[header.Type]; ok {
return init(config)
}
return nil, fmt.Errorf("unsupported collector %s", header.Type)
}