-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
atls: try to attest with all validators
Our aTLS code needs to be adjusted to allow for multiple attestation variants. While we did allow one to have multiple validators before, we tried to validate the first matching one and instantly errored out if validation for that validator failed. Now, we can have multiple matching validators and try all until one successfully validated the document, or until the list of applicable validators is exhausted, where we can return an error.
- Loading branch information
Showing
6 changed files
with
201 additions
and
13 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
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,131 @@ | ||
// Copyright 2024 Edgeless Systems GmbH | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package atls | ||
|
||
import ( | ||
"crypto/x509" | ||
"crypto/x509/pkix" | ||
"encoding/asn1" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/edgelesssys/contrast/internal/oid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestVerifyEmbeddedReport(t *testing.T) { | ||
fakeAttDoc := FakeAttestationDoc{} | ||
attDocBytes, err := json.Marshal(fakeAttDoc) | ||
assert.NoError(t, err) | ||
|
||
testCases := map[string]struct { | ||
cert *x509.Certificate | ||
validators []Validator | ||
wantErr bool | ||
targetErr error | ||
}{ | ||
"success": { | ||
cert: &x509.Certificate{ | ||
Extensions: []pkix.Extension{ | ||
{ | ||
Id: oid.RawTDXReport, | ||
}, | ||
{ | ||
Id: oid.RawSNPReport, | ||
Value: attDocBytes, | ||
}, | ||
}, | ||
}, | ||
validators: NewFakeValidators(stubSNPValidator{}), | ||
}, | ||
"multiple matches": { | ||
cert: &x509.Certificate{ | ||
Extensions: []pkix.Extension{ | ||
{ | ||
Id: oid.RawSNPReport, | ||
Value: []byte("foo"), | ||
}, | ||
{ | ||
Id: oid.RawSNPReport, | ||
Value: attDocBytes, | ||
}, | ||
}, | ||
}, | ||
validators: NewFakeValidators(stubSNPValidator{}), | ||
}, | ||
"skip non-matching validator": { | ||
cert: &x509.Certificate{ | ||
Extensions: []pkix.Extension{ | ||
{ | ||
Id: []int{4, 5, 6}, | ||
}, | ||
{ | ||
Id: oid.RawSNPReport, | ||
Value: attDocBytes, | ||
}, | ||
}, | ||
}, | ||
validators: append(NewFakeValidators(stubSNPValidator{}), NewFakeValidator(stubFooValidator{})), | ||
}, | ||
"match, error": { | ||
cert: &x509.Certificate{ | ||
Extensions: []pkix.Extension{ | ||
{ | ||
Id: oid.RawSNPReport, | ||
Value: []byte("foo"), | ||
}, | ||
}, | ||
}, | ||
validators: NewFakeValidators(stubSNPValidator{}), | ||
wantErr: true, | ||
}, | ||
"no extensions": { | ||
cert: &x509.Certificate{}, | ||
validators: nil, | ||
targetErr: ErrNoValidAttestationExtensions, | ||
wantErr: true, | ||
}, | ||
"no matching validator": { | ||
cert: &x509.Certificate{ | ||
Extensions: []pkix.Extension{ | ||
{ | ||
Id: oid.RawSNPReport, | ||
}, | ||
}, | ||
}, | ||
validators: nil, | ||
targetErr: ErrNoMatchingValidators, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
assert := assert.New(t) | ||
require := require.New(t) | ||
err := verifyEmbeddedReport(tc.validators, tc.cert, nil, nil) | ||
if tc.wantErr { | ||
require.Error(err) | ||
if tc.targetErr != nil { | ||
assert.ErrorIs(err, tc.targetErr) | ||
} | ||
} else { | ||
require.NoError(err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
type stubSNPValidator struct{} | ||
|
||
func (v stubSNPValidator) OID() asn1.ObjectIdentifier { | ||
return oid.RawSNPReport | ||
} | ||
|
||
type stubFooValidator struct{} | ||
|
||
func (v stubFooValidator) OID() asn1.ObjectIdentifier { | ||
return []int{1, 2, 3} | ||
} |
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,16 @@ | ||
// Copyright 2024 Edgeless Systems GmbH | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package attestation | ||
|
||
import ( | ||
"encoding/asn1" | ||
|
||
oids "github.com/edgelesssys/contrast/internal/oid" | ||
) | ||
|
||
// IsAttestationDocumentExtension checks whether the given OID corresponds to an attestation document extension | ||
// supported by Contrast (i.e. TDX or SNP). | ||
func IsAttestationDocumentExtension(oid asn1.ObjectIdentifier) bool { | ||
return oid.Equal(oids.RawTDXReport) || oid.Equal(oids.RawSNPReport) | ||
} |