implementing client blind ID, serverIDsigner blindsign

This commit is contained in:
arnaucode
2017-12-28 01:09:44 +01:00
parent 91dc63ed96
commit 4898cae5c0
18 changed files with 210 additions and 43 deletions

View File

@@ -1,9 +1,14 @@
body {
/*background: #15191e!important;*/
background: #000000!important;
color: #ffffff!important;
}
.card {
/*background: #1f262d!important;*/
/*background: #15191e!important;
color: #ffffff!important;*/
/*border: 1px solid #ffffff!important;*/
background: #000000!important;
color: #ffffff!important;
border: 1px solid #ffffff!important;
}

View File

@@ -1 +1,5 @@
.o_nav {
background: #000000!important;
color: #ffffff!important;
border-bottom: 2px solid #4DD0E1!important;
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 KiB

View File

@@ -5,16 +5,16 @@
</div>
<div class="col-sm-4">
<div class="card">
<img src="img/blockchainIDsystem-logo01.png" class="img-responsive" />
<div class="card-body">
<h4 class="card-title">
blockchainIDsystem
</h4>
<input ng-model="user.email" class="form-control" placeholder="Email" type="text">
<input ng-model="user.password" class="form-control" placeholder="Password" type="password">
<div ng-click="login()" class="btn btn-raised c_indigo300 pull-right">Login</div>
<div ng-click="login()" class="btn btn-raised btn-block c_o_cyan300 pull-right">Login</div>
</div>
</div>
</div>

View File

@@ -1,29 +1,37 @@
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="col-sm-2">
</div>
<div class="col-sm-4">
<div class="col-sm-8">
<div class="card">
<div class="card-body">
<h4 class="card-title">
blockchainIDsystem
</h4>
<div ng-click="newID()" class="btn btn-raised c_o_cyan300">Create new ID</div>
<p>
Generate new ID
<div ng-click="newID()" class="btn btn-raised pull-right c_o_cyan300">Create new ID</div>
</p>
</div>
<hr>
<div class="card-body">
<h4 class="card-title">
Current IDs
</h4>
<p ng-repeat="id in ids">
{{id}} <div ng-click="" class="btn btn-raised c_o_indigo300">Verify</div>
</p>
<div class="row" ng-repeat="id in ids">
<div class="col-sm-6">
Public Key: {{id.pubK}}
<br> Private Key: {{id.privK}}
<br> Date of creation: {{id.date}}
</div>
<div class="col-sm-6">
<div ng-click="blindAndVerify(id.pubK)" class="btn btn-raised c_o_indigo300">Blind & Send to serverIDsigner</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-2">
</div>

View File

@@ -32,4 +32,16 @@ angular.module('app.main', ['ngRoute'])
console.log('data error');
});
};
$scope.blindAndVerify = function(pubK) {
$http.get(clientapi + 'blindandverify/' + pubK)
.then(function(data) {
console.log('data success');
console.log(data);
$scope.ids = data.data;
}, function(data) {
console.log('data error');
});
};
});

View File

@@ -1,5 +1,5 @@
<div ng-controller="NavbarCtrl" ng-show="user">
<nav class="navbar navbar-fixed-top c_cyanG500to300">
<nav class="navbar navbar-fixed-top o_nav">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">

View File

