-
Notifications
You must be signed in to change notification settings - Fork 1
/
tcg2.go
146 lines (139 loc) · 5.14 KB
/
tcg2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package eventlog provides functions for reading PC Client event logs and various EventData they
// can carry.
package eventlog
import (
"bytes"
"fmt"
)
const (
// RIMLocationRaw specifies that the location data is the data itself.
RIMLocationRaw uint32 = iota
// RIMLocationURI specifies that the location data is a URI for where to fetch the data.
RIMLocationURI
// RIMLocationLocal specifies that the location data is a local UEFI device path.
RIMLocationLocal
// RIMLocationVariable specifies that the location data is a UEFI variable name in 16-byte EFIGUID
// followed by '\0\0'-terminated CHAR16 string of the variable name.
RIMLocationVariable
)
var (
// TcgSP800155Event3Signature is the Canonical Event Log event signature for an unmeasured
// informational event that directs the reader to reference measurements for the firmware and
// platform.
TcgSP800155Event3Signature = [...]byte{
'S', 'P', '8', '0', '0', '-', '1', '5', '5', ' ', 'E', 'v', 'e', 'n', 't', '3'}
)
// SP800155Event3 represents a TCG SP 800-155 Event3 event specified in the PC Client Platform
// Firmware Profile.
type SP800155Event3 struct {
PlatformManufacturerID uint32
ReferenceManifestGUID EfiGUID
PlatformManufacturerStr ByteSizedArray
PlatformModel ByteSizedArray
PlatformVersion ByteSizedArray
FirmwareManufacturerStr ByteSizedArray
FirmwareManufacturerID uint32
FirmwareVersion ByteSizedArray
RIMLocatorType uint32
RIMLocator Uint32SizedArray
PlatformCertLocatorType uint32
PlatformCertLocator Uint32SizedArray
}
// UnmarshalFromBytes reads a TCG SP 800-155 Event3 event from the whole of the input slice.
func (evt *SP800155Event3) UnmarshalFromBytes(data []byte) error {
r := bytes.NewBuffer(data)
if err := littleRead(r, "PlatformManufacturerID", &evt.PlatformManufacturerID); err != nil {
return err
}
if err := littleRead(r, "ReferenceManifestGuid", &evt.ReferenceManifestGUID); err != nil {
return err
}
if err := littleRead(r, "PlatformManufacturerStr", &evt.PlatformManufacturerStr); err != nil {
return err
}
if err := littleRead(r, "PlatformModel", &evt.PlatformModel); err != nil {
return err
}
if err := littleRead(r, "PlatformVersion", &evt.PlatformVersion); err != nil {
return err
}
if err := littleRead(r, "FirmwareManufacturerStr", &evt.FirmwareManufacturerStr); err != nil {
return err
}
if err := littleRead(r, "FirmwareManufacturerID", &evt.FirmwareManufacturerID); err != nil {
return err
}
if err := littleRead(r, "FirmwareVersion", &evt.FirmwareVersion); err != nil {
return err
}
if err := littleRead(r, "RIMLocatorType", &evt.RIMLocatorType); err != nil {
return err
}
if err := littleRead(r, "RIMLocator", &evt.RIMLocator); err != nil {
return err
}
if err := littleRead(r, "PlatformCertLocatorType", &evt.PlatformCertLocatorType); err != nil {
return err
}
if err := littleRead(r, "PlatformCertLocator", &evt.PlatformCertLocator); err != nil {
return err
}
if r.Len() > 0 {
return fmt.Errorf("%d bytes remaining of SP800155Event3. Want EOF", r.Len())
}
return nil
}
// MarshalToBytes writes the SP800155Event3 structure to its binary form and returns the byte array.
func (evt *SP800155Event3) MarshalToBytes() ([]byte, error) {
w := bytes.NewBuffer(TcgSP800155Event3Signature[:])
if err := littleWrite(w, "PlatformManufacturerID", evt.PlatformManufacturerID); err != nil {
return nil, err
}
if err := littleWrite(w, "ReferenceManifestGuid", &evt.ReferenceManifestGUID); err != nil {
return nil, err
}
if err := littleWrite(w, "PlatformManufacturerStr", &evt.PlatformManufacturerStr); err != nil {
return nil, err
}
if err := littleWrite(w, "PlatformModel", &evt.PlatformModel); err != nil {
return nil, err
}
if err := littleWrite(w, "PlatformVersion", &evt.PlatformVersion); err != nil {
return nil, err
}
if err := littleWrite(w, "FirmwareManufacturerStr", &evt.FirmwareManufacturerStr); err != nil {
return nil, err
}
if err := littleWrite(w, "FirmwareManufacturerID", evt.FirmwareManufacturerID); err != nil {
return nil, err
}
if err := littleWrite(w, "FirmwareVersion", &evt.FirmwareVersion); err != nil {
return nil, err
}
if err := littleWrite(w, "RIMLocatorType", evt.RIMLocatorType); err != nil {
return nil, err
}
if err := littleWrite(w, "RIMLocator", &evt.RIMLocator); err != nil {
return nil, err
}
if err := littleWrite(w, "PlatformCertLocatorType", evt.PlatformCertLocatorType); err != nil {
return nil, err
}
if err := littleWrite(w, "PlatformCertLocator", &evt.PlatformCertLocator); err != nil {
return nil, err
}
return w.Bytes(), nil
}