Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acme/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Challenge struct {
Token string `json:"token,omitempty"`
Status string `json:"status"`
AccountURI string `json:"accounturi,omitempty"`
IssuerDomainNames []string `json:"issuer-domain-names,omitempty"`
IssuerDomainNames []string `json:"issuerDomainNames,omitempty"`
Validated string `json:"validated,omitempty"`
Error *ProblemDetails `json:"error,omitempty"`
}
12 changes: 11 additions & 1 deletion cmd/pebble/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type config struct {
ExternalAccountBindingRequired bool
ExternalAccountMACKeys map[string]string
CAAIdentities []string
AccountHashPrefix string
// Configure policies to deny certain domains
DomainBlocklist []string
KeyAlgorithm string
Expand Down Expand Up @@ -125,9 +126,18 @@ func main() {
}
}

accountHashPrefix := c.Pebble.AccountHashPrefix
if accountHashPrefix == "" {
logger.Println("No AccountHashPrefix configured, using default [https://pebble.letsencrypt.org/hashed-accounts/]")
accountHashPrefix = "https://pebble.letsencrypt.org/hashed-accounts/"
}
if !strings.HasSuffix(accountHashPrefix, "/") {
accountHashPrefix = accountHashPrefix + "/" // make it in dir format
}

db := db.NewMemoryStore()
ca := ca.New(logger, db, c.Pebble.OCSPResponderURL, keyAlg, alternateRoots, chainLength, profiles)
va := va.New(logger, c.Pebble.HTTPPort, c.Pebble.TLSPort, *strictMode, *resolverAddress, db)
va := va.New(logger, c.Pebble.HTTPPort, c.Pebble.TLSPort, *strictMode, *resolverAddress, db, accountHashPrefix)