@@ -1,11 +1,15 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
ownrsa "./ownrsa"
"github.com/fatih/color"
"github.com/gorilla/mux"
)
//generate key pair
@@ -30,6 +34,7 @@ func NewID(w http.ResponseWriter, r *http.Request) {
newKey := ownrsa.GenerateKeyPair()
key := ownrsa.PackKey(newKey)
key.Date = time.Now()
fmt.Println(key)
keys := readKeys("keys.json")
@@ -40,3 +45,71 @@ func NewID(w http.ResponseWriter, r *http.Request) {
check(err)
fmt.Fprintln(w, string(jResp))
}
type AskBlindSign struct {
M string `json:"m"`
}
func BlindAndVerify(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
packPubK := vars["pubK"]
color.Green(packPubK)
//read the keys stored in /keys directory
keys := readKeys("keys.json")
var key ownrsa.RSA
//search for complete key
for _, k := range keys {
fmt.Println(k.PubK)
fmt.Println(packPubK)
fmt.Println("")
if k.PubK == packPubK {
key = ownrsa.UnpackKey(k)
}
}
//blind the key.PubK
var m []int
//convert packPubK to []bytes
mBytes := []byte(packPubK)
for _, byte := range mBytes {
m = append(m, int(byte))
}
rVal := 101
blinded := ownrsa.Blind(m, rVal, key.PubK, key.PrivK)
fmt.Println(blinded)
//convert blinded to string
var askBlindSign AskBlindSign
askBlindSign.M = ownrsa.ArrayIntToString(blinded, "_")
//send to the serverIDsigner the key.PubK blinded
color.Green(askBlindSign.M)
body := new(bytes.Buffer)
json.NewEncoder(body).Encode(askBlindSign)
res, err := http.Post("http://"+config.ServerIDSigner.IP+":"+config.ServerIDSigner.Port+"/blindsign", "application/json", body)
check(err)
fmt.Println(res)
decoder := json.NewDecoder(res.Body)
//var sigmaString string
err = decoder.Decode(&askBlindSign)
if err != nil {
panic(err)
}
defer r.Body.Close()
fmt.Println("sigmaString")
fmt.Println(askBlindSign)
sigma := ownrsa.StringToArrayInt(askBlindSign.M, "_")
fmt.Println(sigma)
//unblind the response
//TODO
//després de la blindsign response, demanar al serverIDsigner la pubK
//unblinded := ownrsa.Unblind(sigma, rVal, )
jResp, err := json.Marshal(keys)
check(err)
fmt.Fprintln(w, string(jResp))
}

View File

@@ -1,4 +1,8 @@
{
"port": "4100",
"keysDirectory": "keys"
"keysDirectory": "keys",
"serverIDsigner": {
"ip": "127.0.0.1",
"port": "3130"
}
}

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"net/http"
@@ -12,6 +13,7 @@ func main() {
color.Blue("Starting blockchainIDsystem clientApp")
readConfig("config.json")
fmt.Println(config)
//run thw webserver
go GUI()

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"math/rand"
"strconv"
"strings"
"time"
)
@@ -27,6 +28,13 @@ type RSA struct {
PrivK RSAPrivateKey
}
type PackRSA struct {
PubK string `json:"pubK"`
PrivK string `json:"privK"`
Date time.Time `json:"date"`
PubKSigned string `json:"pubKSigned"`
}
const maxPrime = 500
const minPrime = 100
@@ -113,11 +121,11 @@ func Blind(m []int, r int, pubK RSAPublicKey, privK RSAPrivateKey) []int {
return mBlinded
}
func BlindSign(m []int, pubK RSAPublicKey, privK RSAPrivateKey) []int {
func BlindSign(m []int, privK RSAPrivateKey) []int {
var r []int
for i := 0; i < len(m); i++ {
mBigInt := big.NewInt(int64(m[i]))
sigma := new(big.Int).Exp(mBigInt, privK.D, pubK.N)
sigma := new(big.Int).Exp(mBigInt, privK.D, privK.N)
r = append(r, int(sigma.Int64()))
}
return r
@@ -183,11 +191,6 @@ func PubKStringToBigInt(kS RSAPublicKeyString) (RSAPublicKey, error) {
return k, nil
}
type PackRSA struct {
PubK string `json:"pubK"`
PrivK string `json:"privK"`
}
func PackKey(k RSA) PackRSA {
var p PackRSA
p.PubK = k.PubK.E.String() + "," + k.PubK.N.String()
@@ -207,3 +210,19 @@ func UnpackKey(p PackRSA) RSA {
}
return k
}
func ArrayIntToString(a []int, delim string) string {
return strings.Trim(strings.Replace(fmt.Sprint(a), " ", delim, -1), "[]")
}
func StringToArrayInt(s string, delim string) []int {
var a []int
arrayString := strings.Split(s, delim)
for _, s := range arrayString {
i, err := strconv.Atoi(s)
if err != nil {
fmt.Println(err)
}
a = append(a, i)
}
return a
}

View File

@@ -7,8 +7,13 @@ import (
//Config reads the config
type Config struct {
Port string `json:"port"`
KeysDirectory string `json:"keysDirectory"`
Port string `json:"port"`
KeysDirectory string `json:"keysDirectory"`
ServerIDSigner Server `json:"serverIDsigner"`
}
type Server struct {
IP string `json:"ip"`
Port string `json:"port"`
}
var config Config

View File

@@ -21,4 +21,10 @@ var routes = Routes{
"/newid",
NewID,
},
Route{
"BlindAndVerify",
"GET",
"/blindandverify/{pubK}",
BlindAndVerify,
},
}