2019-03-28 20:21:16 +00:00
|
|
|
// Copyright 2019 Google Inc.
|
|
|
|
//
|
|
|
|
// 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.
|
2019-03-28 20:29:24 +00:00
|
|
|
|
2019-03-28 20:21:16 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package attest
|
|
|
|
|
|
|
|
import (
|
2019-05-15 17:36:54 +00:00
|
|
|
"bytes"
|
|
|
|
"crypto/aes"
|
|
|
|
"crypto/cipher"
|
2019-03-28 20:21:16 +00:00
|
|
|
"crypto/rand"
|
2019-07-17 22:15:29 +00:00
|
|
|
"crypto/rsa"
|
2019-04-03 17:40:16 +00:00
|
|
|
"encoding/binary"
|
2019-03-28 20:21:16 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2019-04-03 17:40:16 +00:00
|
|
|
"io"
|
2019-07-17 22:15:29 +00:00
|
|
|
"math/big"
|
2019-03-28 20:21:16 +00:00
|
|
|
|
2019-04-03 17:40:16 +00:00
|
|
|
tpm1 "github.com/google/go-tpm/tpm"
|
2019-03-28 20:21:16 +00:00
|
|
|
tpmtbs "github.com/google/go-tpm/tpmutil/tbs"
|
|
|
|
)
|
|
|
|
|
2019-04-03 17:40:16 +00:00
|
|
|
var wellKnownAuth [20]byte
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
type windowsTPM struct {
|
2019-03-28 20:21:16 +00:00
|
|
|
version TPMVersion
|
|
|
|
pcp *winPCP
|
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (*windowsTPM) isTPMBase() {}
|
|
|
|
|
2019-03-28 20:21:16 +00:00
|
|
|
func probeSystemTPMs() ([]probedTPM, error) {
|
|
|
|
// Windows systems appear to only support a single abstracted TPM.
|
|
|
|
// If we fail to initialize the Platform Crypto Provider, we assume
|
|
|
|
// a TPM is not present.
|
|
|
|
pcp, err := openPCP()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
defer pcp.Close()
|
|
|
|
|
|
|
|
info, err := pcp.TPMInfo()
|
|
|
|
if err != nil {
|
2019-04-11 17:20:46 +00:00
|
|
|
return nil, fmt.Errorf("TPMInfo() failed: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var out probedTPM
|
|
|
|
out.Version, err = tbsConvertVersion(info.TBSInfo)
|
|
|
|
if err != nil {
|
2019-04-11 17:20:46 +00:00
|
|
|
return nil, fmt.Errorf("tbsConvertVersion(%v) failed: %v", info.TBSInfo.TPMVersion, err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return []probedTPM{out}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func tbsConvertVersion(info tbsDeviceInfo) (TPMVersion, error) {
|
|
|
|
switch info.TPMVersion {
|
|
|
|
case 1:
|
|
|
|
return TPMVersion12, nil
|
|
|
|
case 2:
|
|
|
|
return TPMVersion20, nil
|
|
|
|
default:
|
|
|
|
return TPMVersionAgnostic, fmt.Errorf("TBSInfo.TPMVersion %d unsupported", info.TPMVersion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func openTPM(tpm probedTPM) (*TPM, error) {
|
|
|
|
pcp, err := openPCP()
|
|
|
|
if err != nil {
|
2019-04-11 17:20:46 +00:00
|
|
|
return nil, fmt.Errorf("openPCP() failed: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info, err := pcp.TPMInfo()
|
|
|
|
if err != nil {
|
2019-04-11 17:20:46 +00:00
|
|
|
return nil, fmt.Errorf("TPMInfo() failed: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
vers, err := tbsConvertVersion(info.TBSInfo)
|
|
|
|
if err != nil {
|
2019-04-11 17:20:46 +00:00
|
|
|
return nil, fmt.Errorf("tbsConvertVersion(%v) failed: %v", info.TBSInfo.TPMVersion, err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
return &TPM{tpm: &windowsTPM{
|
2019-03-28 20:21:16 +00:00
|
|
|
pcp: pcp,
|
|
|
|
version: vers,
|
2019-09-19 20:13:11 +00:00
|
|
|
}}, nil
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) tpmVersion() TPMVersion {
|
2019-07-19 20:05:18 +00:00
|
|
|
return t.version
|
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) close() error {
|
2019-03-28 20:21:16 +00:00
|
|
|
return t.pcp.Close()
|
|
|
|
}
|
|
|
|
|
2019-04-03 17:40:16 +00:00
|
|
|
func readTPM12VendorAttributes(tpm io.ReadWriter) (TCGVendorID, string, error) {
|
|
|
|
vendor, err := tpm1.GetManufacturer(tpm)
|
|
|
|
if err != nil {
|
|
|
|
return TCGVendorID(0), "", fmt.Errorf("tpm1.GetCapability failed: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-04-03 17:40:16 +00:00
|
|
|
vendorID := TCGVendorID(binary.BigEndian.Uint32(vendor))
|
|
|
|
return vendorID, vendorID.String(), nil
|
|
|
|
}
|
2019-03-28 20:21:16 +00:00
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) info() (*TPMInfo, error) {
|
2019-08-08 01:31:09 +00:00
|
|
|
tInfo := TPMInfo{
|
|
|
|
Version: t.version,
|
|
|
|
Interface: TPMInterfaceKernelManaged,
|
|
|
|
}
|
2019-03-28 20:21:16 +00:00
|
|
|
tpm, err := t.pcp.TPMCommandInterface()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-08-08 01:31:09 +00:00
|
|
|
|
2019-04-03 17:40:16 +00:00
|
|
|
switch t.version {
|
|
|
|
case TPMVersion12:
|
2019-08-08 01:31:09 +00:00
|
|
|
tInfo.Manufacturer, tInfo.VendorInfo, err = readTPM12VendorAttributes(tpm)
|
2019-04-03 17:40:16 +00:00
|
|
|
case TPMVersion20:
|
2019-08-08 01:31:09 +00:00
|
|
|
var t2Info tpm20Info
|
|
|
|
t2Info, err = readTPM2VendorAttributes(tpm)
|
|
|
|
tInfo.Manufacturer = t2Info.manufacturer
|
|
|
|
tInfo.VendorInfo = t2Info.vendor
|
|
|
|
tInfo.FirmwareVersionMajor = t2Info.fwMajor
|
|
|
|
tInfo.FirmwareVersionMinor = t2Info.fwMinor
|
2019-04-03 17:40:16 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported TPM version: %x", t.version)
|
|
|
|
}
|
2019-03-28 20:21:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-08 01:31:09 +00:00
|
|
|
return &tInfo, nil
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) eks() ([]EK, error) {
|
2019-05-03 20:27:48 +00:00
|
|
|
ekCerts, err := t.pcp.EKCerts()
|
2019-03-28 20:21:16 +00:00
|
|
|
if err != nil {
|
2019-04-03 17:40:16 +00:00
|
|
|
return nil, fmt.Errorf("could not read EKCerts: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-08-21 17:26:55 +00:00
|
|
|
if len(ekCerts) > 0 {
|
|
|
|
var eks []EK
|
|
|
|
for _, cert := range ekCerts {
|
|
|
|
eks = append(eks, EK{Certificate: cert, Public: cert.PublicKey})
|
|
|
|
}
|
|
|
|
return eks, nil
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 17:26:55 +00:00
|
|
|
pub, err := t.ekPub()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not read ek public key from tpm: %v", err)
|
2019-07-17 22:15:29 +00:00
|
|
|
}
|
2019-08-21 17:26:55 +00:00
|
|
|
ek := EK{Public: pub}
|
2019-03-28 20:21:16 +00:00
|
|
|
|
2019-09-19 20:13:11 +00:00
|
|
|
i, err := t.info()
|
2019-08-21 17:26:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if i.Manufacturer.String() == manufacturerIntel {
|
|
|
|
ek.CertificateURL = intelEKURL(pub)
|
|
|
|
}
|
|
|
|
return []EK{ek}, nil
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) ekPub() (*rsa.PublicKey, error) {
|
2019-07-17 22:15:29 +00:00
|
|
|
p, err := t.pcp.EKPub()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not read ekpub: %v", err)
|
|
|
|
}
|
|
|
|
ekPub, err := decodeWindowsBcryptRSABlob(p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not decode ekpub: %v", err)
|
|
|
|
}
|
2019-08-21 17:26:55 +00:00
|
|
|
return ekPub, nil
|
2019-07-17 22:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type bcryptRSABlobHeader struct {
|
|
|
|
Magic uint32
|
|
|
|
BitLength uint32
|
|
|
|
ExponentLen uint32
|
|
|
|
ModulusLen uint32
|
|
|
|
Prime1Len uint32
|
|
|
|
Prime2Len uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeWindowsBcryptRSABlob(b []byte) (*rsa.PublicKey, error) {
|
|
|
|
var (
|
|
|
|
r = bytes.NewReader(b)
|
|
|
|
header = &bcryptRSABlobHeader{}
|
|
|
|
exp = make([]byte, 8)
|
|
|
|
mod = []byte("")
|
|
|
|
)
|
|
|
|
if err := binary.Read(r, binary.LittleEndian, header); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if header.Magic != 0x31415352 { // "RSA1"
|
|
|
|
return nil, fmt.Errorf("invalid header magic %x", header.Magic)
|
|
|
|
}
|
|
|
|
if header.ExponentLen > 8 {
|
|
|
|
return nil, errors.New("exponent too large")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := r.Read(exp[8-header.ExponentLen:]); err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to read public exponent: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mod = make([]byte, header.ModulusLen)
|
|
|
|
if n, err := r.Read(mod); n != int(header.ModulusLen) || err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to read modulus (%d, %v)", n, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &rsa.PublicKey{
|
|
|
|
N: new(big.Int).SetBytes(mod),
|
|
|
|
E: int(binary.BigEndian.Uint64(exp)),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-05-16 22:51:01 +00:00
|
|
|
func decryptCredential(secretKey, blob []byte) ([]byte, error) {
|
|
|
|
var scheme uint32
|
2019-05-15 17:36:54 +00:00
|
|
|
symbuf := bytes.NewReader(blob)
|
2019-05-16 22:51:01 +00:00
|
|
|
if err := binary.Read(symbuf, binary.BigEndian, &scheme); err != nil {
|
|
|
|
return nil, fmt.Errorf("reading scheme: %v", err)
|
2019-05-15 17:36:54 +00:00
|
|
|
}
|
2019-05-16 22:51:01 +00:00
|
|
|
if scheme != 0x00000002 {
|
|
|
|
return nil, fmt.Errorf("can only handle CBC schemes")
|
2019-05-15 17:36:54 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 22:51:01 +00:00
|
|
|
iv := make([]byte, 16)
|
|
|
|
if err := binary.Read(symbuf, binary.BigEndian, &iv); err != nil {
|
2019-05-15 17:36:54 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2019-05-16 22:51:01 +00:00
|
|
|
cipherText := make([]byte, len(blob)-20)
|
|
|
|
if err := binary.Read(symbuf, binary.BigEndian, &cipherText); err != nil {
|
|
|
|
return nil, fmt.Errorf("reading ciphertext: %v", err)
|
2019-05-15 17:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decrypt the credential.
|
|
|
|
var (
|
2019-05-16 22:51:01 +00:00
|
|
|
block cipher.Block
|
|
|
|
secret []byte
|
|
|
|
err error
|
2019-05-15 17:36:54 +00:00
|
|
|
)
|
2019-05-16 22:51:01 +00:00
|
|
|
block, err = aes.NewCipher(secretKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("aes.NewCipher failed: %v", err)
|
2019-05-15 17:36:54 +00:00
|
|
|
}
|
2019-05-16 22:51:01 +00:00
|
|
|
secret = cipherText
|
|
|
|
|
|
|
|
mode := cipher.NewCBCDecrypter(block, iv)
|
|
|
|
mode.CryptBlocks(secret, cipherText)
|
|
|
|
// Remove PKCS5 padding.
|
|
|
|
padlen := int(secret[len(secret)-1])
|
|
|
|
secret = secret[:len(secret)-padlen]
|
2019-05-15 17:36:54 +00:00
|
|
|
return secret, nil
|
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) newAK(opts *AKConfig) (*AK, error) {
|
2019-05-03 20:27:48 +00:00
|
|
|
nameHex := make([]byte, 5)
|
|
|
|
if n, err := rand.Read(nameHex); err != nil || n != len(nameHex) {
|
|
|
|
return nil, fmt.Errorf("rand.Read() failed with %d/%d bytes read and error: %v", n, len(nameHex), err)
|
|
|
|
}
|
2019-10-03 19:32:50 +00:00
|
|
|
name := fmt.Sprintf("ak-%x", nameHex)
|
2019-04-03 17:40:16 +00:00
|
|
|
|
2019-10-03 19:32:50 +00:00
|
|
|
kh, err := t.pcp.NewAK(name)
|
2019-05-03 20:27:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("pcp failed to mint attestation key: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-10-03 19:32:50 +00:00
|
|
|
props, err := t.pcp.AKProperties(kh)
|
2019-05-03 20:27:48 +00:00
|
|
|
if err != nil {
|
|
|
|
closeNCryptObject(kh)
|
|
|
|
return nil, fmt.Errorf("pcp failed to read attestation key properties: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-07-19 20:05:18 +00:00
|
|
|
switch t.version {
|
|
|
|
case TPMVersion12:
|
2019-10-03 19:32:50 +00:00
|
|
|
return &AK{ak: newKey12(kh, name, props.RawPublic)}, nil
|
2019-07-19 20:05:18 +00:00
|
|
|
case TPMVersion20:
|
2019-10-03 19:32:50 +00:00
|
|
|
return &AK{ak: newKey20(kh, name, props.RawPublic, props.RawCreationData, props.RawAttest, props.RawSignature)}, nil
|
2019-07-19 20:05:18 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("cannot handle TPM version: %v", t.version)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-07-19 20:05:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) loadAK(opaqueBlob []byte) (*AK, error) {
|
2019-07-19 20:05:18 +00:00
|
|
|
sKey, err := deserializeKey(opaqueBlob, t.version)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("deserializeKey() failed: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-07-19 20:05:18 +00:00
|
|
|
if sKey.Encoding != keyEncodingOSManaged {
|
|
|
|
return nil, fmt.Errorf("unsupported key encoding: %x", sKey.Encoding)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 20:05:18 +00:00
|
|
|
hnd, err := t.pcp.LoadKeyByName(sKey.Name)
|
|
|
|
if err != nil {
|
2019-05-03 20:27:48 +00:00
|
|
|
return nil, fmt.Errorf("pcp failed to load key: %v", err)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-07-19 20:05:18 +00:00
|
|
|
|
|
|
|
switch t.version {
|
|
|
|
case TPMVersion12:
|
2019-10-03 19:32:50 +00:00
|
|
|
return &AK{ak: newKey12(hnd, sKey.Name, sKey.Public)}, nil
|
2019-07-19 20:05:18 +00:00
|
|
|
case TPMVersion20:
|
2019-10-03 19:32:50 +00:00
|
|
|
return &AK{ak: newKey20(hnd, sKey.Name, sKey.Public, sKey.CreateData, sKey.CreateAttestation, sKey.CreateSignature)}, nil
|
2019-07-19 20:05:18 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("cannot handle TPM version: %v", t.version)
|
|
|
|
}
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 17:40:16 +00:00
|
|
|
func allPCRs12(tpm io.ReadWriter) (map[uint32][]byte, error) {
|
|
|
|
numPCRs := 24
|
|
|
|
out := map[uint32][]byte{}
|
|
|
|
|
|
|
|
for pcr := 0; pcr < numPCRs; pcr++ {
|
|
|
|
pcrval, err := tpm1.ReadPCR(tpm, uint32(pcr))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("tpm.ReadPCR() failed with err: %v", err)
|
|
|
|
}
|
|
|
|
out[uint32(pcr)] = pcrval
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-04-03 17:40:16 +00:00
|
|
|
|
|
|
|
if len(out) != numPCRs {
|
|
|
|
return nil, fmt.Errorf("failed to read all PCRs, only read %d", len(out))
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
2019-04-03 17:40:16 +00:00
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) pcrs(alg HashAlg) ([]PCR, error) {
|
2019-04-03 17:40:16 +00:00
|
|
|
var PCRs map[uint32][]byte
|
2019-08-20 18:52:12 +00:00
|
|
|
|
2019-04-03 17:40:16 +00:00
|
|
|
switch t.version {
|
|
|
|
case TPMVersion12:
|
2019-08-20 18:52:12 +00:00
|
|
|
if alg != HashSHA1 {
|
|
|
|
return nil, fmt.Errorf("non-SHA1 algorithm %v is not supported on TPM 1.2", alg)
|
|
|
|
}
|
2019-04-03 17:40:16 +00:00
|
|
|
tpm, err := t.pcp.TPMCommandInterface()
|
|
|
|
if err != nil {
|
2019-08-20 18:52:12 +00:00
|
|
|
return nil, fmt.Errorf("TPMCommandInterface() failed: %v", err)
|
2019-04-03 17:40:16 +00:00
|
|
|
}
|
|
|
|
PCRs, err = allPCRs12(tpm)
|
|
|
|
if err != nil {
|
2019-08-20 18:52:12 +00:00
|
|
|
return nil, fmt.Errorf("failed to read PCRs: %v", err)
|
2019-04-03 17:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case TPMVersion20:
|
|
|
|
tpm, err := t.pcp.TPMCommandInterface()
|
|
|
|
if err != nil {
|
2019-08-20 18:52:12 +00:00
|
|
|
return nil, fmt.Errorf("TPMCommandInterface() failed: %v", err)
|
2019-04-03 17:40:16 +00:00
|
|
|
}
|
2019-08-20 18:52:12 +00:00
|
|
|
PCRs, err = readAllPCRs20(tpm, alg.goTPMAlg())
|
2019-04-03 17:40:16 +00:00
|
|
|
if err != nil {
|
2019-08-20 18:52:12 +00:00
|
|
|
return nil, fmt.Errorf("failed to read PCRs: %v", err)
|
2019-04-03 17:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2019-08-20 18:52:12 +00:00
|
|
|
return nil, fmt.Errorf("unsupported TPM version: %x", t.version)
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 18:52:12 +00:00
|
|
|
out := make([]PCR, len(PCRs))
|
2019-03-28 20:21:16 +00:00
|
|
|
for index, digest := range PCRs {
|
|
|
|
out[int(index)] = PCR{
|
|
|
|
Index: int(index),
|
|
|
|
Digest: digest,
|
2019-08-20 18:52:12 +00:00
|
|
|
DigestAlg: alg.cryptoHash(),
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-20 18:52:12 +00:00
|
|
|
return out, nil
|
2019-03-28 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 21:56:40 +00:00
|
|
|
func (t *windowsTPM) measurementLog() ([]byte, error) {
|
2019-04-03 17:40:16 +00:00
|
|
|
context, err := tpmtbs.CreateContext(tpmtbs.TPMVersion20, tpmtbs.IncludeTPM20|tpmtbs.IncludeTPM12)
|
2019-03-28 20:21:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer context.Close()
|
|
|
|
|
|
|
|
// Run command first with nil buffer to get required buffer size.
|
|
|
|
logLen, err := context.GetTCGLog(nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
logBuffer := make([]byte, logLen)
|
|
|
|
if _, err = context.GetTCGLog(logBuffer); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return logBuffer, nil
|
|
|
|
}
|