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

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

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

View File

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