File: optee.go

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (64 lines) | stat: -rw-r--r-- 1,944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
 * Copyright (C) Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package optee

import (
	"github.com/snapcore/snapd/osutil"
	"github.com/snapcore/snapd/testutil"
)

var (
	newClient = newFDETAClient
)

// FDETAClient represents an interface to our FDE trusted application.
type FDETAClient interface {
	// Present returns true if the FDE TA is present.
	Present() bool

	// DecryptKey requests that the FDE TA decrypt the given key, using the
	// handle as supplimentary information. The decrypted key is returned.
	DecryptKey(input []byte, handle []byte) ([]byte, error)

	// EncryptKey requests that the FDE TA encrypt the given key. A handle and
	// the encrypted key are returned.
	EncryptKey(input []byte) (handle []byte, sealed []byte, err error)

	// Lock requests that the FDE TA be locked. This will prevent it from being
	// used further.
	Lock() error

	// Version returns the version of the FDE TA.
	Version() (int, error)
}

// NewFDETAClient returns a new [FDETAClient].
func NewFDETAClient() FDETAClient {
	return newClient()
}

// MockNewFDETAClient mocks the function called by [NewFDETAClient]. Should only
// be used in tests.
func MockNewFDETAClient(c FDETAClient) (restore func()) {
	osutil.MustBeTestBinary("can only mock optee client in tests")
	return testutil.Mock(&newClient, func() FDETAClient {
		return c
	})
}