-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdk: move verify code into sdk (#1030)
For now the SDK is hidden behind a build tag and only for internal use. Because, contrary to the module's version, the API might receive breaking changes in a minor version - until officially released.
- Loading branch information
Showing
12 changed files
with
259 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ run: | |
modules-download-mode: readonly | ||
build-tags: | ||
- e2e | ||
- contrast_unstable_api | ||
|
||
output: | ||
formats: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Contrast SDK | ||
|
||
**Caution:** This SDK is still under active development and not fit for external use yet. | ||
Please expect breaking changes with new minor versions. | ||
|
||
The SDK allows writing programs that interact with a Contrast deployment like the CLI does, without relying on the CLI. | ||
|
||
# Building | ||
|
||
If you decide to use the unstable API and accept the risk of breakage, you need to set the Go build tag `contrast_unstable_api`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Edgeless Systems GmbH | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
//go:build contrast_unstable_api | ||
|
||
package sdk | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/edgelesssys/contrast/internal/atls" | ||
"github.com/edgelesssys/contrast/internal/attestation/certcache" | ||
"github.com/edgelesssys/contrast/internal/attestation/snp" | ||
"github.com/edgelesssys/contrast/internal/attestation/tdx" | ||
"github.com/edgelesssys/contrast/internal/fsstore" | ||
"github.com/edgelesssys/contrast/internal/logger" | ||
"github.com/edgelesssys/contrast/internal/manifest" | ||
) | ||
|
||
// ValidatorsFromManifest returns a list of validators corresponding to the reference values in the given manifest. | ||
// Originally an unexported function in the contrast CLI. | ||
// Can be made unexported again, if we decide to move all userapi calls from the CLI to the SDK. | ||
func ValidatorsFromManifest(kdsDir string, m *manifest.Manifest, log *slog.Logger, coordinatorPolicyChecksum []byte) ([]atls.Validator, error) { | ||
kdsCache := fsstore.New(kdsDir, log.WithGroup("kds-cache")) | ||
kdsGetter := certcache.NewCachedHTTPSGetter(kdsCache, certcache.NeverGCTicker, log.WithGroup("kds-getter")) | ||
|
||
var validators []atls.Validator | ||
|
||
opts, err := m.SNPValidateOpts(kdsGetter) | ||
if err != nil { | ||
return nil, fmt.Errorf("getting SNP validate options: %w", err) | ||
} | ||
for _, opt := range opts { | ||
opt.ValidateOpts.HostData = coordinatorPolicyChecksum | ||
validators = append(validators, snp.NewValidator(opt.VerifyOpts, opt.ValidateOpts, | ||
logger.NewWithAttrs(logger.NewNamed(log, "validator"), map[string]string{"tee-type": "snp"}), | ||
)) | ||
} | ||
|
||
tdxOpts, err := m.TDXValidateOpts() | ||
if err != nil { | ||
return nil, fmt.Errorf("generating TDX validation options: %w", err) | ||
} | ||
var mrConfigID [48]byte | ||
copy(mrConfigID[:], coordinatorPolicyChecksum) | ||
for _, opt := range tdxOpts { | ||
opt.TdQuoteBodyOptions.MrConfigID = mrConfigID[:] | ||
validators = append(validators, tdx.NewValidator(&tdx.StaticValidateOptsGenerator{Opts: opt}, logger.NewWithAttrs(logger.NewNamed(log, "validator"), map[string]string{"tee-type": "tdx"}))) | ||
} | ||
|
||
return validators, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright 2024 Edgeless Systems GmbH | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
//go:build contrast_unstable_api | ||
|
||
package sdk |
Oops, something went wrong.