2019-07-19 20:05:18 +00:00
|
|
|
// Copyright 2019 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
// use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
// the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing permissions and limitations under
|
|
|
|
// the License.
|
|
|
|
|
2021-12-09 00:43:38 +00:00
|
|
|
// +build linux,!gofuzz,cgo,tspi
|
2019-07-19 20:05:18 +00:00
|
|
|
|
|
|
|
package attest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-12-08 23:06:48 +00:00
|
|
|
"github.com/google/go-tspi/attestation"
|
2019-07-19 20:05:18 +00:00
|
|
|
)
|
|
|
|
|
2020-05-05 23:56:57 +00:00
|
|
|
// trousersKey12 represents a key bound to a TPM 1.2 device via tcsd.
|
|
|
|
type trousersKey12 struct {
|
2019-07-19 20:05:18 +00:00
|
|
|
blob []byte
|
|
|
|
public []byte
|
2019-07-22 16:18:51 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 23:56:57 +00:00
|
|
|
func newTrousersKey12(blob, public []byte) ak {
|
|
|
|
return &trousersKey12{
|
2019-07-30 17:27:57 +00:00
|
|
|
blob: blob,
|
|
|
|
public: public,
|
|
|
|
}
|
2019-07-19 20:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Marshal represents the key in a persistent format which may be
|
|
|
|
// loaded at a later time using tpm.LoadKey().
|
2020-05-05 23:56:57 +00:00
|
|
|
func (k *trousersKey12) marshal() ([]byte, error) {
|
2019-07-19 20:05:18 +00:00
|
|
|
out := serializedKey{
|
|
|
|
Encoding: keyEncodingEncrypted,
|
|
|
|
TPMVersion: TPMVersion12,
|
|
|
|
Blob: k.blob,
|
|
|
|
Public: k.public,
|
|
|
|
}
|
|
|
|
return out.Serialize()
|
|
|
|
}
|
|
|
|
|
2020-05-05 23:56:57 +00:00
|
|
|
func (k *trousersKey12) close(tpm tpmBase) error {
|
2019-07-19 20:05:18 +00:00
|
|
|
return nil // No state for tpm 1.2.
|
|
|
|
}
|
|
|
|
|
2020-05-05 23:56:57 +00:00
|
|
|
func (k *trousersKey12) activateCredential(tb tpmBase, in EncryptedCredential) ([]byte, error) {
|
|
|
|
t, ok := tb.(*trousersTPM)
|
2020-05-05 21:56:40 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("expected *linuxTPM, got %T", tb)
|
|
|
|
}
|
|
|
|
|
2019-07-19 20:05:18 +00:00
|
|
|
cred, err := attestation.AIKChallengeResponse(t.ctx, k.blob, in.Credential, in.Secret)
|
|
|
|
if err != nil {
|
2019-10-03 19:32:50 +00:00
|
|
|
return nil, fmt.Errorf("failed to activate ak: %v", err)
|
2019-07-19 20:05:18 +00:00
|
|
|
}
|
|
|
|
return cred, nil
|
|
|
|
}
|
|
|
|
|
2020-05-05 23:56:57 +00:00
|
|
|
func (k *trousersKey12) quote(tb tpmBase, nonce []byte, alg HashAlg) (*Quote, error) {
|
|
|
|
t, ok := tb.(*trousersTPM)
|
2020-05-05 21:56:40 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("expected *linuxTPM, got %T", tb)
|
|
|
|
}
|
2019-09-18 17:16:00 +00:00
|
|
|
if alg != HashSHA1 {
|
2019-09-23 19:37:40 +00:00
|
|
|
return nil, fmt.Errorf("only SHA1 algorithms supported on TPM 1.2, not %v", alg)
|
2019-09-18 17:16:00 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 20:05:18 +00:00
|
|
|
quote, rawSig, err := attestation.GetQuote(t.ctx, k.blob, nonce)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Quote() failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Quote{
|
|
|
|
Version: TPMVersion12,
|
|
|
|
Quote: quote,
|
|
|
|
Signature: rawSig,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-05-05 23:56:57 +00:00
|
|
|
func (k *trousersKey12) attestationParameters() AttestationParameters {
|
2019-07-23 22:22:53 +00:00
|
|
|
return AttestationParameters{
|
|
|
|
Public: k.public,
|
|
|
|
UseTCSDActivationFormat: true,
|
2019-07-19 20:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-23 21:41:30 +00:00
|
|
|
|
|
|
|
func (k *trousersKey12) certify(tb tpmBase, handle interface{}) (*CertificationParameters, error) {
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
}
|