keyshare.go 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
package irmago

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

type keyshareServer struct {
Sietse Ringers's avatar
Sietse Ringers committed
10
11
12
13
	URL        string              `json:"url"`
	Username   string              `json:"username"`
	Nonce      []byte              `json:"nonce"`
	PrivateKey *paillierPrivateKey `json:"keyPair"`
14
15
}

Sietse Ringers's avatar
Sietse Ringers committed
16
17
18
type keyshareRegistration struct {
	Username  string             `json:"username"`
	Pin       string             `json:"pin"`
Sietse Ringers's avatar
Sietse Ringers committed
19
20
21
22
	PublicKey *paillierPublicKey `json:"publicKey"`
}

type KeyshareHandler interface {
Sietse Ringers's avatar
Sietse Ringers committed
23
	StartKeyshareRegistration(manager *SchemeManager, registrationCallback func(email, pin string))
24
25
}

Sietse Ringers's avatar
Sietse Ringers committed
26
func newKeyshareServer(privatekey *paillierPrivateKey, url, email string) (ks *keyshareServer, err error) {
Sietse Ringers's avatar
Sietse Ringers committed
27
28
29
30
31
32
	ks = &keyshareServer{
		Nonce:      make([]byte, 32),
		URL:        url,
		Username:   email,
		PrivateKey: privatekey,
	}
33
34
35
36
37
38
39
40
	_, 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[:])
}