mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
207bfd99af
* Refactor attestation handling to remove quoteprovider dependency - Removed references to quoteprovider in various files, replacing them with vtpm where necessary. - Updated function signatures and implementations to use SEVNonce instead of quoteprovider.Nonce. - Introduced new vtpm package to handle SEV-related attestation logic, including fetching and verifying attestation reports. - Adjusted tests to reflect changes in the attestation logic and ensure compatibility with the new structure. - Deleted the now redundant quoteprovider/sev_test.go file. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: Add veraison/go-cose dependency to go.mod Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Introduce TLS package for enhanced security configuration and refactor client code to utilize new TLS utilities Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
92 lines
1.8 KiB
Go
92 lines
1.8 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package http
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/ultravioletrs/cocos/pkg/clients"
|
|
"github.com/ultravioletrs/cocos/pkg/tls"
|
|
)
|
|
|
|
type Client interface {
|
|
Transport() *http.Transport
|
|
Secure() string
|
|
Timeout() time.Duration
|
|
}
|
|
|
|
type client struct {
|
|
transport *http.Transport
|
|
cfg clients.ClientConfiguration
|
|
security tls.Security
|
|
}
|
|
|
|
var _ Client = (*client)(nil)
|
|
|
|
func NewClient(cfg clients.ClientConfiguration) (Client, error) {
|
|
transport, security, err := createTransport(cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &client{
|
|
transport: transport,
|
|
cfg: cfg,
|
|
security: security,
|
|
}, nil
|
|
}
|
|
|
|
func (c *client) Transport() *http.Transport {
|
|
return c.transport
|
|
}
|
|
|
|
func (c *client) Secure() string {
|
|
return c.security.String()
|
|
}
|
|
|
|
func (c *client) Timeout() time.Duration {
|
|
return c.cfg.Config().Timeout
|
|
}
|
|
|
|
func createTransport(cfg clients.ClientConfiguration) (*http.Transport, tls.Security, error) {
|
|
transport := &http.Transport{
|
|
MaxIdleConns: 100,
|
|
IdleConnTimeout: 90 * time.Second,
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
|
}
|
|
|
|
security := tls.WithoutTLS
|
|
|
|
if agcfg, ok := cfg.(*clients.AttestedClientConfig); ok && agcfg.AttestedTLS {
|
|
result, err := tls.LoadATLSConfig(
|
|
agcfg.AttestationPolicy,
|
|
agcfg.ServerCAFile,
|
|
agcfg.ClientCert,
|
|
agcfg.ClientKey,
|
|
)
|
|
if err != nil {
|
|
return nil, security, err
|
|
}
|
|
|
|
transport.TLSClientConfig = result.Config
|
|
security = result.Security
|
|
} else {
|
|
conf := cfg.Config()
|
|
|
|
result, err := tls.LoadBasicConfig(conf.ServerCAFile, conf.ClientCert, conf.ClientKey)
|
|
if err != nil {
|
|
return nil, security, err
|
|
}
|
|
|
|
if result.Security != tls.WithoutTLS {
|
|
transport.TLSClientConfig = result.Config
|
|
}
|
|
|
|
security = result.Security
|
|
}
|
|
|
|
return transport, security, nil
|
|
}
|