-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #522 from flatcar/jepio/tpm-refactor
qemu: extract swtpm
- Loading branch information
Showing
7 changed files
with
82 additions
and
58 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,51 @@ | ||
package local | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/coreos/pkg/capnslog" | ||
"github.com/flatcar/mantle/system/exec" | ||
"github.com/flatcar/mantle/util" | ||
) | ||
|
||
type SoftwareTPM struct { | ||
process *exec.ExecCmd | ||
socketPath string | ||
dir string | ||
} | ||
|
||
func NewSwtpm(dir string) (*SoftwareTPM, error) { | ||
swtpm := &SoftwareTPM{} | ||
|
||
os.Mkdir(dir, 0700) | ||
swtpm.dir = dir | ||
swtpm.socketPath = fmt.Sprintf("%v/sock", swtpm.dir) | ||
|
||
swtpm.process = exec.Command("swtpm", "socket", "--tpmstate", fmt.Sprintf("dir=%v", swtpm.dir), "--ctrl", fmt.Sprintf("type=unixio,path=%v", swtpm.socketPath), "--tpm2") | ||
out, err := swtpm.process.StderrPipe() | ||
if err != nil { | ||
return nil, err | ||
} | ||
go util.LogFrom(capnslog.INFO, out) | ||
|
||
if err = swtpm.process.Start(); err != nil { | ||
return nil, err | ||
} | ||
|
||
plog.Debugf("swtpm PID: %v", swtpm.process.Pid()) | ||
|
||
return swtpm, nil | ||
} | ||
|
||
func (swtpm *SoftwareTPM) Stop() { | ||
if err := swtpm.process.Kill(); err != nil { | ||
plog.Errorf("Error killing swtpm: %v", err) | ||
} | ||
plog.Debugf("Delete swtpm temporary directory %v", swtpm.dir) | ||
os.RemoveAll(swtpm.dir) | ||
} | ||
|
||
func (swtpm *SoftwareTPM) SocketPath() string { | ||
return swtpm.socketPath | ||
} |
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 |
---|---|---|
|
@@ -44,6 +44,8 @@ type Options struct { | |
|
||
ExtraBaseDiskSize string | ||
|
||
EnableTPM bool | ||
|
||
*platform.Options | ||
} | ||
|
||
|
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