2021-02-25 18:24:24 +00:00
|
|
|
package acme
|
|
|
|
|
|
|
|
import (
|
2021-03-01 06:49:20 +00:00
|
|
|
"crypto"
|
|
|
|
"encoding/base64"
|
2021-02-25 18:24:24 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"go.step.sm/crypto/jose"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Account is a subset of the internal account type containing only those
|
|
|
|
// attributes required for responses in the ACME protocol.
|
|
|
|
type Account struct {
|
|
|
|
Contact []string `json:"contact,omitempty"`
|
2021-03-01 06:49:20 +00:00
|
|
|
Status Status `json:"status"`
|
2021-02-25 18:24:24 +00:00
|
|
|
Orders string `json:"orders"`
|
|
|
|
ID string `json:"-"`
|
|
|
|
Key *jose.JSONWebKey `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToLog enables response logging.
|
|
|
|
func (a *Account) ToLog() (interface{}, error) {
|
|
|
|
b, err := json.Marshal(a)
|
|
|
|
if err != nil {
|
2021-03-05 07:10:46 +00:00
|
|
|
return nil, WrapErrorISE(err, "error marshaling account for logging")
|
2021-02-25 18:24:24 +00:00
|
|
|
}
|
|
|
|
return string(b), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetID returns the account ID.
|
|
|
|
func (a *Account) GetID() string {
|
|
|
|
return a.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetKey returns the JWK associated with the account.
|
|
|
|
func (a *Account) GetKey() *jose.JSONWebKey {
|
|
|
|
return a.Key
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsValid returns true if the Account is valid.
|
|
|
|
func (a *Account) IsValid() bool {
|
2021-02-28 18:09:06 +00:00
|
|
|
return Status(a.Status) == StatusValid
|
2021-02-25 18:24:24 +00:00
|
|
|
}
|
2021-03-01 06:49:20 +00:00
|
|
|
|
|
|
|
// KeyToID converts a JWK to a thumbprint.
|
|
|
|
func KeyToID(jwk *jose.JSONWebKey) (string, error) {
|
|
|
|
kid, err := jwk.Thumbprint(crypto.SHA256)
|
|
|
|
if err != nil {
|
2021-03-05 07:10:46 +00:00
|
|
|
return "", WrapErrorISE(err, "error generating jwk thumbprint")
|
2021-03-01 06:49:20 +00:00
|
|
|
}
|
|
|
|
return base64.RawURLEncoding.EncodeToString(kid), nil
|
|
|
|
}
|