-
Notifications
You must be signed in to change notification settings - Fork 17
/
certificates.go
43 lines (35 loc) · 1017 Bytes
/
certificates.go
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
/*
* Copyright (c) 2023 Intel Corporation
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*/
package connector
import (
"fmt"
"io"
"net/http"
"github.com/pkg/errors"
)
// GetTokenSigningCertificates is used to get Trust Authority attestation token signing certificates
func (connector *trustAuthorityConnector) GetTokenSigningCertificates() ([]byte, error) {
url := fmt.Sprintf("%s/certs", connector.cfg.BaseUrl)
newRequest := func() (*http.Request, error) {
return http.NewRequest(http.MethodGet, url, nil)
}
var headers = map[string]string{
headerAccept: mimeApplicationJson,
}
var jwks []byte
processResponse := func(resp *http.Response) error {
var err error
jwks, err = io.ReadAll(resp.Body)
if err != nil {
return errors.Errorf("Failed to read body from %s: %s", url, err)
}
return nil
}
if err := doRequest(*connector.rclient, connector.cfg.TlsCfg, newRequest, nil, headers, processResponse); err != nil {
return nil, err
}
return jwks, nil
}