forked from TrueCloudLab/lego
Switch DNS-01 challenge over to central validation function
This commit is contained in:
parent
0c1adedebe
commit
08cd016ed3
3 changed files with 4 additions and 46 deletions
|
@ -108,7 +108,7 @@ func (c *Client) SetChallengeProvider(challenge Challenge, p ChallengeProvider)
|
||||||
case TLSSNI01:
|
case TLSSNI01:
|
||||||
c.solvers[challenge] = &tlsSNIChallenge{jws: c.jws, validate: validate, provider: p}
|
c.solvers[challenge] = &tlsSNIChallenge{jws: c.jws, validate: validate, provider: p}
|
||||||
case DNS01:
|
case DNS01:
|
||||||
c.solvers[challenge] = &dnsChallenge{jws: c.jws, provider: p}
|
c.solvers[challenge] = &dnsChallenge{jws: c.jws, validate: validate, provider: p}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown challenge %v", challenge)
|
return fmt.Errorf("Unknown challenge %v", challenge)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,9 @@ package acme
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -34,6 +32,7 @@ func DNS01Record(domain, keyAuth string) (fqdn string, value string, ttl int) {
|
||||||
// dnsChallenge implements the dns-01 challenge according to ACME 7.5
|
// dnsChallenge implements the dns-01 challenge according to ACME 7.5
|
||||||
type dnsChallenge struct {
|
type dnsChallenge struct {
|
||||||
jws *jws
|
jws *jws
|
||||||
|
validate validateFunc
|
||||||
provider ChallengeProvider
|
provider ChallengeProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,48 +65,7 @@ func (s *dnsChallenge) Solve(chlng challenge, domain string) error {
|
||||||
|
|
||||||
preCheckDNS(domain, fqdn)
|
preCheckDNS(domain, fqdn)
|
||||||
|
|
||||||
jsonBytes, err := json.Marshal(challenge{Resource: "challenge", Type: chlng.Type, Token: chlng.Token, KeyAuthorization: keyAuth})
|
return s.validate(s.jws, domain, chlng.URI, chlng)
|
||||||
if err != nil {
|
|
||||||
return errors.New("Failed to marshal network message...")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell the server we handle DNS-01
|
|
||||||
resp, err := s.jws.post(chlng.URI, jsonBytes)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Failed to post JWS message. -> %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Repeatedly check the server for an updated status on our request.
|
|
||||||
var challengeResponse challenge
|
|
||||||
Loop:
|
|
||||||
for {
|
|
||||||
if resp.StatusCode >= http.StatusBadRequest {
|
|
||||||
return handleHTTPError(resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&challengeResponse)
|
|
||||||
resp.Body.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch challengeResponse.Status {
|
|
||||||
case "valid":
|
|
||||||
logf("The server validated our request")
|
|
||||||
break Loop
|
|
||||||
case "pending":
|
|
||||||
break
|
|
||||||
case "invalid":
|
|
||||||
return errors.New("The server could not validate our request.")
|
|
||||||
default:
|
|
||||||
return errors.New("The server returned an unexpected state.")
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
resp, err = http.Get(chlng.URI)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkDNS(domain, fqdn string) bool {
|
func checkDNS(domain, fqdn string) bool {
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestDNSValidServerResponse(t *testing.T) {
|
||||||
|
|
||||||
manualProvider, _ := NewDNSProviderManual()
|
manualProvider, _ := NewDNSProviderManual()
|
||||||
jws := &jws{privKey: privKey.(*rsa.PrivateKey), directoryURL: ts.URL}
|
jws := &jws{privKey: privKey.(*rsa.PrivateKey), directoryURL: ts.URL}
|
||||||
solver := &dnsChallenge{jws: jws, provider: manualProvider}
|
solver := &dnsChallenge{jws: jws, validate: validate, provider: manualProvider}
|
||||||
clientChallenge := challenge{Type: "dns01", Status: "pending", URI: ts.URL, Token: "http8"}
|
clientChallenge := challenge{Type: "dns01", Status: "pending", URI: ts.URL, Token: "http8"}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
Loading…
Reference in a new issue