mirror of
https://github.com/kairos-io/kcrypt-challenger.git
synced 2025-08-02 15:38:19 +00:00
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package client
|
|
|
|
import (
|
|
"github.com/kairos-io/kairos-sdk/collector"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// There are the directories under which we expect to find kairos configuration.
|
|
// When we are booted from an iso (during installation), configuration is expected
|
|
// under `/oem`. When we are booting an installed system (in initramfs phase),
|
|
// the path is `/sysroot/oem`.
|
|
// When we run the challenger in hooks, we may have the config under /tmp/oem
|
|
var confScanDirs = []string{"/oem", "/sysroot/oem", "/tmp/oem"}
|
|
|
|
type Client struct {
|
|
Config Config
|
|
}
|
|
|
|
type Config struct {
|
|
Kcrypt struct {
|
|
Challenger struct {
|
|
MDNS bool `yaml:"mdns,omitempty"`
|
|
Server string `yaml:"challenger_server,omitempty"`
|
|
NVIndex string `yaml:"nv_index,omitempty"` // Non-volatile index memory: where we store the encrypted passphrase (offline mode)
|
|
CIndex string `yaml:"c_index,omitempty"` // Certificate index: this is where the rsa pair that decrypts the passphrase lives
|
|
TPMDevice string `yaml:"tpm_device,omitempty"`
|
|
Certificate string `yaml:"certificate,omitempty"`
|
|
}
|
|
}
|
|
}
|
|
|
|
func unmarshalConfig() (Config, error) {
|
|
var result Config
|
|
|
|
o := &collector.Options{NoLogs: true, MergeBootCMDLine: false}
|
|
if err := o.Apply(collector.Directories(confScanDirs...)); err != nil {
|
|
return result, err
|
|
}
|
|
|
|
c, err := collector.Scan(o, func(d []byte) ([]byte, error) {
|
|
return d, nil
|
|
})
|
|
if err != nil {
|
|
return result, err
|
|
}
|
|
|
|
a, _ := c.String()
|
|
err = yaml.Unmarshal([]byte(a), &result)
|
|
if err != nil {
|
|
return result, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|