Browse Source

implementing client blind ID, serverIDsigner blindsign

master
arnaucode 6 years ago
parent
commit
4898cae5c0
18 changed files with 210 additions and 43 deletions
  1. +6
    -1
      clientApp/GUI/css/bootstrapMaterial-dark-overwrite.css
  2. +5
    -1
      clientApp/GUI/css/own.css
  3. BIN
      clientApp/GUI/img/blockchainIDsystem-logo.xcf
  4. BIN
      clientApp/GUI/img/blockchainIDsystem-logo01.png
  5. BIN
      clientApp/GUI/img/blockchainIDsystem-logo02.png
  6. +2
    -2
      clientApp/GUI/views/login/login.html
  7. +17
    -9
      clientApp/GUI/views/main/main.html
  8. +12
    -0
      clientApp/GUI/views/main/main.js
  9. +1
    -1
      clientApp/GUI/views/navbar.html
  10. +73
    -0
      clientApp/clientAppRESTFunctions.go
  11. +5
    -1
      clientApp/config.json
  12. +2
    -0
      clientApp/main.go
  13. +26
    -7
      clientApp/ownrsa/rsa.go
  14. +7
    -2
      clientApp/readConfig.go
  15. +6
    -0
      clientApp/restRoutes.go
  16. +26
    -7
      serverIDsigner/ownrsa/rsa.go
  17. +2
    -2
      serverIDsigner/testUser.sh
  18. +20
    -10
      serverIDsigner/userRESTFunctions.go

+ 6
- 1
clientApp/GUI/css/bootstrapMaterial-dark-overwrite.css

@ -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;
}

+ 5
- 1
clientApp/GUI/css/own.css

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

BIN
clientApp/GUI/img/blockchainIDsystem-logo.xcf


BIN
clientApp/GUI/img/blockchainIDsystem-logo01.png

Before After
Width: 1279  |  Height: 1279  |  Size: 458 KiB

BIN
clientApp/GUI/img/blockchainIDsystem-logo02.png

Before After
Width: 1279  |  Height: 1279  |  Size: 456 KiB

+ 2
- 2
clientApp/GUI/views/login/login.html

@ -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>

+ 17
- 9
clientApp/GUI/views/main/main.html

@ -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>

+ 12
- 0
clientApp/GUI/views/main/main.js

@ -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
- 1
clientApp/GUI/views/navbar.html

@ -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">

+ 73
- 0
clientApp/clientAppRESTFunctions.go

@ -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))
}

+ 5
- 1
clientApp/config.json

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

+ 2
- 0
clientApp/main.go

@ -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()

+ 26
- 7
clientApp/ownrsa/rsa.go

@ -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
- 2
clientApp/readConfig.go

@ -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

+ 6
- 0
clientApp/restRoutes.go

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

+ 26
- 7
serverIDsigner/ownrsa/rsa.go

@ -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
}

+ 2
- 2
serverIDsigner/testUser.sh

@ -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 ""

+ 20
- 10
serverIDsigner/userRESTFunctions.go

@ -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 {

Loading…
Cancel
Save