for keyID, key := range c.Pebble.ExternalAccountMACKeys {
err := db.AddExternalAccountKeyByID(keyID, key)
Expand Down
7 changes: 4 additions & 3 deletions core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ type Authorization struct {
type Challenge struct {
sync.RWMutex
acme.Challenge
ID string
Authz *Authorization
ValidatedDate time.Time
ID string
Authz *Authorization
ValidatedDate time.Time
AncestorDomain string
}

func (ch *Challenge) ExpectedKeyAuthorization(key *jose.JSONWebKey) string {
Expand Down
125 changes: 120 additions & 5 deletions va/va.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package va

import (
"context"
"crypto"
"crypto/sha256"
"crypto/subtle"
"crypto/tls"
Expand All @@ -11,6 +12,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"hash"
"io"
"log"
"math/rand"
Expand Down Expand Up @@ -111,6 +113,7 @@ type VAImpl struct {
strict bool
customResolverAddr string
dnsClient *dns.Client
AccountHashPrefix string // exported so wfe can publish it in meta

// The VA having a DB client is indeed strange. This is only used to
// facilitate va.setOrderError changing the ARI related order replacement
Expand All @@ -123,6 +126,7 @@ func New(
httpPort, tlsPort int,
strict bool, customResolverAddr string,
db *db.MemoryStore,
accountHashPrefix string,
) *VAImpl {
va := &VAImpl{
log: log,
Expand All @@ -134,6 +138,7 @@ func New(
strict: strict,
customResolverAddr: customResolverAddr,
db: db,
AccountHashPrefix: accountHashPrefix,
}

if customResolverAddr != "" {
Expand Down Expand Up @@ -566,6 +571,11 @@ type dnsPersistIssueValue struct {
persistUntil *time.Time
}

type dnsPersistHashedAccountURI struct {
hashAlg hash.Hash
value string
}

// trimWSP trims RFC 8659 whitespace characters (space and tab) from the
// beginning and end of a string.
func trimWSP(s string) string {
Expand Down Expand Up @@ -658,13 +668,74 @@ func parseDNSPersistIssueValues(issuerDomainName string, paramsRaw []string) (*d
return result, nil
}

// splitAccountURI accepts hashprefix and accounturi in TXT record,
// split and parse it into hash algorithm and actual hash
func splitAccountURI(prefix string, accounturi string) (*dnsPersistHashedAccountURI, error) {
if !strings.HasPrefix(accounturi, prefix) {
return nil, fmt.Errorf("accountHashPrefix does not match, expected %s", prefix)
}
// calculate account hash format, as defined in draft-ietf-acme-dns-persist-03
temp := strings.Split(strings.TrimPrefix(accounturi, prefix), "/")
if len(temp) != 2 {
return nil, fmt.Errorf("accounthash does not contain hash algorithm")
}

hashalgstring := temp[0] // hash alg: keep mind IANA have names in lowercase
observedhash := temp[1]

var hashalg hash.Hash
switch hashalgstring { // use a bunch of allowed hash algs
case "sha-256":
hashalg = crypto.SHA256.New()
case "sha-384":
hashalg = crypto.SHA384.New()
case "sha-512":
hashalg = crypto.SHA512.New()
case "sha3-256":
hashalg = crypto.SHA3_256.New()
case "sha3-384":
hashalg = crypto.SHA3_384.New()
case "sha3-512":
hashalg = crypto.SHA3_512.New()
default:
return nil, fmt.Errorf("accountHash has unsupported hash algorithm %s", temp[0])
}
return &dnsPersistHashedAccountURI{
hashAlg: hashalg,
value: observedhash,
}, nil
}

func (va VAImpl) validateDNSPersist01(task *vaTask) *core.ValidationRecord {
needWildcardPolicy := task.Wildcard
validationTargetDomain := task.Identifier.Value
challengeSubdomain := fmt.Sprintf("%s.%s", "_validation-persist", task.Identifier.Value)
result := &core.ValidationRecord{
URL: challengeSubdomain,
ValidatedAt: time.Now(),
}

// if AncestorDomain is included, check its allowed and change challenge subdomain into it
if task.Challenge.AncestorDomain != "" {
challengeSubdomain = fmt.Sprintf("%s.%s", "_validation-persist", task.Challenge.AncestorDomain)
validationTargetDomain = task.Challenge.AncestorDomain
result.URL = challengeSubdomain
// if one set AncestorDomain it validating txt record need wildcard policy
needWildcardPolicy = true
if !strings.HasSuffix(task.Identifier.Value, ("." + task.Challenge.AncestorDomain)) {
result.Error = acme.UnauthorizedProblem(
fmt.Sprintf("requested AncestorDomain %s is not subdomain of requested ident %s",
task.Challenge.AncestorDomain, task.Identifier.Value))
return result
}
if !strings.Contains(task.Challenge.AncestorDomain, ".") {
result.Error = acme.UnauthorizedProblem(
fmt.Sprintf("requested AncestorDomain %s is a TLD, rejected",
task.Challenge.AncestorDomain))
return result
}
}

txtRecords, err := va.getTXTEntry(challengeSubdomain)
if err != nil {
result.Error = acme.UnauthorizedProblem(
Expand Down Expand Up @@ -702,17 +773,61 @@ func (va VAImpl) validateDNSPersist01(task *vaTask) *core.ValidationRecord {
"Error parsing DNS-PERSIST-01 challenge TXT record with issuer-domain-name %q: missing mandatory accountURI parameter", receivedIssuer))
continue
}
if params.accountURI != task.AccountURL {

if params.accountURI == task.AccountURL {
syntaxErrs = append(syntaxErrs, fmt.Sprintf(
"Error parsing DNS-PERSIST-01 challenge TXT record with issuer-domain-name %q: this record uses raw AcccountURI, Please use hashed format",
receivedIssuer))
continue
}

hashedAccURI, err := splitAccountURI(va.AccountHashPrefix, params.accountURI)
if err != nil {
syntaxErrs = append(syntaxErrs, fmt.Sprintf(
"Error parsing DNS-PERSIST-01 challenge TXT record with issuer-domain-name %q: %s", receivedIssuer, err.Error()))
continue
}

// building account hash
thumbprint, err := task.Account.Key.Thumbprint(crypto.SHA256)
if err != nil {
// Shouldn't fail for valid account, but if it failed we can't succeed this challgne at large
result.Error = acme.InternalErrorProblem(fmt.Sprintf(
"Error building thumbprint for account %s: %s", task.AccountURL, err.Error()))
return result
}

key := []byte(base64.RawURLEncoding.EncodeToString(thumbprint))
accountidentsurffix := append(key, []byte(task.AccountURL)...)

hashedAccURI.hashAlg.Reset()
globalAccHashIn := []byte{0x1, '*'} // global accounthash, see Section 4.1
globalAccHashIn = append(globalAccHashIn, accountidentsurffix...)
hashedAccURI.hashAlg.Write(globalAccHashIn)
globalAccHashStr := base64.RawURLEncoding.EncodeToString(hashedAccURI.hashAlg.Sum(nil))

hashedAccURI.hashAlg.Reset()
perdomainAcchashIn := []byte{byte(len(validationTargetDomain))} // per domain accounthash value
perdomainAcchashIn = append(perdomainAcchashIn, []byte(validationTargetDomain)...)
perdomainAcchashIn = append(perdomainAcchashIn, accountidentsurffix...)
hashedAccURI.hashAlg.Write(perdomainAcchashIn)
perdomainAcchashStr := base64.RawURLEncoding.EncodeToString(hashedAccURI.hashAlg.Sum(nil))

validAccountURIs := []string{perdomainAcchashStr, globalAccHashStr}

if !slices.Contains(validAccountURIs, hashedAccURI.value) {
authorizationErrs = append(authorizationErrs, fmt.Sprintf(
"Error parsing DNS-PERSIST-01 challenge TXT record with issuer-domain-name %q: accounturi mismatch: expected %q, got %q",
receivedIssuer, task.AccountURL, params.accountURI))
// tell hash expected for debug
"Error parsing DNS-PERSIST-01 challenge TXT record with issuer-domain-name %q: "+
"accounthash mismatch: expected %s for validation target %s, %s for domain-correlation opt-out, got %q",
receivedIssuer, validAccountURIs[0], validationTargetDomain, validAccountURIs[1], hashedAccURI.value))
continue
}
// Per the dns-persist-01 specification, if the policy tag is present
// parameter's defined values MUST be treated as case-insensitive.
if task.Wildcard && strings.ToLower(params.policy) != "wildcard" {
if needWildcardPolicy && strings.ToLower(params.policy) != "wildcard" {
authorizationErrs = append(authorizationErrs, fmt.Sprintf(
"Error parsing DNS-PERSIST-01 challenge TXT record with issuer-domain-name %q: policy mismatch: expected \"wildcard\", got %q",
"Error parsing DNS-PERSIST-01 challenge TXT record with issuer-domain-name %q: policy mismatch: required \"wildcard\", got %q",
receivedIssuer, params.policy))
continue
}
Expand Down
Loading
Loading