aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-27 14:09:12 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-27 14:09:12 +0100
commit6c0b2240d3d53621e0b145b1bd1b79a3826e3485 (patch)
tree218a279fe3c24c20a34d491b8746319b276edcce
parent23282f058e68aac8bf29216faf90d7f27f6ad8c8 (diff)
Add account
-rw-r--r--account.go27
-rw-r--r--cmd/acme/main.go15
-rw-r--r--registration.go7
3 files changed, 46 insertions, 3 deletions
diff --git a/account.go b/account.go
new file mode 100644
index 0000000..5264636
--- /dev/null
+++ b/account.go
@@ -0,0 +1,27 @@
+package acme
+
+import (
+ "crypto/rand"
+ "crypto/rsa"
+ "net/mail"
+)
+
+type Account struct {
+ Contact []string
+ PrivKey *rsa.PrivateKey
+}
+
+func NewAccount(email string, bits int) (Account, error) {
+ m, err := mail.ParseAddress(email)
+ if err != nil {
+ return Account{}, err
+ }
+ key, err := rsa.GenerateKey(rand.Reader, bits)
+ if err != nil {
+ return Account{}, err
+ }
+ return Account{
+ Contact: []string{"mailto:" + m.Address},
+ PrivKey: key,
+ }, nil
+}
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index c5ed22b..c85d1b3 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -6,12 +6,21 @@ import (
"dim13.org/acme"
)
-func main() {
- dir, err := acme.NewDirectory(acme.LEV1)
+func must(err error) {
if err != nil {
log.Fatal(err)
}
+}
+
+func main() {
+ dir, err := acme.NewDirectory(acme.LEV1)
+ must(err)
log.Println(dir)
- acme.Post(dir.NewReg, acme.Registration{})
+ acc, err := acme.NewAccount("Dimitri Sokolyuk <demon@dim13.org>", 2048)
+ must(err)
+ log.Println(acc)
+
+ me := []string{"mailto:demon@dim13.org"}
+ acme.Post(dir.NewReg, acme.NewRegistration(me))
}
diff --git a/registration.go b/registration.go
index 06d1ca8..d0e75d8 100644
--- a/registration.go
+++ b/registration.go
@@ -4,3 +4,10 @@ type Registration struct {
Resource string `json:"resource"`
Contact []string `json:"contact"`
}
+
+func NewRegistration(contact []string) Registration {
+ return Registration{
+ Resource: "new-reg",
+ Contact: contact,
+ }
+}