blob: 87c22e6442860a64f9e757ec2a8e69ac4c21508a [file] [log] [blame]
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package hwsec
import (
// LocalVA implements the VA functionality by hwsec-test-va binary.
type LocalVA struct{}
// NewLocalVA creates a new instance of LocalVA.
func NewLocalVA() *LocalVA {
return &LocalVA{}
// GetDecodedVAChallenge get the VA challenge generated by hwsec-test-va.
func (rc *LocalVA) GetDecodedVAChallenge(ctx context.Context) ([]byte, error) {
out, err := testexec.CommandContext(ctx, "hwsec-test-va", "generate").Output()
if err != nil {
return nil, errors.Wrap(err, "failed to create challenge")
dec, err := base64.StdEncoding.DecodeString(string(out))
if err != nil {
return nil, errors.Wrap(err, "failed to decode challenge")
return dec, err
// VerifyEncodedVAChallenge asks hwsec-test-va to verify the challenge response.
func (rc *LocalVA) VerifyEncodedVAChallenge(ctx context.Context, signedChallenge string) error {
fd, err := ioutil.TempFile("", "tast-hwsec-test-va-challenge-response")
if err != nil {
return errors.Wrap(err, "error creating temp file")
defer os.Remove(fd.Name())
defer fd.Close()
if _, err := fd.WriteString(signedChallenge); err != nil {
return errors.Wrap(err, "failed to write challenge response")
if _, err := testexec.CommandContext(ctx, "hwsec-test-va", "verify", "--input="+fd.Name()).CombinedOutput(); err != nil {
return errors.Wrap(err, "verification failed")
return err