aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
Diffstat (limited to 'account.go')
-rw-r--r--account.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/account.go b/account.go
index 62d3213..7766893 100644
--- a/account.go
+++ b/account.go
@@ -3,12 +3,16 @@ package acme
import (
"crypto/rand"
"crypto/rsa"
+ "fmt"
"net/mail"
+
+ "github.com/square/go-jose"
)
type Account struct {
Contact []string `json:"contact"`
PrivKey *rsa.PrivateKey `json:"key"`
+ Signer jose.Signer `json:"-"`
}
func NewAccount(email string, bits int) (Account, error) {
@@ -25,3 +29,25 @@ func NewAccount(email string, bits int) (Account, error) {
PrivKey: key,
}, nil
}
+
+func (a *Account) Sign(msg []byte) ([]byte, error) {
+ if a.Signer == nil {
+ signer, err := jose.NewSigner(jose.RS256, a.PrivKey)
+ if err != nil {
+ return nil, err
+ }
+ signer.SetNonceSource(nonces)
+ a.Signer = signer
+ }
+ obj, err := a.Signer.Sign(msg)
+ return []byte(obj.FullSerialize()), err
+}
+
+func (a *Account) ParseSigned(msg []byte) ([]byte, error) {
+ fmt.Println("MSG", string(msg))
+ obj, err := jose.ParseSigned(string(msg))
+ if err != nil {
+ return nil, err
+ }
+ return obj.Verify(&a.PrivKey.PublicKey)
+}