-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…40495) * Add structure of `tpm` package * Add proto conversion methods * Add tests for proto conversions * Add startup stuff for tpm sim based tests * try and fail to write a fake ekcert to the tpm * Working ability to write to a TPM ekcert index * Tidy up * Add finishing touches to test and add godocs * Go mod tidy * Appease linter * Remove incorrectly copied comment * Tidy up line wrapping * Add license header * Update lib/tpm/tpm.go * Update lib/tpm/tpm_simulator_test.go * Update lib/tpm/validate.go * Update lib/tpm/tpm.go * Update lib/tpm/tpm_simulator_test.go * Update lib/tpm/tpm_simulator_test.go * Update lib/tpm/tpm_simulator_test.go * Avoid managing closure in the attestWithTPM func * Use ekCertSerialHex const * Simpler JoinAuditAttributes method * Add missing err return * Add remark on the nvram rsa ekcert index * Update lib/tpm/tpm_simulator_test.go * Add subtests * Clarify in hex * Switch to testing exported iface * Use x509.CertPool and switch to testing public APi * Remove overly cautious check * Validate Validate params * Reuse strings builder when handling an odd number of hex digits * Switch to gocmp and struct for ekcert * Use return struct for Attest * Avoid marshalling PKIX key twice * Update lib/tpm/validate.go --------- Co-authored-by: Alan Parra <[email protected]>
- Loading branch information
1 parent
fc2f62b
commit 985f955
Showing
7 changed files
with
811 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package tpm | ||
|
||
import ( | ||
"github.com/google/go-attestation/attest" | ||
|
||
"github.com/gravitational/teleport/api/client/proto" | ||
) | ||
|
||
// AttestationParametersToProto converts an attest.AttestationParameters to | ||
// its protobuf representation. | ||
func AttestationParametersToProto(in attest.AttestationParameters) *proto.TPMAttestationParameters { | ||
return &proto.TPMAttestationParameters{ | ||
Public: in.Public, | ||
CreateData: in.CreateData, | ||
CreateAttestation: in.CreateAttestation, | ||
CreateSignature: in.CreateSignature, | ||
} | ||
} | ||
|
||
// AttestationParametersFromProto extracts an attest.AttestationParameters from | ||
// its protobuf representation. | ||
func AttestationParametersFromProto(in *proto.TPMAttestationParameters) attest.AttestationParameters { | ||
if in == nil { | ||
return attest.AttestationParameters{} | ||
} | ||
return attest.AttestationParameters{ | ||
Public: in.Public, | ||
CreateData: in.CreateData, | ||
CreateAttestation: in.CreateAttestation, | ||
CreateSignature: in.CreateSignature, | ||
} | ||
} | ||
|
||
// EncryptedCredentialToProto converts an attest.EncryptedCredential to | ||
// its protobuf representation. | ||
func EncryptedCredentialToProto(in *attest.EncryptedCredential) *proto.TPMEncryptedCredential { | ||
if in == nil { | ||
return nil | ||
} | ||
return &proto.TPMEncryptedCredential{ | ||
CredentialBlob: in.Credential, | ||
Secret: in.Secret, | ||
} | ||
} | ||
|
||
// EncryptedCredentialFromProto extracts an attest.EncryptedCredential from | ||
// its protobuf representation. | ||
func EncryptedCredentialFromProto(in *proto.TPMEncryptedCredential) *attest.EncryptedCredential { | ||
if in == nil { | ||
return nil | ||
} | ||
return &attest.EncryptedCredential{ | ||
Credential: in.CredentialBlob, | ||
Secret: in.Secret, | ||
} | ||
} |
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,52 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package tpm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-attestation/attest" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/gravitational/teleport/api/utils" | ||
) | ||
|
||
func TestAttestationParametersProto(t *testing.T) { | ||
want := attest.AttestationParameters{ | ||
Public: []byte("public"), | ||
CreateData: []byte("create_data"), | ||
CreateAttestation: []byte("create_attestation"), | ||
CreateSignature: []byte("create_signature"), | ||
} | ||
pb := AttestationParametersToProto(want) | ||
clonedPb := utils.CloneProtoMsg(pb) | ||
got := AttestationParametersFromProto(clonedPb) | ||
require.Equal(t, want, got) | ||
} | ||
|
||
func TestEncryptedCredentialProto(t *testing.T) { | ||
want := &attest.EncryptedCredential{ | ||
Credential: []byte("encrypted_credential"), | ||
Secret: []byte("secret"), | ||
} | ||
pb := EncryptedCredentialToProto(want) | ||
clonedPb := utils.CloneProtoMsg(pb) | ||
got := EncryptedCredentialFromProto(clonedPb) | ||
require.Equal(t, want, got) | ||
} |
Oops, something went wrong.