arnaucube
arnaucube/darkID-prototypePublic Self-hosted repository
darkID-prototype/clientApp/clientApp.go
clientApp/clientApp.goRaw
 1package main
 2
 3import (
 4	"bytes"
 5	"crypto"
 6	"crypto/rand"
 7	"crypto/rsa"
 8	"encoding/json"
 9	"fmt"
10	"net/http"
11	"time"
12
13	"github.com/cryptoballot/fdh"
14	"github.com/cryptoballot/rsablind"
15)
16
17func IDs() []Key {
18	//read the keys stored in /keys directory
19	keys := readKeys()
20	return keys
21}
22func NewID() []Key {
23	//generate RSA keys pair
24	reader := rand.Reader
25	k, err := rsa.GenerateKey(reader, keysize)
26	check(err)
27
28	id := hash(time.Now().String())
29	savePEMKey(keysDir+"/"+id+"private.pem", k)
30	savePublicPEMKey(keysDir+"/"+id+"public.pem", k.PublicKey)
31
32	var key Key
33	key.ID = id
34	key.PrivK = id + "private.pem"
35	key.PubK = id + "public.pem"
36
37	key.Date = time.Now()
38	fmt.Println(key)
39
40	keys := readKeys()
41	keys = append(keys, key)
42	saveKeys(keys)
43	return keys
44}
45
46type AskBlindSign struct {
47	M []byte `json:"m"`
48}
49type SignResponse struct {
50	Sig  []byte        `json:"sig"`
51	PubK rsa.PublicKey `json:"pubK"`
52}
53
54func BlindAndSendToSign(keyID string) []byte {
55	//get the key
56	key := getKeyByKeyID(keyID)
57	//privK := openPEMKey(key.PrivK)
58	pubK := openPublicPEMKey(key.PubK)
59
60	//TODO pubK to string
61	m := []byte("pubK") //convert pubK to array of bytes
62	//blind the hashed message
63	// We do a SHA256 full-domain-hash expanded to 1536 bits (3/4 the key size)
64	hashed := fdh.Sum(crypto.SHA256, hashize, m)
65	blinded, unblinder, err := rsablind.Blind(&pubK, hashed)
66	if err != nil {
67		panic(err)
68	}
69	var askBlindSign AskBlindSign
70	askBlindSign.M = blinded
71	//send blinded to serverIDsigner
72	body := new(bytes.Buffer)
73	json.NewEncoder(body).Encode(askBlindSign)
74	res, err := http.Post(config.Server+"blindsign", "application/json", body)
75	check(err)
76	var signResponse SignResponse
77	decoder := json.NewDecoder(res.Body)
78	err = decoder.Decode(&signResponse)
79	if err != nil {
80		panic(err)
81	}
82	defer res.Body.Close()
83
84	sig := signResponse.Sig
85	serverPubK := signResponse.PubK
86
87	//unblind the signedblind
88	unblindedSig := rsablind.Unblind(&serverPubK, sig, unblinder)
89	fmt.Println(unblindedSig)
90
91	return unblindedSig
92}
93
94func Verify(packPubK string) {
95
96	return
97}