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 { body {
/*background: #15191e!important;*/
background: #000000!important; background: #000000!important;
color: #ffffff!important; color: #ffffff!important;
} }
.card { .card {
/*background: #1f262d!important;*/
/*background: #15191e!important;
color: #ffffff!important;*/
/*border: 1px solid #ffffff!important;*/
background: #000000!important; background: #000000!important;
color: #ffffff!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>
<div class="col-sm-4"> <div class="col-sm-4">
<div class="card"> <div class="card">
<img src="img/blockchainIDsystem-logo01.png" class="img-responsive" />
<div class="card-body"> <div class="card-body">
<h4 class="card-title"> <h4 class="card-title">
blockchainIDsystem blockchainIDsystem
</h4> </h4>
<input ng-model="user.email" class="form-control" placeholder="Email" type="text"> <input ng-model="user.email" class="form-control" placeholder="Email" type="text">
<input ng-model="user.password" class="form-control" placeholder="Password" type="password"> <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> </div>
</div> </div>

View File

@@ -1,29 +1,37 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-sm-4"> <div class="col-sm-2">
</div> </div>
<div class="col-sm-4"> <div class="col-sm-8">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<h4 class="card-title"> <h4 class="card-title">
blockchainIDsystem blockchainIDsystem
</h4> </h4>
<p>
<div ng-click="newID()" class="btn btn-raised c_o_cyan300">Create new ID</div> Generate new ID
<div ng-click="newID()" class="btn btn-raised pull-right c_o_cyan300">Create new ID</div>
</p>
</div> </div>
<hr>
<div class="card-body"> <div class="card-body">
<h4 class="card-title"> <h4 class="card-title">
Current IDs Current IDs
</h4> </h4>
<p ng-repeat="id in ids"> <div class="row" ng-repeat="id in ids">
{{id}} <div ng-click="" class="btn btn-raised c_o_indigo300">Verify</div> <div class="col-sm-6">
</p> 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>
</div> </div>
<div class="col-sm-4"> <div class="col-sm-2">
</div> </div>

View File

@@ -32,4 +32,16 @@ angular.module('app.main', ['ngRoute'])
console.log('data error'); 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"> <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="container-fluid">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">

View File

@@ -1,11 +1,15 @@
package main package main
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"time"
ownrsa "./ownrsa" ownrsa "./ownrsa"
"github.com/fatih/color"
"github.com/gorilla/mux"
) )
//generate key pair //generate key pair
@@ -30,6 +34,7 @@ func NewID(w http.ResponseWriter, r *http.Request) {
newKey := ownrsa.GenerateKeyPair() newKey := ownrsa.GenerateKeyPair()
key := ownrsa.PackKey(newKey) key := ownrsa.PackKey(newKey)
key.Date = time.Now()
fmt.Println(key) fmt.Println(key)
keys := readKeys("keys.json") keys := readKeys("keys.json")
@@ -40,3 +45,71 @@ func NewID(w http.ResponseWriter, r *http.Request) {
check(err) check(err)
fmt.Fprintln(w, string(jResp)) 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", "port": "4100",
"keysDirectory": "keys" "keysDirectory": "keys",
"serverIDsigner": {
"ip": "127.0.0.1",
"port": "3130"
}
} }

