mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
remove aws nitro attestation
This commit is contained in:
parent
090afe499d
commit
2fb4c15753
@ -1,30 +0,0 @@
|
||||
//go:build aws
|
||||
// +build aws
|
||||
|
||||
package aws
|
||||
|
||||
// #include <nitroattest.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NaAdGetVerifiedPayloadAsJson(adBlob []byte, rootCertDer []byte, ts time.Time) (string, error) {
|
||||
jsonCstr := C.na_ad_get_verified_payload_as_json(
|
||||
(*C.uint8_t)(&adBlob[0]),
|
||||
C.size_t(len(adBlob)),
|
||||
(*C.uint8_t)(&rootCertDer[0]),
|
||||
C.size_t(len(rootCertDer)),
|
||||
C.uint64_t(ts.Unix()),
|
||||
)
|
||||
jsonStr := C.GoString(jsonCstr)
|
||||
C.na_str_free(jsonCstr)
|
||||
|
||||
if jsonStr == "" {
|
||||
return "", fmt.Errorf("failed to verify attestation document: %s", adBlob)
|
||||
}
|
||||
|
||||
return jsonStr, nil
|
||||
}
|
@ -6,10 +6,6 @@ type Issuer struct {
|
||||
oid.AWS
|
||||
}
|
||||
|
||||
func NewIssuer() *Issuer {
|
||||
return &Issuer{}
|
||||
}
|
||||
|
||||
func (i *Issuer) Issue(userData []byte, nonce []byte) ([]byte, error) {
|
||||
return NsmGetAttestationDoc(userData, nonce)
|
||||
panic("aws issuer not implemented")
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
//go:build aws
|
||||
// +build aws
|
||||
|
||||
package aws
|
||||
|
||||
// #include <nsm.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// As defined by the attestation document's COSE_Sign1 structure
|
||||
const nsmMaxAttestationDocSize = 16 * 1024
|
||||
|
||||
func NsmGetAttestationDoc(userData []byte, nonce []byte) ([]byte, error) {
|
||||
doc := make([]byte, nsmMaxAttestationDocSize)
|
||||
doclen := C.uint32_t(len(doc))
|
||||
|
||||
nsm_fd := C.nsm_lib_init()
|
||||
if nsm_fd < 0 {
|
||||
return nil, fmt.Errorf("could not open NSM module")
|
||||
}
|
||||
defer C.nsm_lib_exit(nsm_fd)
|
||||
|
||||
errCode := C.nsm_get_attestation_doc(
|
||||
nsm_fd,
|
||||
(*C.uint8_t)(&userData[0]),
|
||||
C.uint32_t(len(userData)),
|
||||
(*C.uint8_t)(&nonce[0]),
|
||||
C.uint32_t(len(nonce)),
|
||||
nil,
|
||||
0,
|
||||
(*C.uint8_t)(&doc[0]),
|
||||
&doclen,
|
||||
)
|
||||
if errCode != C.ERROR_CODE_SUCCESS {
|
||||
return nil, fmt.Errorf("failed to generate attestation document: %d", errCode)
|
||||
}
|
||||
doc = doc[:doclen]
|
||||
|
||||
return doc, nil
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//go:build !aws
|
||||
// +build !aws
|
||||
|
||||
package aws
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errInvalidBuild = errors.New("not built with \"-tags aws\"")
|
||||
|
||||
func NsmGetAttestationDoc(userData []byte, nonce []byte) ([]byte, error) {
|
||||
return nil, errInvalidBuild
|
||||
}
|
||||
|
||||
func NaAdGetVerifiedPayloadAsJson(adBlob []byte, rootCertDer []byte, ts time.Time) (string, error) {
|
||||
return "", errInvalidBuild
|
||||
}
|
@ -1,89 +1,13 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/coordinator/oid"
|
||||
)
|
||||
|
||||
// https://aws-nitro-enclaves.amazonaws.com/AWS_NitroEnclaves_Root-G1.zip
|
||||
var awsNitroEnclavesRoot = []byte{
|
||||
0x30, 0x82, 0x02, 0x11, 0x30, 0x82, 0x01, 0x96, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00,
|
||||
0xf9, 0x31, 0x75, 0x68, 0x1b, 0x90, 0xaf, 0xe1, 0x1d, 0x46, 0xcc, 0xb4, 0xe4, 0xe7, 0xf8, 0x56,
|
||||
0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x49, 0x31, 0x0b,
|
||||
0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06,
|
||||
0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x31, 0x0c, 0x30, 0x0a,
|
||||
0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x03, 0x41, 0x57, 0x53, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03,
|
||||
0x55, 0x04, 0x03, 0x0c, 0x12, 0x61, 0x77, 0x73, 0x2e, 0x6e, 0x69, 0x74, 0x72, 0x6f, 0x2d, 0x65,
|
||||
0x6e, 0x63, 0x6c, 0x61, 0x76, 0x65, 0x73, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x31, 0x30, 0x32,
|
||||
0x38, 0x31, 0x33, 0x32, 0x38, 0x30, 0x35, 0x5a, 0x17, 0x0d, 0x34, 0x39, 0x31, 0x30, 0x32, 0x38,
|
||||
0x31, 0x34, 0x32, 0x38, 0x30, 0x35, 0x5a, 0x30, 0x49, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
|
||||
0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
|
||||
0x06, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b,
|
||||
0x0c, 0x03, 0x41, 0x57, 0x53, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x12,
|
||||
0x61, 0x77, 0x73, 0x2e, 0x6e, 0x69, 0x74, 0x72, 0x6f, 0x2d, 0x65, 0x6e, 0x63, 0x6c, 0x61, 0x76,
|
||||
0x65, 0x73, 0x30, 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06,
|
||||
0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x03, 0x62, 0x00, 0x04, 0xfc, 0x02, 0x54, 0xeb, 0xa6, 0x08,
|
||||
0xc1, 0xf3, 0x68, 0x70, 0xe2, 0x9a, 0xda, 0x90, 0xbe, 0x46, 0x38, 0x32, 0x92, 0x73, 0x6e, 0x89,
|
||||
0x4b, 0xff, 0xf6, 0x72, 0xd9, 0x89, 0x44, 0x4b, 0x50, 0x51, 0xe5, 0x34, 0xa4, 0xb1, 0xf6, 0xdb,
|
||||
0xe3, 0xc0, 0xbc, 0x58, 0x1a, 0x32, 0xb7, 0xb1, 0x76, 0x07, 0x0e, 0xde, 0x12, 0xd6, 0x9a, 0x3f,
|
||||
0xea, 0x21, 0x1b, 0x66, 0xe7, 0x52, 0xcf, 0x7d, 0xd1, 0xdd, 0x09, 0x5f, 0x6f, 0x13, 0x70, 0xf4,
|
||||
0x17, 0x08, 0x43, 0xd9, 0xdc, 0x10, 0x01, 0x21, 0xe4, 0xcf, 0x63, 0x01, 0x28, 0x09, 0x66, 0x44,
|
||||
0x87, 0xc9, 0x79, 0x62, 0x84, 0x30, 0x4d, 0xc5, 0x3f, 0xf4, 0xa3, 0x42, 0x30, 0x40, 0x30, 0x0f,
|
||||
0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30,
|
||||
0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x90, 0x25, 0xb5, 0x0d, 0xd9, 0x05,
|
||||
0x47, 0xe7, 0x96, 0xc3, 0x96, 0xfa, 0x72, 0x9d, 0xcf, 0x99, 0xa9, 0xdf, 0x4b, 0x96, 0x30, 0x0e,
|
||||
0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x0a,
|
||||
0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x03, 0x69, 0x00, 0x30, 0x66, 0x02,
|
||||
0x31, 0x00, 0xa3, 0x7f, 0x2f, 0x91, 0xa1, 0xc9, 0xbd, 0x5e, 0xe7, 0xb8, 0x62, 0x7c, 0x16, 0x98,
|
||||
0xd2, 0x55, 0x03, 0x8e, 0x1f, 0x03, 0x43, 0xf9, 0x5b, 0x63, 0xa9, 0x62, 0x8c, 0x3d, 0x39, 0x80,
|
||||
0x95, 0x45, 0xa1, 0x1e, 0xbc, 0xbf, 0x2e, 0x3b, 0x55, 0xd8, 0xae, 0xee, 0x71, 0xb4, 0xc3, 0xd6,
|
||||
0xad, 0xf3, 0x02, 0x31, 0x00, 0xa2, 0xf3, 0x9b, 0x16, 0x05, 0xb2, 0x70, 0x28, 0xa5, 0xdd, 0x4b,
|
||||
0xa0, 0x69, 0xb5, 0x01, 0x6e, 0x65, 0xb4, 0xfb, 0xde, 0x8f, 0xe0, 0x06, 0x1d, 0x6a, 0x53, 0x19,
|
||||
0x7f, 0x9c, 0xda, 0xf5, 0xd9, 0x43, 0xbc, 0x61, 0xfc, 0x2b, 0xeb, 0x03, 0xcb, 0x6f, 0xee, 0x8d,
|
||||
0x23, 0x02, 0xf3, 0xdf, 0xf6,
|
||||
}
|
||||
|
||||
type attestationDocument struct {
|
||||
ModuleID string `json:"module_id"`
|
||||
Digest string
|
||||
Timestamp int
|
||||
Pcrs map[string]string
|
||||
PublicKey []byte `json:"public_key"`
|
||||
UserData []byte `json:"user_data"`
|
||||
Nonce []byte
|
||||
}
|
||||
|
||||
type VerifyFunc func(adBlob []byte, rootCertDer []byte, ts time.Time) (string, error)
|
||||
|
||||
type Validator struct {
|
||||
oid.AWS
|
||||
getVerifiedPayloadAsJson VerifyFunc
|
||||
}
|
||||
|
||||
func NewValidator(getVerifiedPayloadAsJson VerifyFunc) *Validator {
|
||||
return &Validator{getVerifiedPayloadAsJson: getVerifiedPayloadAsJson}
|
||||
}
|
||||
|
||||
func (a *Validator) Validate(attDoc []byte, nonce []byte) ([]byte, error) {
|
||||
jsonStr, err := a.getVerifiedPayloadAsJson(attDoc, awsNitroEnclavesRoot, time.Now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var parsedAttDoc attestationDocument
|
||||
if err := json.Unmarshal([]byte(jsonStr), &parsedAttDoc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !bytes.Equal(parsedAttDoc.Nonce, nonce) {
|
||||
return nil, fmt.Errorf("validator: failed nonce freshness for nonce: %s", parsedAttDoc.Nonce)
|
||||
}
|
||||
|
||||
// TODO: Choose PCRs for validation
|
||||
|
||||
return parsedAttDoc.UserData, nil
|
||||
panic("aws validator not implemented")
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
nonce []byte
|
||||
verifyResult string
|
||||
verifyErr error
|
||||
expectedUserData []byte
|
||||
expectErr bool
|
||||
}{
|
||||
"valid": {
|
||||
nonce: []byte{2, 3, 4},
|
||||
verifyResult: `{"nonce":[2,3,4], "user_data":[5,6,7]}`,
|
||||
expectedUserData: []byte{5, 6, 7},
|
||||
},
|
||||
"invalid nonce": {
|
||||
nonce: []byte{2, 3, 5},
|
||||
verifyResult: `{"nonce":[2,3,4], "user_data":[5,6,7]}`,
|
||||
expectErr: true,
|
||||
},
|
||||
"nil nonce": {
|
||||
nonce: nil,
|
||||
verifyResult: `{"nonce":[2,3,4], "user_data":[5,6,7]}`,
|
||||
expectErr: true,
|
||||
},
|
||||
"verify error": {
|
||||
nonce: []byte{2, 3, 4},
|
||||
verifyErr: errors.New("failed"),
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
doc := []byte("doc")
|
||||
|
||||
verify := func(adBlob []byte, rootCertDer []byte, ts time.Time) (string, error) {
|
||||
assert.Equal(doc, adBlob)
|
||||
assert.Equal(awsNitroEnclavesRoot, rootCertDer)
|
||||
return tc.verifyResult, tc.verifyErr
|
||||
}
|
||||
|
||||
userData, err := NewValidator(verify).Validate(doc, tc.nonce)
|
||||
if tc.expectErr {
|
||||
require.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(err)
|
||||
assert.Equal(tc.expectedUserData, userData)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user