From 84c2bceade15d6afe93fd78c5d84e890868c67ed Mon Sep 17 00:00:00 2001 From: xenolf Date: Fri, 12 Jun 2015 00:15:13 +0200 Subject: [PATCH] Add initial implementation for challenge choosing --- acme/client.go | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/acme/client.go b/acme/client.go index 1927981a..d339a772 100644 --- a/acme/client.go +++ b/acme/client.go @@ -143,11 +143,39 @@ func (c *Client) ObtainCertificates(domains []string) error { // Looks through the challenge combinations to find a solvable match. // Then solves the challenges in series and returns. -func (c *Client) solveChallenges(challenges []*authorizationResource) { +func (c *Client) solveChallenges(challenges []*authorizationResource) error { // loop through the resources, basically through the domains. - for _, authz := challenges { - + for _, authz := range challenges { + // no solvers - no solving + if solvers := c.chooseSolvers(authz.Body); solvers != nil { + for i, solver := range solvers { + solver.Solve(authz.Body.Challenges[i], authz.Domain) + } + } else { + return fmt.Errorf("Could not determine solvers for %s", authz.Domain) + } } + + return nil +} + +// Checks all combinations from the server and returns an array of +// solvers which should get executed in series. +func (c *Client) chooseSolvers(auth authorization) map[int]solver { + for _, combination := range auth.Combinations { + solvers := make(map[int]solver) + for i := range combination { + if solver, ok := c.Solvers[auth.Challenges[i].Type]; ok { + solvers[i] = solver + } + } + + // If we can solve the whole combination, return the solvers + if len(solvers) == len(combination) { + return solvers + } + } + return nil } // Get the challenges needed to proof our identifier to the ACME server.