4
0
Эх сурвалжийг харах

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 жил өмнө
parent
commit
a857c45847

+ 1 - 1
acme/authority.go

@@ -372,7 +372,7 @@ func (a *Authority) validate(ch challenge, jwk *jose.JSONWebKey) (challenge, err
 	dialer := &net.Dialer{
 	dialer := &net.Dialer{
 		Timeout: 30 * time.Second,
 		Timeout: 30 * time.Second,
 	}
 	}
-	return ch.validate(jwk, validateOptions{
+	return ch.clone().morph().validate(jwk, validateOptions{
 		httpGet:   client.Get,
 		httpGet:   client.Get,
 		lookupTxt: net.LookupTXT,
 		lookupTxt: net.LookupTXT,
 		tlsDial: func(network, addr string, config *tls.Config) (*tls.Conn, error) {
 		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
 // 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.
 // of the public challenge API apart from the Retry-After header.
 type Retry struct {
 type Retry struct {