View File

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

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"math/rand" "math/rand"
"strconv"
"strings" "strings"
"time" "time"
) )
@@ -27,6 +28,13 @@ type RSA struct {
PrivK RSAPrivateKey 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 maxPrime = 500
const minPrime = 100 const minPrime = 100
@@ -113,11 +121,11 @@ func Blind(m []int, r int, pubK RSAPublicKey, privK RSAPrivateKey) []int {
return mBlinded return mBlinded
} }
func BlindSign(m []int, pubK RSAPublicKey, privK RSAPrivateKey) []int { func BlindSign(m []int, privK RSAPrivateKey) []int {
var r []int var r []int
for i := 0; i < len(m); i++ { for i := 0; i < len(m); i++ {
mBigInt := big.NewInt(int64(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())) r = append(r, int(sigma.Int64()))
} }
return r return r
@@ -183,11 +191,6 @@ func PubKStringToBigInt(kS RSAPublicKeyString) (RSAPublicKey, error) {
return k, nil return k, nil
} }
type PackRSA struct {
PubK string `json:"pubK"`
PrivK string `json:"privK"`
}
func PackKey(k RSA) PackRSA { func PackKey(k RSA) PackRSA {
var p PackRSA var p PackRSA
p.PubK = k.PubK.E.String() + "," + k.PubK.N.String() p.PubK = k.PubK.E.String() + "," + k.PubK.N.String()
@@ -207,3 +210,19 @@ func UnpackKey(p PackRSA) RSA {
} }
return k 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 //Config reads the config
type Config struct { type Config struct {
Port string `json:"port"` Port string `json:"port"`
KeysDirectory string `json:"keysDirectory"` KeysDirectory string `json:"keysDirectory"`
ServerIDSigner Server `json:"serverIDsigner"`
}
type Server struct {
IP string `json:"ip"`
Port string `json:"port"`
} }
var config Config var config Config

View File

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

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"math/rand" "math/rand"
"strconv"
"strings" "strings"
"time" "time"
) )
@@ -27,6 +28,13 @@ type RSA struct {
PrivK RSAPrivateKey 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 maxPrime = 500
const minPrime = 100 const minPrime = 100
@@ -113,11 +121,11 @@ func Blind(m []int, r int, pubK RSAPublicKey, privK RSAPrivateKey) []int {
return mBlinded return mBlinded
} }
func BlindSign(m []int, pubK RSAPublicKey, privK RSAPrivateKey) []int { func BlindSign(m []int, privK RSAPrivateKey) []int {
var r []int var r []int
for i := 0; i < len(m); i++ { for i := 0; i < len(m); i++ {
mBigInt := big.NewInt(int64(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())) r = append(r, int(sigma.Int64()))
} }
return r return r
@@ -183,11 +191,6 @@ func PubKStringToBigInt(kS RSAPublicKeyString) (RSAPublicKey, error) {
return k, nil return k, nil
} }
type PackRSA struct {
PubK string `json:"pubK"`
PrivK string `json:"privK"`
}
func PackKey(k RSA) PackRSA { func PackKey(k RSA) PackRSA {
var p PackRSA var p PackRSA
p.PubK = k.PubK.E.String() + "," + k.PubK.N.String() p.PubK = k.PubK.E.String() + "," + k.PubK.N.String()
@@ -207,3 +210,19 @@ func UnpackKey(p PackRSA) RSA {
} }
return k 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

@@ -10,9 +10,9 @@ curl -X POST http://127.0.0.1:3130/login -d '{"email": "user1@e.com", "password"
echo "" echo ""
echo "send pubK and m to blind sign" echo "send pubK and m to blind sign"
echo "json to send to the serverIDsigner:" echo "json to send to the serverIDsigner:"
echo '{"pubKstring": {"e": "65537", "n": "139093"}, "m": "hola"}' echo '{"m": "hola"}'
echo "serverIDsigner response:" echo "serverIDsigner response:"
BLINDSIGNED=$(curl -X POST http://127.0.0.1:3130/blindsign -d '{"pubKstring": {"e": "65537", "n": "139093"}, "m": "hola"}') BLINDSIGNED=$(curl -X POST http://127.0.0.1:3130/blindsign -d '{"m": "hola"}')
echo "$BLINDSIGNED" echo "$BLINDSIGNED"
echo "" echo ""

View File

@@ -7,6 +7,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/fatih/color"
"gopkg.in/mgo.v2/bson" "gopkg.in/mgo.v2/bson"
ownrsa "./ownrsa" ownrsa "./ownrsa"
@@ -96,13 +97,12 @@ type Sign struct {
} }
type AskBlindSign struct { type AskBlindSign struct {
PubKString ownrsa.RSAPublicKeyString `json:"pubKstring"` /*PubKString ownrsa.RSAPublicKeyString `json:"pubKstring"`
PubK ownrsa.RSAPublicKey `json:"pubK"` PubK ownrsa.RSAPublicKey `json:"pubK"`*/
M string `json:"m"` M string `json:"m"`
} }
func BlindSign(w http.ResponseWriter, r *http.Request) { func BlindSign(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Body)
decoder := json.NewDecoder(r.Body) decoder := json.NewDecoder(r.Body)
var askBlindSign AskBlindSign var askBlindSign AskBlindSign
err := decoder.Decode(&askBlindSign) err := decoder.Decode(&askBlindSign)
@@ -110,26 +110,36 @@ func BlindSign(w http.ResponseWriter, r *http.Request) {
panic(err) panic(err)
} }
defer r.Body.Close() defer r.Body.Close()
color.Red(askBlindSign.M)
fmt.Println(askBlindSign) fmt.Println(askBlindSign)
/*fmt.Println(askBlindSign)
askBlindSign.PubK, err = ownrsa.PubKStringToBigInt(askBlindSign.PubKString) askBlindSign.PubK, err = ownrsa.PubKStringToBigInt(askBlindSign.PubKString)
if err != nil { if err != nil {
fmt.Fprintln(w, "error") fmt.Fprintln(w, "error")
return return
} }*/
//convert msg to []int //convert msg to []int
var m []int /*var m []int
mBytes := []byte(askBlindSign.M) mBytes := []byte(askBlindSign.M)
for _, byte := range mBytes { for _, byte := range mBytes {
m = append(m, int(byte)) m = append(m, int(byte))
} }*/
sigma := ownrsa.BlindSign(m, askBlindSign.PubK, serverRSA.PrivK) //here the privK will be the CA privK, not the m emmiter's one. The pubK is the user's one m := ownrsa.StringToArrayInt(askBlindSign.M, "_")
sigma := ownrsa.BlindSign(m, serverRSA.PrivK) //here the privK will be the CA privK, not the m emmiter's one. The pubK is the user's one
fmt.Print("Sigma': ") fmt.Print("Sigma': ")
fmt.Println(sigma) fmt.Println(sigma)
sigmaString := ownrsa.ArrayIntToString(sigma, "_")
askBlindSign.M = sigmaString
fmt.Fprintln(w, sigma) jResp, err := json.Marshal(askBlindSign)
if err != nil {
panic(err)
}
fmt.Fprintln(w, string(jResp))
} }
type PetitionVerifySign struct { type PetitionVerifySign struct {