aboutsummaryrefslogtreecommitdiff
path: root/cmd/batch/main.go
blob: 222d4d717d9fbcfbb3204fd04afbf5a32b8c5c55 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main

import (
	"log"

	"dim13.org/acme"
)

func main() {
	log.Println("Scan files")
	crt, err := scanFiles(*baseDir)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Dial", *provider)
	prov, err := acme.DialProvider(*provider)
	if err != nil {
		log.Fatal(err)
	}

	for _, c := range crt {
		if c.IsValid(*graceTime) && !*force {
			log.Println("Skip", c)
			continue
		}
		csr, err := acme.NewCSR(c.PrivateKey, c.Leaf.DNSNames, c.Leaf.EmailAddresses)
		if err != nil {
			log.Println(err)
			continue
		}
		_ = csr
	}
	if len(*emails) > 0 && len(*domains) > 0 {
		key, err := acme.NewKey(*keySize)
		if err != nil {
			log.Fatal(err)
		}
		sig, err := acme.NewSigner(key)
		if err != nil {
			log.Fatal(err)
		}
		var con acme.Contacts
		for _, email := range *emails {
			m, err := acme.NewMail(email)
			if err != nil {
				log.Fatal(err)
			}
			con = append(con, m)
		}
		log.Println("Register", con)
		err = prov.Register(sig, con, agree)
		if err != nil {
			log.Fatal(err)
		}
		log.Println(*emails)
		log.Println(*domains)
	}
}

func agree(tos string) bool {
	log.Println("Agree to", tos)
	return true
}