Fixup tests, add testing pipelines and small refactors

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
This commit is contained in:
Ettore Di Giacinto
2022-02-17 10:10:04 +01:00
parent 1ab3e10e4d
commit e5997ada4c
12 changed files with 200 additions and 60 deletions

22
get.go
View File

@@ -16,11 +16,21 @@ import (
"github.com/sirupsen/logrus"
)
func Get(cacerts []byte, url string, header http.Header, opts ...Option) ([]byte, error) {
// Get retrieves a message from a remote ws server after
// a successfully process of the TPM challenge
func Get(url string, opts ...Option) ([]byte, error) {
c := &config{}
c.apply(opts...)
header := c.header
if c.header == nil {
header = http.Header{}
}
dialer := websocket.DefaultDialer
if len(cacerts) > 0 {
if len(c.cacerts) > 0 {
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(cacerts)
pool.AppendCertsFromPEM(c.cacerts)
dialer = &websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
HandshakeTimeout: 45 * time.Second,
@@ -30,9 +40,6 @@ func Get(cacerts []byte, url string, header http.Header, opts ...Option) ([]byte
}
}
c := &Config{}
c.Apply(opts...)
attestationData, aikBytes, err := getAttestationData(c)
if err != nil {
return nil, err
@@ -48,9 +55,6 @@ func Get(cacerts []byte, url string, header http.Header, opts ...Option) ([]byte
return nil, err
}
if header == nil {
header = http.Header{}
}
header.Add("Authorization", token)
wsURL := strings.Replace(url, "http", "ws", 1)
logrus.Infof("Using TPMHash %s to dial %s", hash, wsURL)