2022-10-27 05:04:23 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-06-09 09:41:02 -04:00
|
|
|
package snp
|
2022-10-27 05:04:23 -04:00
|
|
|
|
|
|
|
import (
|
2023-08-18 10:16:46 -04:00
|
|
|
"os"
|
2022-10-27 05:04:23 -04:00
|
|
|
"testing"
|
|
|
|
|
2023-03-09 09:23:42 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/simulator"
|
2022-10-27 05:04:23 -04:00
|
|
|
tpmclient "github.com/google/go-tpm-tools/client"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetAttestationKey(t *testing.T) {
|
2023-08-18 10:16:46 -04:00
|
|
|
cgo := os.Getenv("CGO_ENABLED")
|
|
|
|
if cgo == "0" {
|
|
|
|
t.Skip("skipping test because CGO is disabled and tpm simulator requires it")
|
|
|
|
}
|
2023-11-06 08:22:44 -05:00
|
|
|
|
2022-10-27 05:04:23 -04:00
|
|
|
require := require.New(t)
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2023-03-09 09:23:42 -05:00
|
|
|
tpm, err := simulator.OpenSimulatedTPM()
|
2022-10-27 05:04:23 -04:00
|
|
|
require.NoError(err)
|
|
|
|
defer tpm.Close()
|
|
|
|
|
2023-11-06 08:22:44 -05:00
|
|
|
// create the attestation key in RSA format
|
2022-10-27 05:04:23 -04:00
|
|
|
tpmAk, err := tpmclient.AttestationKeyRSA(tpm)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.NotNil(tpmAk)
|
|
|
|
|
|
|
|
// get the cached, already created key
|
|
|
|
getAk, err := getAttestationKey(tpm)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.NotNil(getAk)
|
|
|
|
|
|
|
|
// if everything worked fine, tpmAk and getAk are the same key
|
|
|
|
assert.Equal(tpmAk, getAk)
|
|
|
|
}
|