aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-22 18:43:30 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-22 18:43:30 +0100
commit84497cce8f0f89a74c09ba9ecd71e30af8f571f0 (patch)
treed58690ca8a6fca3e0cba2fe941842180dba6e917 /crypto.go
parent160a6c8f3ba267c94f4f75de1e33fe544f15769c (diff)
Add thumb
Diffstat (limited to 'crypto.go')
-rw-r--r--crypto.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/crypto.go b/crypto.go
index b2173e1..bce5b2a 100644
--- a/crypto.go
+++ b/crypto.go
@@ -1,13 +1,17 @@
package acme
import (
+ "crypto"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
+ "encoding/base64"
"encoding/pem"
"io"
"io/ioutil"
+
+ "github.com/square/go-jose"
)
func LoadKey(r io.Reader) (*rsa.PrivateKey, error) {
@@ -42,3 +46,12 @@ func NewCSR(altnames []string, key *rsa.PrivateKey) ([]byte, error) {
}
return x509.CreateCertificateRequest(rand.Reader, &tmpl, key)
}
+
+func Thumb(token string, key *rsa.PrivateKey) (string, error) {
+ k := &jose.JsonWebKey{Key: key, Algorithm: "RSA"}
+ t, err := k.Thumbprint(crypto.SHA256)
+ if err != nil {
+ return "", err
+ }
+ return token + "." + base64.RawStdEncoding.EncodeToString(t), nil
+}