mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-09 01:35:16 -04:00

keyservice joinservice upgrade-agent measurement-reader debugd disk-mapper rewrote joinservice main rewrote some unit tests rewrote upgrade-agent + some grpc functions rewrote measurement-reader rewrote debugd removed unused import removed forgotten zap reference in measurements reader rewrote disk-mapper + tests rewrote packages verify disk-mapper malicious join bootstrapper attestationconfigapi versionapi internal/cloud/azure disk-mapper tests image/upload/internal/cmd rewrote verify (WIP with loglevel increase) rewrote forgotten zap references in disk-mapper rewrote malicious join rewrote bootstrapper rewrote parts of internal/ rewrote attestationconfigapi (WIP) rewrote versionapi cli rewrote internal/cloud/azure rewrote disk-mapper tests (untested by me rn) rewrote image/upload/internal/cmd removed forgotten zap references in verify/cmd rewrote packages hack/oci-pin hack/qemu-metadata-api debugd/internal/debugd/deploy hack/bazel-deps-mirror cli/internal/cmd cli-k8s-compatibility rewrote hack/qemu-metadata-api/server rewrote debugd/internal/debugd/deploy rewrote hack/bazel-deps-mirror rewrote rest of hack/qemu-metadata-api rewrote forgotten zap references in joinservice server rewrote cli/internal/cmd rewrote cli-k8s-compatibility rewrote packages internal/staticupload e2d/internal/upgrade internal/constellation/helm internal/attestation/aws/snp internal/attestation/azure/trustedlaunch joinservice/internal/certcache/amkds some missed unit tests rewrote e2e/internal/upgrade rewrote internal/constellation/helm internal/attestation/aws/snp internal/attestation/azure/trustedlaunch joinservice/internal/certcache/amkds search and replace test logging over all left *_test.go
89 lines
2.8 KiB
Go
89 lines
2.8 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
/*
|
|
This package deals with the low level attestation and verification logic of Constellation nodes.
|
|
|
|
General tpm attestation code that is not subjective to a single platform should go into the vtpm package.
|
|
Since attestation capabilities can differ between platforms, the attestation code should go into a subpackage for that respective platform.
|
|
|
|
We commonly implement the following two interfaces for a platform:
|
|
|
|
// Issuer issues an attestation document.
|
|
type Issuer interface {
|
|
oid.Getter
|
|
Issue(userData []byte, nonce []byte) (quote []byte, err error)
|
|
}
|
|
|
|
// Validator is able to validate an attestation document.
|
|
type Validator interface {
|
|
oid.Getter
|
|
Validate(attDoc []byte, nonce []byte) ([]byte, error)
|
|
}
|
|
|
|
Attestation code for new platforms needs to implement these two interfaces.
|
|
*/
|
|
package attestation
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/sha256"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/crypto"
|
|
)
|
|
|
|
const (
|
|
// clusterIDContext is the value to use for info when deriving the cluster ID.
|
|
clusterIDContext = "clusterID"
|
|
// MeasurementSecretContext is the value to use for info
|
|
// when deriving the measurement secret from the master secret.
|
|
MeasurementSecretContext = "measurementSecret"
|
|
)
|
|
|
|
// Logger is a logger used to print warnings and infos during attestation validation.
|
|
type Logger interface {
|
|
Info(format string, args ...any)
|
|
Warn(format string, args ...any)
|
|
}
|
|
|
|
// NOPLogger is a no-op implementation of [Logger].
|
|
type NOPLogger struct{}
|
|
|
|
// Infof is a no-op.
|
|
func (NOPLogger) Infof(string, ...interface{}) {}
|
|
|
|
// Warnf is a no-op.
|
|
func (NOPLogger) Warnf(string, ...interface{}) {}
|
|
|
|
// DeriveClusterID derives the cluster ID from a salt and secret value.
|
|
func DeriveClusterID(secret, salt []byte) ([]byte, error) {
|
|
return crypto.DeriveKey(secret, salt, []byte(crypto.DEKPrefix+clusterIDContext), crypto.DerivedKeyLengthDefault)
|
|
}
|
|
|
|
// MakeExtraData binds userData to a random nonce used in attestation.
|
|
func MakeExtraData(userData []byte, nonce []byte) []byte {
|
|
data := append([]byte{}, userData...)
|
|
data = append(data, nonce...)
|
|
digest := sha256.Sum256(data)
|
|
return digest[:]
|
|
}
|
|
|
|
// CompareExtraData compares the extra data of a quote with the expected extra data.
|
|
// Returns true if the data from the quote matches the expected data.
|
|
// If the slices are not of equal length, the shorter slice is padded with zeros.
|
|
func CompareExtraData(quoteData, expectedData []byte) bool {
|
|
if len(quoteData) != len(expectedData) {
|
|
// If the lengths are not equal, pad the shorter slice with zeros.
|
|
diff := len(quoteData) - len(expectedData)
|
|
if diff < 0 {
|
|
diff = -diff
|
|
quoteData = append(quoteData, bytes.Repeat([]byte{0x00}, diff)...)
|
|
} else {
|
|
expectedData = append(expectedData, bytes.Repeat([]byte{0x00}, diff)...)
|
|
}
|
|
}
|
|
return bytes.Equal(quoteData, expectedData)
|
|
}
|