aboutsummaryrefslogtreecommitdiff
path: root/challange_http.go
diff options
context:
space:
mode:
Diffstat (limited to 'challange_http.go')
-rw-r--r--challange_http.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/challange_http.go b/challange_http.go
index 2d10da4..30233bb 100644
--- a/challange_http.go
+++ b/challange_http.go
@@ -1,7 +1,43 @@
package acme
+import (
+ "io"
+ "net"
+ "net/http"
+)
+
const wellKnown = `/.well-known/acme-challenge/`
func init() {
registerChallenge(ChallengeHTTP)
}
+
+type httpChallenge struct {
+ Challenge
+ Addr string
+}
+
+func (c *httpChallenge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ io.WriteString(w, c.KeyAuthorization)
+}
+
+func (c *httpChallenge) Solve() error {
+ done := make(chan bool)
+ l, err := net.Listen("tcp", c.Addr)
+ if err != nil {
+ return err
+ }
+ defer l.Close()
+ s := &http.Server{
+ Handler: c,
+ ConnState: func(_ net.Conn, st http.ConnState) {
+ if st == http.StateClosed {
+ done <- true
+ }
+ },
+ }
+ s.SetKeepAlivesEnabled(false)
+ go s.Serve(l)
+ <-done
+ return nil
+}