-
Notifications
You must be signed in to change notification settings - Fork 0
/
maa.go
35 lines (32 loc) · 926 Bytes
/
maa.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
package maa
import (
"context"
"fmt"
"net/http"
)
// Attest requests a JWT token from MAA for the current machine.
//
// This function combines NewParameters, GetEncryptedToken, and DecryptToken.
func Attest(ctx context.Context, nonce []byte, maaURL string, httpClient HttpClient) (string, error) {
tpm, err := newTPM(nil)
if err != nil {
return "", fmt.Errorf("opening TPM: %w", err)
}
defer tpm.Close()
params, err := newParameters(ctx, nonce, httpClient, tpm)
if err != nil {
return "", fmt.Errorf("getting system parameters: %w", err)
}
encryptedToken, err := GetEncryptedToken(ctx, params, nonce, maaURL, httpClient)
if err != nil {
return "", fmt.Errorf("getting token: %w", err)
}
token, err := decryptToken(encryptedToken, tpm)
if err != nil {
return "", fmt.Errorf("decrypting token: %w", err)
}
return token, nil
}
type HttpClient interface {
Do(*http.Request) (*http.Response, error)
}