aboutsummaryrefslogtreecommitdiff
path: root/solve_webroot.go
blob: 096ca4afb28be49d64cea26895b57951eb51f3eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package acme

import (
	"io"
	"log"
	"os"
	"path"
)

type webrootSolver struct {
	webroot string
	file    string
}

func NewWebrootSolver(webroot string) Solver {
	return &webrootSolver{webroot: webroot}
}

func (s *webrootSolver) Solve(ch Challenge) error {
	s.file = path.Join(s.webroot, WellKnown, ch.Token)
	log.Println("solve webroot", s.file)
	err := os.MkdirAll(path.Dir(s.file), 0755)
	if err != nil {
		return err
	}
	fd, err := CreateFile(s.file, 0644)
	if err != nil {
		return err
	}
	defer fd.Close()
	_, err = io.WriteString(fd, ch.KeyAuthorization)
	return err
}

func (s *webrootSolver) Solved() error {
	return os.Remove(s.file)
}

func (webrootSolver) Type() ChalType { return ChallengeHTTP }