keyshare.go 1.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package irmago

import (
	"crypto/rand"
	"crypto/sha256"
	"encoding/base64"

	"github.com/mcornejo/go-go-gadget-paillier"
)

type keyshareServer struct {
	URL          string              `json:"url"`
	Username     string              `json:"username"`
	Nonce        []byte              `json:"nonce"`
	PrivateKey   *paillierPrivateKey `json:"keyPair"`
	keyGenerator paillierKeygen
}

Sietse Ringers's avatar
Sietse Ringers committed
19
20
21
22
type keyshareRegistration struct {
	Username  string             `json:"username"`
	Pin       string             `json:"pin"`
	PublicKey paillier.PublicKey `json:"publicKey"`
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
}

func newKeyshareServer(keygen paillierKeygen) (ks *keyshareServer, err error) {
	ks.Nonce = make([]byte, 0, 32)
	ks.keyGenerator = keygen
	_, err = rand.Read(ks.Nonce)
	return
}

func (ks *keyshareServer) HashedPin(pin string) string {
	hash := sha256.Sum256(append(ks.Nonce, []byte(pin)...))
	return base64.RawStdEncoding.EncodeToString(hash[:])
}

func (ks *keyshareServer) GetKey() *paillierPrivateKey {
	if ks.PrivateKey == nil {
		ks.PrivateKey = ks.keyGenerator.paillierKey()
	}
	return ks.PrivateKey
}

Sietse Ringers's avatar
Sietse Ringers committed
44
45
func KeyshareEnroll(manager *SchemeManager, email, pin string) error {
	//NewHTTPTransport(qr.URL)
46
}