Преглед изворни кода

acme/authority: Polymorph the challenge type

Prior to validation, we must wrap the base challenge in the correct
concrete challenge type so that we dispatch the correct validation
method.
David Cowden пре 6 година
родитељ
комит
a857c45847
2 измењених фајлова са 14 додато и 1 уклоњено
  1. 1 1
      acme/authority.go
  2. 13 0
      acme/challenge.go

+ 1 - 1
acme/authority.go

@@ -372,7 +372,7 @@ func (a *Authority) validate(ch challenge, jwk *jose.JSONWebKey) (challenge, err
 	dialer := &net.Dialer{
 		Timeout: 30 * time.Second,
 	}
-	return ch.validate(jwk, validateOptions{
+	return ch.clone().morph().validate(jwk, validateOptions{
 		httpGet:   client.Get,
 		lookupTxt: net.LookupTXT,
 		tlsDial: func(network, addr string, config *tls.Config) (*tls.Conn, error) {

+ 13 - 0
acme/challenge.go

@@ -291,6 +291,19 @@ func unmarshalChallenge(data []byte) (challenge, error) {
 	}
 }
 
+func (bc *baseChallenge) morph() challenge {
+	switch bc.getType() {
+	case "dns-01":
+		return &dns01Challenge{bc}
+	case "http-01":
+		return &http01Challenge{bc}
+	case "tls-alpn-01":
+		return &tlsALPN01Challenge{bc}
+	default:
+		panic("unrecognized challenge type: " + bc.getType())
+	}
+}
+
 // Challenge retry information is internally relevant and needs to be stored in the DB, but should not be part
 // of the public challenge API apart from the Retry-After header.
 type Retry struct {