Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
10dd5f7
Bump Go version to 1.19 (#325)
brandonweeks May 22, 2023
62a036b
Bump golang.org/x/sys from 0.0.0-20220209214540-3681064d5158 to 0.8.0…
dependabot[bot] May 22, 2023
a4b579b
Bump github.com/google/go-tpm-tools from 0.3.9 to 0.3.12 (#324)
dependabot[bot] May 22, 2023
b474b71
wrappedTPM20.ekTemplate() never returns an error. (#327)
zhsh May 29, 2023
89884d0
Fix Intel EK certificate URL (#310)
hslatman Jun 2, 2023
258084d
Add support for generating TPM2.0 challenges using AttestedCertifyInfo
juanvallejo May 31, 2023
50c1e1e
Renamed some variables and methods to highlight that only RSA EKs are…
zhsh Jun 13, 2023
a9b6eb1
use legacy tpm2 at its new path (#331)
chrisfenner Jun 13, 2023
2788b54
Fix golangci-lint workflow (#336)
ldez Jun 20, 2023
ac9aa24
Bump golang.org/x/sys from 0.8.0 to 0.9.0 (#335)
dependabot[bot] Jun 20, 2023
63dd90f
Bump github.com/google/go-tpm from 0.3.4 to 0.9.0 (#337)
brandonweeks Jun 21, 2023
d29df30
Add EK as a field to AK struct. (#332)
zhsh Jun 22, 2023
b92d1c6
Add TPM.EKCertificates() method, it returns all certificates from TPM…
zhsh Jun 23, 2023
8af5f4e
attest: Make PCRs included in quote configurable (#311)
smo4201 Jun 26, 2023
a56e8c4
Activate AK with ECC EKs. (#339)
zhsh Jun 28, 2023
60adf13
attest: ActivateCredentialWithEK() method that can be used with non-d…
zhsh Jun 29, 2023
310e2ca
attest: Remove the EK field from AK struct (#341)
zhsh Jun 29, 2023
0465506
attest: Create keys under non-default SRKs (#342)
zhsh Jul 11, 2023
ab5dee2
ci: don't install OpenSSL 1.1 on macOS (#350)
brandonweeks Sep 8, 2023
3c84bff
Bump golang.org/x/sys from 0.9.0 to 0.12.0 (#348)
dependabot[bot] Sep 8, 2023
42c11fc
Fix typo (#349)
djm-google Sep 8, 2023
3d71f10
Fix Intel EK certificate URLs on Linux (#347)
hslatman Sep 8, 2023
f4ab877
Bump github.com/google/go-tpm-tools (#351)
dependabot[bot] Sep 11, 2023
82eb5d4
Bump github.com/google/go-tpm-tools from 0.4.0 to 0.4.1 (#352)
dependabot[bot] Sep 18, 2023
136789e
Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (#354)
dependabot[bot] Oct 16, 2023
776dc3a
Bump golang.org/x/sys from 0.12.0 to 0.13.0 (#353)
dependabot[bot] Oct 16, 2023
74a4936
Bump github.com/google/go-tpm-tools from 0.4.1 to 0.4.2 (#355)
dependabot[bot] Oct 30, 2023
93c5899
Bump golang.org/x/sys from 0.13.0 to 0.14.0 (#356)
dependabot[bot] Nov 6, 2023
a3545df
don't drop leading zeroes when performing generic ecdsa signing (#357)
mwielgoszewski Nov 9, 2023
8a53e65
Add TPM 2 application key support for Windows
mjg59 Apr 28, 2022
35c70c7
Add signing support for keys generated on Windows
hslatman Nov 10, 2022
c5ba242
Fix missing `ECDSA` curve when signing on Windows
hslatman Jan 4, 2023
31b84de
Explicitly set scheme for ECDSA signing
mjg59 May 23, 2023
c8f04b2
Add loadKey for Windows
mjg59 Sep 8, 2023
1254b4d
Fix tpm_windows.go dependency to legacy/tpm2
werwurm Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.3
go-version: 1.20.x
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.53.3
12 changes: 4 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test-linux:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
go-version: [1.20.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -27,7 +27,7 @@ jobs:
test-linux-tpm12:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
go-version: [1.20.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -43,7 +43,7 @@ jobs:
test-macos:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
go-version: [1.20.x]
runs-on: macos-latest
steps:
- name: Install Go
Expand All @@ -53,16 +53,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
# See https://github.com/google/go-tpm-tools#macos-dev
- name: Install openssl
run: brew install [email protected]
- name: Link openssl
run: sudo ln -s $(brew --prefix [email protected])/include/openssl /usr/local/include
- name: Test
run: C_INCLUDE_PATH="$(brew --prefix [email protected])/include" LIBRARY_PATH="$(brew --prefix [email protected])/lib" go test ./...
test-windows:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
go-version: [1.20.x]
runs-on: windows-latest
steps:
- name: Install Go
Expand Down
4 changes: 2 additions & 2 deletions attest/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"fmt"
"io"

"github.com/google/go-tpm/legacy/tpm2"
tpm1 "github.com/google/go-tpm/tpm"
"github.com/google/go-tpm/tpm2"

// TODO(jsonp): Move activation generation code to internal package.
"github.com/google/go-tpm/tpm2/credactivation"
"github.com/google/go-tpm/legacy/tpm2/credactivation"
"github.com/google/go-tspi/verification"
)

Expand Down
4 changes: 4 additions & 0 deletions attest/application_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type KeyConfig struct {
// Size is used to specify the bit size of the key or elliptic curve. For
// example, '256' is used to specify curve P-256.
Size int
// Parent describes the Storage Root Key that will be used as a parent.
// If nil, the default SRK (i.e. RSA with handle 0x81000001) is assumed.
// Supported only by TPM 2.0 on Linux.
Parent *ParentKeyConfig
}

// defaultConfig is used when no other configuration is specified.
Expand Down
2 changes: 1 addition & 1 deletion attest/attest-tool/attest-tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func runCommand(tpm *attest.TPM) error {
fmt.Printf("Version: %d\n", info.Version)
fmt.Printf("Interface: %d\n", info.Interface)
fmt.Printf("VendorInfo: %x\n", info.VendorInfo)
fmt.Printf("Manufactorer: %v\n", info.Manufacturer)
fmt.Printf("Manufacturer: %v\n", info.Manufacturer)

case "make-ak", "make-aik":
k, err := tpm.NewAK(nil)
Expand Down
2 changes: 1 addition & 1 deletion attest/attest-tool/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package internal

import (
"github.com/google/go-attestation/attest"
"github.com/google/go-tpm/tpm2"
"github.com/google/go-tpm/legacy/tpm2"
)

// Dump describes the layout of serialized information from the dump command.
Expand Down
55 changes: 47 additions & 8 deletions attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
"io"
"strings"

"github.com/google/go-tpm/legacy/tpm2"
"github.com/google/go-tpm/tpm"
"github.com/google/go-tpm/tpm2"
"github.com/google/go-tpm/tpmutil"
)

// TPMVersion is used to configure a preference in
Expand Down Expand Up @@ -98,11 +99,23 @@ const (
keyEncodingParameterized
)

// ParentKeyConfig describes the Storage Root Key that is used
// as a parent for new keys.
type ParentKeyConfig struct {
Algorithm Algorithm
Handle tpmutil.Handle
}

var defaultParentConfig = ParentKeyConfig{
Algorithm: RSA,
Handle: 0x81000001,
}

type ak interface {
close(tpmBase) error
marshal() ([]byte, error)
activateCredential(tpm tpmBase, in EncryptedCredential) ([]byte, error)
quote(t tpmBase, nonce []byte, alg HashAlg) (*Quote, error)
activateCredential(tpm tpmBase, in EncryptedCredential, ek *EK) ([]byte, error)
quote(t tpmBase, nonce []byte, alg HashAlg, selectedPCRs []int) (*Quote, error)
attestationParameters() AttestationParameters
certify(tb tpmBase, handle interface{}) (*CertificationParameters, error)
}
Expand All @@ -126,19 +139,39 @@ func (k *AK) Marshal() ([]byte, error) {
}

// ActivateCredential decrypts the secret using the key to prove that the AK
// was generated on the same TPM as the EK.
// was generated on the same TPM as the EK. This method can be used with TPMs
// that have the default EK, i.e. RSA EK with handle 0x81010001.
//
// This operation is synonymous with TPM2_ActivateCredential.
func (k *AK) ActivateCredential(tpm *TPM, in EncryptedCredential) (secret []byte, err error) {
return k.ak.activateCredential(tpm.tpm, in)
return k.ak.activateCredential(tpm.tpm, in, nil)
}

// ActivateCredential decrypts the secret using the key to prove that the AK
// was generated on the same TPM as the EK. This method can be used with TPMs
// that have an ECC EK. The 'ek' argument must be one of EKs returned from
// TPM.EKs() or TPM.EKCertificates().
//
// This operation is synonymous with TPM2_ActivateCredential.
func (k *AK) ActivateCredentialWithEK(tpm *TPM, in EncryptedCredential, ek EK) (secret []byte, err error) {
return k.ak.activateCredential(tpm.tpm, in, &ek)
}

// Quote returns a quote over the platform state, signed by the AK.
//
// This is a low-level API. Consumers seeking to attest the state of the
// platform should use tpm.AttestPlatform() instead.
func (k *AK) Quote(tpm *TPM, nonce []byte, alg HashAlg) (*Quote, error) {
return k.ak.quote(tpm.tpm, nonce, alg)
pcrs := make([]int, 24)
for pcr := range pcrs {
pcrs[pcr] = pcr
}
return k.ak.quote(tpm.tpm, nonce, alg, pcrs)
}

// QuotePCRs is like Quote() but allows the caller to select a subset of the PCRs.
func (k *AK) QuotePCRs(tpm *TPM, nonce []byte, alg HashAlg, pcrs []int) (*Quote, error) {
return k.ak.quote(tpm.tpm, nonce, alg, pcrs)
}

// AttestationParameters returns information about the AK, typically used to
Expand All @@ -155,9 +188,12 @@ func (k *AK) Certify(tpm *TPM, handle interface{}) (*CertificationParameters, er
return k.ak.certify(tpm.tpm, handle)
}

// AKConfig encapsulates parameters for minting keys. This type is defined
// now (despite being empty) for future interface compatibility.
// AKConfig encapsulates parameters for minting keys.
type AKConfig struct {
// Parent describes the Storage Root Key that will be used as a parent.
// If nil, the default SRK (i.e. RSA with handle 0x81000001) is assumed.
// Supported only by TPM 2.0 on Linux.
Parent *ParentKeyConfig
}

// EncryptedCredential represents encrypted parameters which must be activated
Expand Down Expand Up @@ -205,6 +241,9 @@ type EK struct {
// Public key. Clients or servers can perform an HTTP GET to this URL, and
// use ParseEKCertificate on the response body.
CertificateURL string

// The EK persistent handle.
handle tpmutil.Handle
}

// AttestationParameters describes information about a key which is necessary
Expand Down
92 changes: 75 additions & 17 deletions attest/attest_simulated_tpm20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,45 @@ func TestSimTPM20AKCreateAndLoad(t *testing.T) {
}

func TestSimTPM20ActivateCredential(t *testing.T) {
testActivateCredential(t, false)
}

func TestSimTPM20ActivateCredentialWithEK(t *testing.T) {
testActivateCredential(t, true)
}

func testActivateCredential(t *testing.T, useEK bool) {
sim, tpm := setupSimulatedTPM(t)
defer sim.Close()

ak, err := tpm.NewAK(nil)
if err != nil {
t.Fatalf("NewAK() failed: %v", err)
}
defer ak.Close(tpm)

EKs, err := tpm.EKs()
if err != nil {
t.Fatalf("EKs() failed: %v", err)
}
ek := chooseEK(t, EKs)

ak, err := tpm.NewAK(nil)
if err != nil {
t.Fatalf("NewAK() failed: %v", err)
}
defer ak.Close(tpm)

ap := ActivationParameters{
TPMVersion: TPMVersion20,
AK: ak.AttestationParameters(),
EK: ek,
EK: ek.Public,
}
secret, challenge, err := ap.Generate()
if err != nil {
t.Fatalf("Generate() failed: %v", err)
}

decryptedSecret, err := ak.ActivateCredential(tpm, *challenge)
var decryptedSecret []byte
if useEK {
decryptedSecret, err = ak.ActivateCredentialWithEK(tpm, *challenge, ek)
} else {
decryptedSecret, err = ak.ActivateCredential(tpm, *challenge)
}
if err != nil {
t.Errorf("ak.ActivateCredential() failed: %v", err)
}
Expand Down Expand Up @@ -246,24 +259,69 @@ func TestSimTPM20PCRs(t *testing.T) {
}
}

func TestSimTPM20Persistence(t *testing.T) {
func TestSimTPM20PersistenceSRK(t *testing.T) {
testPersistenceSRK(t, defaultParentConfig)
}

func TestSimTPM20PersistenceECCSRK(t *testing.T) {
parentConfig := ParentKeyConfig{
Algorithm: ECDSA,
Handle: 0x81000002,
}
testPersistenceSRK(t, parentConfig)
}

func testPersistenceSRK(t *testing.T, parentConfig ParentKeyConfig) {
sim, tpm := setupSimulatedTPM(t)
defer sim.Close()

ekHnd, _, err := tpm.tpm.(*wrappedTPM20).getPrimaryKeyHandle(commonEkEquivalentHandle)
srkHnd, _, err := tpm.tpm.(*wrappedTPM20).getStorageRootKeyHandle(parentConfig)
if err != nil {
t.Fatalf("getStorageRootKeyHandle() failed: %v", err)
}
if srkHnd != parentConfig.Handle {
t.Fatalf("bad SRK-equivalent handle: got 0x%x, wanted 0x%x", srkHnd, parentConfig.Handle)
}

srkHnd, p, err := tpm.tpm.(*wrappedTPM20).getStorageRootKeyHandle(parentConfig)
if err != nil {
t.Fatalf("second getStorageRootKeyHandle() failed: %v", err)
}
if srkHnd != parentConfig.Handle {
t.Fatalf("bad SRK-equivalent handle: got 0x%x, wanted 0x%x", srkHnd, parentConfig.Handle)
}
if p {
t.Fatalf("generated a new key the second time; that shouldn't happen")
}
}

func TestSimTPM20PersistenceEK(t *testing.T) {
sim, tpm := setupSimulatedTPM(t)
defer sim.Close()

eks, err := tpm.EKs()
if err != nil {
t.Errorf("EKs() failed: %v", err)
}
if len(eks) == 0 || (eks[0].Public == nil) {
t.Errorf("EKs() = %v, want at least 1 EK with populated fields", eks)
}

ek := eks[0]
ekHnd, _, err := tpm.tpm.(*wrappedTPM20).getEndorsementKeyHandle(&ek)
if err != nil {
t.Fatalf("getPrimaryKeyHandle() failed: %v", err)
t.Fatalf("getStorageRootKeyHandle() failed: %v", err)
}
if ekHnd != commonEkEquivalentHandle {
t.Fatalf("bad EK-equivalent handle: got 0x%x, wanted 0x%x", ekHnd, commonEkEquivalentHandle)
if ekHnd != ek.handle {
t.Fatalf("bad EK-equivalent handle: got 0x%x, wanted 0x%x", ekHnd, ek.handle)
}

ekHnd, p, err := tpm.tpm.(*wrappedTPM20).getPrimaryKeyHandle(commonEkEquivalentHandle)
ekHnd, p, err := tpm.tpm.(*wrappedTPM20).getEndorsementKeyHandle(&ek)
if err != nil {
t.Fatalf("second getPrimaryKeyHandle() failed: %v", err)
t.Fatalf("second getEndorsementKeyHandle() failed: %v", err)
}
if ekHnd != commonEkEquivalentHandle {
t.Fatalf("bad EK-equivalent handle: got 0x%x, wanted 0x%x", ekHnd, commonEkEquivalentHandle)
if ekHnd != ek.handle {
t.Fatalf("bad EK-equivalent handle: got 0x%x, wanted 0x%x", ekHnd, ek.handle)
}
if p {
t.Fatalf("generated a new key the second time; that shouldn't happen")
Expand Down
9 changes: 4 additions & 5 deletions attest/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package attest

import (
"bytes"
"crypto"
"flag"
"fmt"
"reflect"
Expand Down Expand Up @@ -119,16 +118,16 @@ func TestAKCreateAndLoad(t *testing.T) {
}
}

// chooseEK selects the EK public which will be activated against.
func chooseEK(t *testing.T, eks []EK) crypto.PublicKey {
// chooseEK selects the EK which will be activated against.
func chooseEK(t *testing.T, eks []EK) EK {
t.Helper()

for _, ek := range eks {
return ek.Public
return ek
}

t.Fatalf("No suitable EK found")
return nil
return EK{}
}

func TestPCRs(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion attest/attest_tpm12_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestTPMActivateCredential(t *testing.T) {
ap := ActivationParameters{
TPMVersion: TPMVersion12,
AK: ak.AttestationParameters(),
EK: ek,
EK: ek.Public,
}
secret, challenge, err := ap.Generate()
if err != nil {
Expand Down
Loading