|
|
|
@ -22,6 +22,7 @@ package messages
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"crypto/x509"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"encoding/pem"
|
|
|
|
|
"fmt"
|
|
|
|
|
"math/big"
|
|
|
|
@ -144,6 +145,66 @@ func (i *HealthInfo) String() string {
|
|
|
|
|
return builder.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ProfileUsage string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
UsageOcsp ProfileUsage = "ocsp"
|
|
|
|
|
UsagePerson ProfileUsage = "person"
|
|
|
|
|
UsageClient ProfileUsage = "client"
|
|
|
|
|
UsageCode ProfileUsage = "code"
|
|
|
|
|
UsageServer ProfileUsage = "server"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var validProfileUsages = map[string]ProfileUsage{
|
|
|
|
|
"ocsp": UsageOcsp,
|
|
|
|
|
"person": UsagePerson,
|
|
|
|
|
"client": UsageClient,
|
|
|
|
|
"code": UsageCode,
|
|
|
|
|
"server": UsageServer,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ParseUsage(u string) (ProfileUsage, error) {
|
|
|
|
|
usage, ok := validProfileUsages[u]
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", fmt.Errorf("unsupported profile usage: %s", u)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return usage, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CAProfile struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
UseFor ProfileUsage `json:"use-for"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p CAProfile) String() string {
|
|
|
|
|
return fmt.Sprintf("profile['%s': '%s']", p.Name, p.UseFor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CertificateInfo struct {
|
|
|
|
|
Status string `json:"status"`
|
|
|
|
|
Signing bool `json:"signing"`
|
|
|
|
|
Profiles []CAProfile `json:"profiles"`
|
|
|
|
|
ValidUntil time.Time `json:"valid-until"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i CertificateInfo) String() string {
|
|
|
|
|
marshal, _ := json.Marshal(i)
|
|
|
|
|
|
|
|
|
|
return string(marshal)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *HealthInfo) ParseCertificateInfo(info string) (*CertificateInfo, error) {
|
|
|
|
|
certInfo := CertificateInfo{}
|
|
|
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(info), &certInfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("could not parse certificate information: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &certInfo, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HealthResponse struct {
|
|
|
|
|
Version string `msgpack:"version"`
|
|
|
|
|
Healthy bool `msgpack:"healthy"`
|
|
|
|
|