implementing client blind ID, serverIDsigner blindsign
arnaucode arnaucode@gmail.com
Thu, 28 Dec 2017 01:09:44 +0100
18 files changed,
210 insertions(+),
43 deletions(-)
jump to
M
clientApp/GUI/css/bootstrapMaterial-dark-overwrite.css
→
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; }
M
clientApp/GUI/css/own.css
→
clientApp/GUI/css/own.css
@@ -1,1 +1,5 @@
- +.o_nav { + background: #000000!important; + color: #ffffff!important; + border-bottom: 2px solid #4DD0E1!important; +}
M
clientApp/GUI/views/login/login.html
→
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>
M
clientApp/GUI/views/main/main.html
→
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>
M
clientApp/GUI/views/main/main.js
→
clientApp/GUI/views/main/main.js
@@ -32,4 +32,16 @@ }, function(data) {
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'); + }); + }; });
M
clientApp/clientAppRESTFunctions.go
→
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 @@ //generate RSA keys pair
newKey := ownrsa.GenerateKeyPair() key := ownrsa.PackKey(newKey) + key.Date = time.Now() fmt.Println(key) keys := readKeys("keys.json")@@ -40,3 +45,71 @@ jResp, err := json.Marshal(keys)
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)) +}
M
clientApp/config.json
→
clientApp/config.json
@@ -1,4 +1,8 @@
{ "port": "4100", - "keysDirectory": "keys" + "keysDirectory": "keys", + "serverIDsigner": { + "ip": "127.0.0.1", + "port": "3130" + } }
M
clientApp/main.go
→
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()
M
clientApp/ownrsa/rsa.go
→
clientApp/ownrsa/rsa.go
@@ -5,6 +5,7 @@ "errors"
"fmt" "math/big" "math/rand" + "strconv" "strings" "time" )@@ -25,6 +26,13 @@
type RSA struct { PubK RSAPublicKey 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@@ -113,11 +121,11 @@ }
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@@ -181,11 +189,6 @@ if !ok {
return k, errors.New("error parsing big int N") } return k, nil -} - -type PackRSA struct { - PubK string `json:"pubK"` - PrivK string `json:"privK"` } func PackKey(k RSA) PackRSA {@@ -207,3 +210,19 @@ fmt.Println("error on Unpacking Keys")
} 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 +}
M
clientApp/readConfig.go
→
clientApp/readConfig.go
@@ -7,8 +7,13 @@ )
//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
M
clientApp/restRoutes.go
→
clientApp/restRoutes.go
@@ -21,4 +21,10 @@ "GET",
"/newid", NewID, }, + Route{ + "BlindAndVerify", + "GET", + "/blindandverify/{pubK}", + BlindAndVerify, + }, }
M
serverIDsigner/ownrsa/rsa.go
→
serverIDsigner/ownrsa/rsa.go
@@ -5,6 +5,7 @@ "errors"
"fmt" "math/big" "math/rand" + "strconv" "strings" "time" )@@ -25,6 +26,13 @@
type RSA struct { PubK RSAPublicKey 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@@ -113,11 +121,11 @@ }
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@@ -181,11 +189,6 @@ if !ok {
return k, errors.New("error parsing big int N") } return k, nil -} - -type PackRSA struct { - PubK string `json:"pubK"` - PrivK string `json:"privK"` } func PackKey(k RSA) PackRSA {@@ -207,3 +210,19 @@ fmt.Println("error on Unpacking Keys")
} 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 +}
M
serverIDsigner/testUser.sh
→
serverIDsigner/testUser.sh
@@ -10,9 +10,9 @@
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 ""
M
serverIDsigner/userRESTFunctions.go
→
serverIDsigner/userRESTFunctions.go
@@ -7,6 +7,7 @@ "net/http"
"strconv" "strings" + "github.com/fatih/color" "gopkg.in/mgo.v2/bson" ownrsa "./ownrsa"@@ -96,13 +97,12 @@ C string `json:"c"`
} 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 @@ if err != nil {
panic(err) } defer r.Body.Close() + color.Red(askBlindSign.M) + fmt.Println(askBlindSign) - 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)) - } + }*/ + + m := ownrsa.StringToArrayInt(askBlindSign.M, "_") - 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 + 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 {