aboutsummaryrefslogtreecommitdiff
path: root/cmd/acme/main.go
blob: 687fd6f816423ebb0ac1c89be422cf502d8dfe68 (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
package main

import (
	"encoding/json"
	"flag"
	"io/ioutil"
	"log"

	"dim13.org/acme"
)

func must(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

const (
	eMail   = `another@example.com`
	keySize = 2048
)

var (
	server = flag.String("server", acme.LEStaging, "directory server")
	port   = flag.Int("port", 8443, "port to listen")
)

func init() {
	flag.Parse()
}

func main() {
	acc, err := acme.NewAccount(eMail, keySize)
	must(err)
	acme.Print(acc)
	//acme.Dump(acc)
	err = acme.Save(".acme/account.json", acc)
	must(err)
	acme.SaveKey(".acme/priv.pem", acc.PrivKey)

	dir := acme.Directory{}
	err = acme.Get(acc, *server, &dir)
	must(err)
	acme.Print(dir)

	resp, err := acme.Post(acc, dir.NewReg, acme.NewRegistration(acc.Contact, acme.NewReg{}))
	must(err)
	log.Println(resp)

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	must(err)
	log.Println(string(body))

	rr := acme.RegistrationResp{}
	err = json.Unmarshal(body, &rr)
	must(err)
	log.Printf("%+v\n", rr)
}