mirror of
https://github.com/arnaucube/blockchainIDsystem.git
synced 2026-02-07 11:06:41 +01:00
implementing client blind ID, serverIDsigner blindsign
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
|
||||
.o_nav {
|
||||
background: #000000!important;
|
||||
color: #ffffff!important;
|
||||
border-bottom: 2px solid #4DD0E1!important;
|
||||
}
|
||||
|
||||
BIN
clientApp/GUI/img/blockchainIDsystem-logo.xcf
Normal file
BIN
clientApp/GUI/img/blockchainIDsystem-logo.xcf
Normal file
Binary file not shown.
BIN
clientApp/GUI/img/blockchainIDsystem-logo01.png
Normal file
BIN
clientApp/GUI/img/blockchainIDsystem-logo01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 458 KiB |
BIN
clientApp/GUI/img/blockchainIDsystem-logo02.png
Normal file
BIN
clientApp/GUI/img/blockchainIDsystem-logo02.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 456 KiB |
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"port": "4100",
|
||||
"keysDirectory": "keys"
|
||||
"keysDirectory": "keys",
|
||||
"serverIDsigner": {
|
||||
"ip": "127.0.0.1",
|
||||
"port": "3130"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,4 +21,10 @@ var routes = Routes{
|
||||
"/newid",
|
||||
NewID,
|
||||
},
|
||||
Route{
|
||||
"BlindAndVerify",
|
||||
"GET",
|
||||
"/blindandverify/{pubK}",
|
||||
BlindAndVerify,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ curl -X POST http://127.0.0.1:3130/login -d '{"email": "user1@e.com", "password"
|
||||
echo ""
|
||||
echo "send pubK and m to blind sign"
|
||||
echo "json to send to the serverIDsigner:"
|
||||
echo '{"pubKstring": {"e": "65537", "n": "139093"}, "m": "hola"}'
|
||||
echo '{"m": "hola"}'
|
||||
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 ""
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
|
||||
ownrsa "./ownrsa"
|
||||
@@ -96,13 +97,12 @@ type Sign struct {
|
||||
}
|
||||
|
||||
type AskBlindSign struct {
|
||||
PubKString ownrsa.RSAPublicKeyString `json:"pubKstring"`
|
||||
PubK ownrsa.RSAPublicKey `json:"pubK"`
|
||||
M string `json:"m"`
|
||||
/*PubKString ownrsa.RSAPublicKeyString `json:"pubKstring"`
|
||||
PubK ownrsa.RSAPublicKey `json:"pubK"`*/
|
||||
M string `json:"m"`
|
||||
}
|
||||
|
||||
func BlindSign(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.Body)
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
var askBlindSign AskBlindSign
|
||||
err := decoder.Decode(&askBlindSign)
|
||||
@@ -110,26 +110,36 @@ func BlindSign(w http.ResponseWriter, r *http.Request) {
|
||||
panic(err)
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
color.Red(askBlindSign.M)
|
||||
fmt.Println(askBlindSign)
|
||||
|
||||
/*fmt.Println(askBlindSign)
|
||||
askBlindSign.PubK, err = ownrsa.PubKStringToBigInt(askBlindSign.PubKString)
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "error")
|
||||
return
|
||||
}
|
||||
}*/
|
||||
|
||||
//convert msg to []int
|
||||
var m []int
|
||||
/*var m []int
|
||||
mBytes := []byte(askBlindSign.M)
|
||||
for _, byte := range mBytes {
|
||||
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.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 {
|
||||
|
||||
Reference in New Issue
Block a user