| 1 |
package attest |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"crypto/sha1" |
| 6 |
"encoding/binary" |
| 7 |
) |
| 8 |
|
| 9 |
const ( |
| 10 |
ekBlobTag = 0x000c |
| 11 |
ekBlobActivateTag = 0x002b |
| 12 |
ekTypeActivate = 0x0001 |
| 13 |
|
| 14 |
algXOR = 0x0000000a |
| 15 |
|
| 16 |
schemeESNone = 0x0001 |
| 17 |
) |
| 18 |
|
| 19 |
type symKeyHeader struct { |
| 20 |
Alg uint32 |
| 21 |
Scheme uint16 |
| 22 |
KeySize uint16 |
| 23 |
} |
| 24 |
|
| 25 |
type activationBlobHeader struct { |
| 26 |
Tag uint16 |
| 27 |
KeyHeader symKeyHeader |
| 28 |
} |
| 29 |
|
| 30 |
func makeEmptyPCRInfo() []byte { |
| 31 |
var b bytes.Buffer |
| 32 |
binary.Write(&b, binary.BigEndian, uint16(3)) // SIZE_OF_SELECT |
| 33 |
b.Write([]byte{0x00, 0x00, 0x00}) // empty bitfield for 3 PCRs |
| 34 |
b.Write([]byte{0x01}) // TPM_LOCALITY_SELECTION = TPM_LOC_ZERO |
| 35 |
b.Write(bytes.Repeat([]byte{0}, sha1.Size)) // TPM_COMPOSITE_HASH |
| 36 |
return b.Bytes() |
| 37 |
} |
| 38 |
|
| 39 |
func makeActivationBlob(symKey, akpub []byte) (blob []byte, err error) { |
| 40 |
akHash := sha1.Sum(akpub) |
| 41 |
|
| 42 |
var out bytes.Buffer |
| 43 |
if err := binary.Write(&out, binary.BigEndian, activationBlobHeader{ |
| 44 |
Tag: ekBlobActivateTag, |
| 45 |
KeyHeader: symKeyHeader{ |
| 46 |
Alg: algXOR, |
| 47 |
Scheme: schemeESNone, |
| 48 |
KeySize: uint16(len(symKey)), |
| 49 |
}, |
| 50 |
}); err != nil { |
| 51 |
return nil, err |
| 52 |
} |
| 53 |
|
| 54 |
out.Write(symKey) |
| 55 |
out.Write(akHash[:]) |
| 56 |
out.Write(makeEmptyPCRInfo()) |
| 57 |
return out.Bytes(), nil |
| 58 |
} |