-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
53 lines (46 loc) · 1.22 KB
/
store.go
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
package store
import (
"crypto"
"crypto/x509"
"encoding/json"
"encoding/pem"
"github.com/go-acme/lego/v4/registration"
"golang.org/x/net/context"
"time"
)
type Store interface {
GetUser(ctx context.Context, email string) (user *User, has bool, err error)
SaveUser(ctx context.Context, user *User) (err error)
GetUserCertificate(ctx context.Context, email string, domain string) (cert *Certificate, has bool, err error)
SaveUserCertificate(ctx context.Context, email string, domain string, cert *Certificate) (err error)
}
type User struct {
Email string `json:"email"`
Resource []byte `json:"resource"`
Key []byte `json:"key"`
}
func (u *User) GetEmail() string {
return u.Email
}
func (u *User) GetRegistration() *registration.Resource {
r := ®istration.Resource{}
rErr := json.Unmarshal(u.Resource, r)
if rErr != nil {
return nil
}
return r
}
func (u *User) GetPrivateKey() crypto.PrivateKey {
block, _ := pem.Decode(u.Key)
key, parseKeyErr := x509.ParsePKCS1PrivateKey(block.Bytes)
if parseKeyErr != nil {
return nil
}
return key
}
type Certificate struct {
Resource []byte `json:"resource"`
Cert []byte `json:"cert"`
Key []byte `json:"key"`
NotAfter time.Time `json:"notAfter"`
}