Browse Source

id blindsign and verificated working

master
arnaucode 7 years ago
parent
commit
082864de1c
10 changed files with 132 additions and 68 deletions
  1. +6
    -5
      clientApp/GUI/views/main/main.html
  2. +4
    -4
      clientApp/GUI/views/main/main.js
  3. +40
    -11
      clientApp/clientApp.go
  4. +2
    -2
      clientApp/clientAppRESTFunctions.go
  5. +77
    -8
      clientApp/keys.go
  6. BIN
      documentation/screenshot02.png
  7. +1
    -0
      serverIDsigner/.gitignore
  8. +0
    -27
      serverIDsigner/keys/server_private.pem
  9. +0
    -8
      serverIDsigner/keys/server_public.pem
  10. +2
    -3
      serverIDsigner/userRESTFunctions.go

+ 6
- 5
clientApp/GUI/views/main/main.html

@ -25,7 +25,7 @@
<h4 class="card-title">
My IDs
</h4>
<div class="row" style="height:200px;" ng-repeat="id in ids">
<div class="row" style="height:160px;" ng-repeat="id in ids">
<div class="col-sm-6">
Public Key: {{id.pubK}}
<!--<br> Private Key: {{id.privK}}-->
@ -40,11 +40,12 @@
<span class="badge c_o_green300" ng-show="id.verified">Verified</span>
</div>
<div class="pull-right">
<span class="badge c_o_orange300" ng-show="!id.pubKSigned">Not signed</span>
<span class="badge c_o_green300" ng-show="id.pubKSigned">Signed</span>
<span class="badge c_o_orange300" ng-show="!id.unblindedsig">Not signed</span>
<span class="badge c_o_blue300" ng-show="id.unblindedsig">Signed</span>
</div>
<div ng-click="blindAndSendToSign(id.pubK)" ng-show="!id.pubKSigned" class="btn btn-sm btn-raised c_o_cyan300 pull-right">Send to serverIDsigner</div>
<div ng-click="verify(id.pubK)" ng-show="!id.verified"class="btn btn-sm btn-raised c_o_deepPurple300 pull-right">Verify</div>
<br><br>
<div ng-click="blindAndSendToSign(id.id)" ng-show="!id.unblindedsig" class="btn btn-sm btn-raised c_o_cyan300 pull-right">Send to serverIDsigner</div>
<!--<div ng-click="verify(id.id)" ng-show="!id.verified"class="btn btn-sm btn-raised c_o_deepPurple300 pull-right">Verify</div>-->
</div>
</div>
</div>

+ 4
- 4
clientApp/GUI/views/main/main.js

