aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-10 20:16:59 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-10 20:16:59 +0100
commitae870e2238178ef86a68818171cb1ef0eeb9d5d1 (patch)
tree371591f2116bf40f922496198291e3f02112ceb2
parentcb9a55bd70137add83aa05d4b850d3af25c7a6fc (diff)
HTTP Solver
-rw-r--r--cmd/acme/docker.toml2
-rw-r--r--cmd/acme/main.go1
-rw-r--r--cmd/acme/solve_http.go23
-rw-r--r--desire.go1
-rw-r--r--provider.go1
5 files changed, 17 insertions, 11 deletions
diff --git a/cmd/acme/docker.toml b/cmd/acme/docker.toml
index d9f54ca..bd1c359 100644
--- a/cmd/acme/docker.toml
+++ b/cmd/acme/docker.toml
@@ -1,6 +1,6 @@
[defaults]
gracetime = "168h" # 1 week
-listen = ":8080"
+listen = "localhost:8080"
basedir = ".acme" # usually "/etc/ssl"
provider = "les"
account = "webmaster"
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index 1dbc496..dffeda0 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -88,6 +88,7 @@ func main() {
},
Webroot: des.Webroot,
}
+ hs.Init()
acme.RegisterSolver(acme.ChallengeHTTP, hs)
wg.Add(1)
diff --git a/cmd/acme/solve_http.go b/cmd/acme/solve_http.go
index 8c8c7bc..f9ab400 100644
--- a/cmd/acme/solve_http.go
+++ b/cmd/acme/solve_http.go
@@ -1,9 +1,9 @@
package main
import (
+ "io"
"log"
"net/http"
- "os"
"path"
"dim13.org/acme"
@@ -13,12 +13,26 @@ type httpChallenge struct {
http.Server
Webroot string
file string
+ started bool
+}
+
+func (c *httpChallenge) Init() error {
+ if !c.started {
+ go c.ListenAndServe()
+ c.started = true
+ }
+ return nil
}
func (c *httpChallenge) Solve(token, keyAuth string) error {
log.Println("solver", c)
if c.Webroot != "" {
return c.solveWebroot(token, keyAuth)
+ } else {
+ p := path.Join(acme.WellKnown, token)
+ http.HandleFunc(p, func(w http.ResponseWriter, r *http.Request) {
+ io.WriteString(w, keyAuth)
+ })
}
return nil
}
@@ -34,10 +48,3 @@ func (c *httpChallenge) solveWebroot(token, keyAuth string) error {
_, err = fd.Write([]byte(keyAuth))
return err
}
-
-func (c *httpChallenge) Finish() error {
- if c.Webroot != "" {
- return os.Remove(c.file)
- }
- return nil
-}
diff --git a/desire.go b/desire.go
index 7811db0..cfb691c 100644
--- a/desire.go
+++ b/desire.go
@@ -18,7 +18,6 @@ type Desire struct {
// Solver decribes a solving interface
type Solver interface {
Solve(token, keyAuth string) error
- Finish() error
}
const WellKnown = `/.well-known/acme-challenge/`
diff --git a/provider.go b/provider.go
index 8529044..e4d1576 100644
--- a/provider.go
+++ b/provider.go
@@ -273,7 +273,6 @@ func (p *Provider) Authorize(s ThumbSigner, d *Desire) error {
if err != nil {
return err
}
- defer sol.Finish()
var done bool
for !done {