@ -39,8 +39,8 @@ angular.module('app.main', ['ngRoute'])
});
};
$scope.blindAndSendToSign = function(pubK) {
$http.get(clientapi + 'blindandsendtosign/' + pubK)
$scope.blindAndSendToSign = function(id) {
$http.get(clientapi + 'blindandsendtosign/' + id)
.then(function(data) {
console.log('data success');
console.log(data);
@ -50,8 +50,8 @@ angular.module('app.main', ['ngRoute'])
console.log('data error');
});
};
$scope.verify = function(pubK) {
$http.get(clientapi + 'verify/' + pubK)
$scope.verify = function(id) {
$http.get(clientapi + 'verify/' + id)
.then(function(data) {
console.log('data success');
console.log(data);

+ 40
- 11
clientApp/clientApp.go

@ -12,6 +12,7 @@ import (
"github.com/cryptoballot/fdh"
"github.com/cryptoballot/rsablind"
"github.com/fatih/color"
)
func IDs() []Key {
@ -51,18 +52,33 @@ type SignResponse struct {
PubK rsa.PublicKey `json:"pubK"`
}
func BlindAndSendToSign(keyID string) []byte {
func BlindAndSendToSign(keyID string) []Key {
//get the key
key := getKeyByKeyID(keyID)
//privK := openPEMKey(key.PrivK)
pubK := openPublicPEMKey(key.PubK)
pubK, err := openPublicPEMKey(keysDir + "/" + key.PubK)
check(err)
//pubK to string
m, err := ExportRsaPublicKeyAsPemStr(pubK)
check(err)
mB := []byte(m)
//get serverPubK
var serverPubK *rsa.PublicKey
res, err := http.Get(config.Server)
check(err)
decoder := json.NewDecoder(res.Body)
err = decoder.Decode(&serverPubK)
if err != nil {
panic(err)
}
defer res.Body.Close()
//TODO pubK to string
m := []byte("pubK") //convert pubK to array of bytes
//blind the hashed message
// We do a SHA256 full-domain-hash expanded to 1536 bits (3/4 the key size)
hashed := fdh.Sum(crypto.SHA256, hashize, m)
blinded, unblinder, err := rsablind.Blind(&pubK, hashed)
hashed := fdh.Sum(crypto.SHA256, hashize, mB)
blinded, unblinder, err := rsablind.Blind(serverPubK, hashed)
if err != nil {
panic(err)
}
@ -71,10 +87,10 @@ func BlindAndSendToSign(keyID string) []byte {
//send blinded to serverIDsigner
body := new(bytes.Buffer)
json.NewEncoder(body).Encode(askBlindSign)
res, err := http.Post(config.Server+"blindsign", "application/json", body)
res, err = http.Post(config.Server+"blindsign", "application/json", body)
check(err)
var signResponse SignResponse
decoder := json.NewDecoder(res.Body)
decoder = json.NewDecoder(res.Body)
err = decoder.Decode(&signResponse)
if err != nil {
panic(err)
@ -82,13 +98,26 @@ func BlindAndSendToSign(keyID string) []byte {
defer res.Body.Close()
sig := signResponse.Sig
serverPubK := signResponse.PubK
//serverPubK := signResponse.PubK
//unblind the signedblind
unblindedSig := rsablind.Unblind(&serverPubK, sig, unblinder)
unblindedSig := rsablind.Unblind(serverPubK, sig, unblinder)
color.Green("unblindedSig")
fmt.Println(unblindedSig)
return unblindedSig
// Verify the original hashed message against the unblinded signature
if err := rsablind.VerifyBlindSignature(serverPubK, hashed, unblindedSig); err != nil {
fmt.Println(err)
} else {
color.Green("blind signature verified")
key.Verified = true
}
key.UnblindedSig = unblindedSig
key.Hashed = hashed
key.ServerVerifier = serverPubK
saveKey(key)
keys := readKeys()
return keys
}
func Verify(packPubK string) {

+ 2
- 2
clientApp/clientAppRESTFunctions.go

@ -40,9 +40,9 @@ func GetBlindAndSendToSign(w http.ResponseWriter, r *http.Request) {
idKey := vars["idKey"]
color.Green(idKey)
unblindedSig := BlindAndSendToSign(idKey)
keys := BlindAndSendToSign(idKey)
jResp, err := json.Marshal(unblindedSig)
jResp, err := json.Marshal(keys)
check(err)
fmt.Fprintln(w, string(jResp))
}

+ 77
- 8
clientApp/keys.go

@ -6,18 +6,67 @@ import (
"encoding/asn1"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/fatih/color"
)
type Key struct {
ID string `json:"id"`
PrivK string `json:"privK"` //path of the PrivK file
PubK string `json:"pubK"` //path of the PubK file
Date time.Time `json:"date"`
Verified bool `json:"verified"`
Signed string `json:"signed"`
ID string `json:"id"`
PrivK string `json:"privK"` //path of the PrivK file
PubK string `json:"pubK"` //path of the PubK file
Date time.Time `json:"date"`
Hashed []byte `json:"hashed"`
UnblindedSig []byte `json:"unblindedsig"`
Verified bool `json:"verified"`
ServerVerifier *rsa.PublicKey `json:"serververifier"`
}
func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string {
privkey_bytes := x509.MarshalPKCS1PrivateKey(privkey)
privkey_pem := pem.EncodeToMemory(
&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: privkey_bytes,
},
)
return string(privkey_pem)
}
func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error) {
block, _ := pem.Decode([]byte(privPEM))
if block == nil {
return nil, errors.New("failed to parse PEM block containing the key")
}
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return nil, err
}
return priv, nil
}
func ExportRsaPublicKeyAsPemStr(pubkey rsa.PublicKey) (string, error) {
asn1Bytes, err := asn1.Marshal(pubkey)
check(err)
pubkey_pem := pem.EncodeToMemory(
&pem.Block{
Type: "PUBLIC KEY",
Bytes: asn1Bytes,
},
)
color.Red("pubkey_pem")
fmt.Println(pubkey_pem)
return string(pubkey_pem), nil
}
func ParseRsaPublicKeyFromPemStr(pubPEM string) (pub rsa.PublicKey, err error) {
pemBlock, _ := pem.Decode([]byte(pubPEM))
_, err = asn1.Unmarshal(pemBlock.Bytes, &pub)
return
}
func savePEMKey(fileName string, key *rsa.PrivateKey) {
@ -49,10 +98,20 @@ func savePublicPEMKey(fileName string, pubkey rsa.PublicKey) {
err = pem.Encode(pemfile, pemkey)
check(err)
}
func openPEMKey(path string) (key rsa.PrivateKey) {
func openPEMKey(path string) (key *rsa.PrivateKey, err error) {
b, err := ioutil.ReadFile(path)
if err != nil {
fmt.Print(err)
}
key, err = ParseRsaPrivateKeyFromPemStr(string(b))
return
}
func openPublicPEMKey(path string) (key rsa.PublicKey) {
func openPublicPEMKey(path string) (key rsa.PublicKey, err error) {
b, err := ioutil.ReadFile(path)
if err != nil {
fmt.Print(err)
}
key, err = ParseRsaPublicKeyFromPemStr(string(b))
return
}
func readKeys() []Key {
@ -73,6 +132,16 @@ func saveKeys(keys []Key) {
err = ioutil.WriteFile(keysDir+"/keys.json", jsonKeys, 0644)
check(err)
}
func saveKey(k Key) {
fmt.Println(k)
keys := readKeys()
for i, key := range keys {
if key.ID == k.ID {
keys[i] = k
}
}
saveKeys(keys)
}
func getKeyByKeyID(keyID string) (k Key) {
keys := readKeys()
for _, key := range keys {

BIN
documentation/screenshot02.png

Before After
Width: 852  |  Height: 628  |  Size: 49 KiB Width: 853  |  Height: 626  |  Size: 61 KiB

+ 1
- 0
serverIDsigner/.gitignore

@ -0,0 +1 @@
keys

+ 0
- 27
serverIDsigner/keys/server_private.pem

@ -1,27 +0,0 @@
-----BEGIN PRIVATE KEY-----
MIIEpQIBAAKCAQEA061q3ahXEG9rHf/uekmIk4fSvtG8p7OwkjP3PlafFjxeA4BS
8dkjPUEboXMftQCFrzWc5nLyQR4Ig5xMzjaEbQv/JBdpP/E1nl+fC6ca45Rov0OE
7OQrDyEPb1qNJ3uQmh+N9ZvTLNndT3bBxtBfmIRyMq+78mMumzNvFbx6zfNpwv9T
HDgBnfZoAZ7gpIZeKn/yFasQmzFwpy9hfqZ21SCL7GmiU+nAz2TxtyFkUttMeIxD
gSSKLYxzt6mKdElNv0K97tBU1eRaXz4hpq/I0dtmcidrS/45MtXij6wO1agIvnH+
pygSI5QF3rE+lVYaDuKJZ6QBvnNEF9/cu7j/ZQIDAQABAoIBAQDAP+apPnUkpi0B
aCqtwg9a/qb3TAItxdN+VdgeNAn05gr03x12LiIFRhbUQXzwpXLFOMoxuwAvCBnv
fot7VqRbbePiYajjvC1Yk7wdlz2iqG2iGK6ngGtjKEGefv1oeJ9Se4oxIb9gItcP
jupbqXDJUrFtO5JViKMRrlsbwL1AQkWafiBJyfaeO9f6fikrv9dWJCE/wDN6F4XB
cVZj30GzBVpLfq6cuP1I7o1txNdRivPza4S6zufy53CfkFqsyjehFfvmlMCK+6/p
6EDd1pag3tfr/+1k1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PlafFjxeA4BS8dkj
PUEboXMftQCFrzWc5nLyQR4Ig5xMzjaEbQv/JBdpP/E1nl+fC6ca45Rov0OE7OQr
DyEPb1qNJ3uQmh+N9ZvTLNndT3bBxtBfmIRyMq+78mMumzNvFbx6zfNpwv9THDgB
nfZoAZ7gpIZeKn/yFasQmzFwpy9hfqZ21SCL7GmiU+nAz2TxtyFkUttMeIxDgSSK
LYxzt6mKdElNv0K97tBU1eRaXz4hpq/I0dtmcidrS/45MtXij6wO1agIvnH+pygS
I5QF3rE+lVYaDuKJZ6QBvnNEF9/cu7j/ZQIDAQAB
-----END PUBLIC KEY-----

+ 2
- 3
serverIDsigner/userRESTFunctions.go

@ -20,9 +20,8 @@ type User struct {
}
func Index(w http.ResponseWriter, r *http.Request) {
//TODO return the public key, to allow others verifign signed strings by this server
jResp, err := json.Marshal("a")
// return server public key, to allow others verifign signed strings by this server
jResp, err := json.Marshal(serverKey.PublicKey)
if err != nil {
panic(err)
}

Loading…
Cancel
Save