@ -1 +1,2 @@ |
|||
tests |
|||
peer/blockchain.data |
@ -1 +0,0 @@ |
|||
blockchain.data |
@ -1 +1 @@ |
|||
{"genesisblock":"YKWAWY6GM5xrLhYrfi6hAmPmsECUH83n7xVcgaguLF4=","lastupdate":"0001-01-01T00:00:00Z","blocks":[{"hash":"YKWAWY6GM5xrLhYrfi6hAmPmsECUH83n7xVcgaguLF4=","height":0,"date":"2017-11-29T10:42:55.112675187+01:00","previoushash":"","nexthash":"cSN48a9BwgJQZdz2NwBRPJqCtC4Qtv-l-RYeGl9eBZs=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"cSN48a9BwgJQZdz2NwBRPJqCtC4Qtv-l-RYeGl9eBZs=","height":1,"date":"2017-11-29T23:07:43.169204719+01:00","previoushash":"YKWAWY6GM5xrLhYrfi6hAmPmsECUH83n7xVcgaguLF4=","nexthash":"Ql0MH8WVaCOXzRWmR5xUyAQXaQ5Ovt6PoN3HrkHmYmk=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"Ql0MH8WVaCOXzRWmR5xUyAQXaQ5Ovt6PoN3HrkHmYmk=","height":2,"date":"2017-12-26T14:38:41.446523607+01:00","previoushash":"cSN48a9BwgJQZdz2NwBRPJqCtC4Qtv-l-RYeGl9eBZs=","nexthash":"64bzp4j5jJjCcvKYcsytJOKD5dFyMHUjtNY1S5TD8Sk=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"64bzp4j5jJjCcvKYcsytJOKD5dFyMHUjtNY1S5TD8Sk=","height":3,"date":"2017-12-26T18:05:05.541862456+01:00","previoushash":"Ql0MH8WVaCOXzRWmR5xUyAQXaQ5Ovt6PoN3HrkHmYmk=","nexthash":"N-w5F0pRA0kpZx7JDS3RPBedUSq1Kyk13Pc1guhY7Ws=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"N-w5F0pRA0kpZx7JDS3RPBedUSq1Kyk13Pc1guhY7Ws=","height":4,"date":"2017-12-26T18:06:13.953399725+01:00","previoushash":"64bzp4j5jJjCcvKYcsytJOKD5dFyMHUjtNY1S5TD8Sk=","nexthash":"45Otq5P8WR97T4SxvaFk_0icNdUcIzO-mTjn6wrxJd4=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"45Otq5P8WR97T4SxvaFk_0icNdUcIzO-mTjn6wrxJd4=","height":5,"date":"2017-12-26T18:06:57.93092362+01:00","previoushash":"N-w5F0pRA0kpZx7JDS3RPBedUSq1Kyk13Pc1guhY7Ws=","nexthash":"","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="}]} |
|||
{"genesisblock":"YKWAWY6GM5xrLhYrfi6hAmPmsECUH83n7xVcgaguLF4=","lastupdate":"0001-01-01T00:00:00Z","blocks":[{"hash":"YKWAWY6GM5xrLhYrfi6hAmPmsECUH83n7xVcgaguLF4=","height":0,"date":"2017-11-29T10:42:55.112675187+01:00","previoushash":"","nexthash":"cSN48a9BwgJQZdz2NwBRPJqCtC4Qtv-l-RYeGl9eBZs=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"cSN48a9BwgJQZdz2NwBRPJqCtC4Qtv-l-RYeGl9eBZs=","height":1,"date":"2017-11-29T23:07:43.169204719+01:00","previoushash":"YKWAWY6GM5xrLhYrfi6hAmPmsECUH83n7xVcgaguLF4=","nexthash":"Ql0MH8WVaCOXzRWmR5xUyAQXaQ5Ovt6PoN3HrkHmYmk=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"Ql0MH8WVaCOXzRWmR5xUyAQXaQ5Ovt6PoN3HrkHmYmk=","height":2,"date":"2017-12-26T14:38:41.446523607+01:00","previoushash":"cSN48a9BwgJQZdz2NwBRPJqCtC4Qtv-l-RYeGl9eBZs=","nexthash":"64bzp4j5jJjCcvKYcsytJOKD5dFyMHUjtNY1S5TD8Sk=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"64bzp4j5jJjCcvKYcsytJOKD5dFyMHUjtNY1S5TD8Sk=","height":3,"date":"2017-12-26T18:05:05.541862456+01:00","previoushash":"Ql0MH8WVaCOXzRWmR5xUyAQXaQ5Ovt6PoN3HrkHmYmk=","nexthash":"N-w5F0pRA0kpZx7JDS3RPBedUSq1Kyk13Pc1guhY7Ws=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"N-w5F0pRA0kpZx7JDS3RPBedUSq1Kyk13Pc1guhY7Ws=","height":4,"date":"2017-12-26T18:06:13.953399725+01:00","previoushash":"64bzp4j5jJjCcvKYcsytJOKD5dFyMHUjtNY1S5TD8Sk=","nexthash":"45Otq5P8WR97T4SxvaFk_0icNdUcIzO-mTjn6wrxJd4=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"45Otq5P8WR97T4SxvaFk_0icNdUcIzO-mTjn6wrxJd4=","height":5,"date":"2017-12-26T18:06:57.93092362+01:00","previoushash":"N-w5F0pRA0kpZx7JDS3RPBedUSq1Kyk13Pc1guhY7Ws=","nexthash":"xnXIWKAsIHTOwzWDJe-5daa_5bOSPTLbsG5Ft49g3XA=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"xnXIWKAsIHTOwzWDJe-5daa_5bOSPTLbsG5Ft49g3XA=","height":6,"date":"2017-12-26T20:11:10.182353841+01:00","previoushash":"45Otq5P8WR97T4SxvaFk_0icNdUcIzO-mTjn6wrxJd4=","nexthash":"U-Yz_cpPe6Cm4U9zMunLWH2s5hvUFLHJn7_u_3680Cs=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"U-Yz_cpPe6Cm4U9zMunLWH2s5hvUFLHJn7_u_3680Cs=","height":7,"date":"2017-12-26T21:08:30.923107227+01:00","previoushash":"xnXIWKAsIHTOwzWDJe-5daa_5bOSPTLbsG5Ft49g3XA=","nexthash":"zlsDiXG2raTI2tear0LtIQV72BtHTXLzQGV623_CUDc=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"zlsDiXG2raTI2tear0LtIQV72BtHTXLzQGV623_CUDc=","height":8,"date":"2017-12-26T21:08:45.373348196+01:00","previoushash":"U-Yz_cpPe6Cm4U9zMunLWH2s5hvUFLHJn7_u_3680Cs=","nexthash":"MordV-LXcl8AfW5gVq1wHxLHr3EZn7KhWcRJDEamVbA=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"MordV-LXcl8AfW5gVq1wHxLHr3EZn7KhWcRJDEamVbA=","height":9,"date":"2017-12-26T21:08:59.694290728+01:00","previoushash":"zlsDiXG2raTI2tear0LtIQV72BtHTXLzQGV623_CUDc=","nexthash":"gRhKt8ZRKbDFLr-rSEnipo3QI3loQwTjkNoK0G96Z-w=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"gRhKt8ZRKbDFLr-rSEnipo3QI3loQwTjkNoK0G96Z-w=","height":10,"date":"2017-12-26T21:12:18.832944058+01:00","previoushash":"MordV-LXcl8AfW5gVq1wHxLHr3EZn7KhWcRJDEamVbA=","nexthash":"NQMu54PaN9Ph9Qh2VJb9q6hHbENPYfS62YVkjTs0F1k=","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="},{"hash":"NQMu54PaN9Ph9Qh2VJb9q6hHbENPYfS62YVkjTs0F1k=","height":11,"date":"2017-12-26T21:12:40.460894962+01:00","previoushash":"gRhKt8ZRKbDFLr-rSEnipo3QI3loQwTjkNoK0G96Z-w=","nexthash":"","data":[{"address":"firstaddress"}],"emitter":"VOnL-15rFsUiCnRoyGFksKvWKcwNBRz5iarRem0Ilvo="}]} |
@ -1,3 +0,0 @@ |
|||
curl -X POST http://127.0.0.1:3030/signup -d '{"email": "user1@e.com", "password": "user1"}' |
|||
|
|||
curl -X POST http://127.0.0.1:3030/login -d '{"email": "user1@e.com", "password": "user1"}' |
@ -0,0 +1,5 @@ |
|||
# serverIDsign |
|||
|
|||
- The server where the user creates a non anonymous account |
|||
- Also is the server that blind signs the Anonymous ID of the users |
|||
- Have the webapp (frontend) to interact through a GUI interface |
@ -0,0 +1,9 @@ |
|||
{ |
|||
"ip": "127.0.0.1", |
|||
"port": "3130", |
|||
"webserverport": "3180", |
|||
"mongodb": { |
|||
"ip": "127.0.0.1:27017", |
|||
"database": "serverIDsigner" |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"log" |
|||
"runtime" |
|||
) |
|||
|
|||
func check(err error) { |
|||
if err != nil { |
|||
_, fn, line, _ := runtime.Caller(1) |
|||
log.Println(line) |
|||
log.Println(fn) |
|||
log.Println(err) |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"io" |
|||
"log" |
|||
"os" |
|||
"strings" |
|||
"time" |
|||
) |
|||
|
|||
func savelog() { |
|||
timeS := time.Now().String() |
|||
_ = os.Mkdir("logs", os.ModePerm) |
|||
//next 3 lines are to avoid windows filesystem errors
|
|||
timeS = strings.Replace(timeS, " ", "_", -1) |
|||
timeS = strings.Replace(timeS, ".", "-", -1) |
|||
timeS = strings.Replace(timeS, ":", "-", -1) |
|||
logFile, err := os.OpenFile("logs/log-"+timeS+".log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) |
|||
if err != nil { |
|||
panic(err) |
|||
} |
|||
mw := io.MultiWriter(os.Stdout, logFile) |
|||
log.SetOutput(mw) |
|||
} |
@ -0,0 +1,58 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"log" |
|||
"net/http" |
|||
|
|||
mgo "gopkg.in/mgo.v2" |
|||
|
|||
"github.com/fatih/color" |
|||
"github.com/gorilla/handlers" |
|||
|
|||
ownrsa "./ownrsa" |
|||
) |
|||
|
|||
var userCollection *mgo.Collection |
|||
|
|||
var serverRsa ownrsa.RSA |
|||
|
|||
func main() { |
|||
color.Blue("Starting serverIDsigner") |
|||
|
|||
//read configuration file
|
|||
readConfig("config.json") |
|||
|
|||
initializeToken() |
|||
|
|||
//initialize RSA
|
|||
serverRsa = ownrsa.GenerateKeyPair() |
|||
color.Blue("Public Key:") |
|||
fmt.Println(serverRsa.PubK) |
|||
color.Green("Private Key:") |
|||
fmt.Println(serverRsa.PrivK) |
|||
|
|||
//mongodb
|
|||
session, err := getSession() |
|||
check(err) |
|||
userCollection = getCollection(session, "users") |
|||
|
|||
//run thw webserver
|
|||
go webserver() |
|||
|
|||
//run API
|
|||
log.Println("api server running") |
|||
log.Print("port: ") |
|||
log.Println(config.Port) |
|||
router := NewRouter() |
|||
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"}) |
|||
originsOk := handlers.AllowedOrigins([]string{"*"}) |
|||
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"}) |
|||
log.Fatal(http.ListenAndServe(":"+config.Port, handlers.CORS(originsOk, headersOk, methodsOk)(router))) |
|||
} |
|||
|
|||
func webserver() { |
|||
log.Println("webserver in port " + config.WebServerPort) |
|||
http.Handle("/", http.FileServer(http.Dir("./webapp"))) |
|||
http.ListenAndServe(":"+config.WebServerPort, nil) |
|||
} |
@ -0,0 +1,54 @@ |
|||
package ownrsa |
|||
|
|||
import "math/rand" |
|||
|
|||
func randInt(min int, max int) int { |
|||
r := rand.Intn(max-min) + min |
|||
return r |
|||
} |
|||
func randPrime(min int, max int) int { |
|||
primes := sieveOfEratosthenes(max) |
|||
|
|||
randN := rand.Intn(len(primes)-0) + 0 |
|||
|
|||
return primes[randN] |
|||
|
|||
} |
|||
|
|||
// return list of primes less than N
|
|||
func sieveOfEratosthenes(N int) (primes []int) { |
|||
b := make([]bool, N) |
|||
for i := 2; i < N; i++ { |
|||
if b[i] == true { |
|||
continue |
|||
} |
|||
primes = append(primes, i) |
|||
for k := i * i; k < N; k += i { |
|||
b[k] = true |
|||
} |
|||
} |
|||
return |
|||
} |
|||
|
|||
func gcd(a, b int) int { |
|||
var bgcd func(a, b, res int) int |
|||
|
|||
bgcd = func(a, b, res int) int { |
|||
switch { |
|||
case a == b: |
|||
return res * a |
|||
case a%2 == 0 && b%2 == 0: |
|||
return bgcd(a/2, b/2, 2*res) |
|||
case a%2 == 0: |
|||
return bgcd(a/2, b, res) |
|||
case b%2 == 0: |
|||
return bgcd(a, b/2, res) |
|||
case a > b: |
|||
return bgcd(a-b, b, res) |
|||
default: |
|||
return bgcd(a, b-a, res) |
|||
} |
|||
} |
|||
|
|||
return bgcd(a, b, 1) |
|||
} |
@ -0,0 +1,183 @@ |
|||
package ownrsa |
|||
|
|||
import ( |
|||
"errors" |
|||
"fmt" |
|||
"math/big" |
|||
"math/rand" |
|||
"time" |
|||
) |
|||
|
|||
type RSAPublicKey struct { |
|||
E *big.Int `json:"e"` |
|||
N *big.Int `json:"n"` |
|||
} |
|||
type RSAPublicKeyString struct { |
|||
E string `json:"e"` |
|||
N string `json:"n"` |
|||
} |
|||
type RSAPrivateKey struct { |
|||
D *big.Int `json:"d"` |
|||
N *big.Int `json:"n"` |
|||
} |
|||
|
|||
type RSA struct { |
|||
PubK RSAPublicKey |
|||
PrivK RSAPrivateKey |
|||
} |
|||
|
|||
const maxPrime = 500 |
|||
const minPrime = 100 |
|||
|
|||
func GenerateKeyPair() RSA { |
|||
|
|||
rand.Seed(time.Now().Unix()) |
|||
p := randPrime(minPrime, maxPrime) |
|||
q := randPrime(minPrime, maxPrime) |
|||
fmt.Print("p:") |
|||
fmt.Println(p) |
|||
fmt.Print("q:") |
|||
fmt.Println(q) |
|||
|
|||
n := p * q |
|||
phi := (p - 1) * (q - 1) |
|||
e := 65537 |
|||
var pubK RSAPublicKey |
|||
pubK.E = big.NewInt(int64(e)) |
|||
pubK.N = big.NewInt(int64(n)) |
|||
|
|||
d := new(big.Int).ModInverse(big.NewInt(int64(e)), big.NewInt(int64(phi))) |
|||
|
|||
var privK RSAPrivateKey |
|||
privK.D = d |
|||
privK.N = big.NewInt(int64(n)) |
|||
|
|||
var rsa RSA |
|||
rsa.PubK = pubK |
|||
rsa.PrivK = privK |
|||
return rsa |
|||
} |
|||
func Encrypt(m string, pubK RSAPublicKey) []int { |
|||
var c []int |
|||
mBytes := []byte(m) |
|||
for _, byte := range mBytes { |
|||
c = append(c, EncryptInt(int(byte), pubK)) |
|||
} |
|||
return c |
|||
} |
|||
func Decrypt(c []int, privK RSAPrivateKey) string { |
|||
var m string |
|||
var mBytes []byte |
|||
for _, indC := range c { |
|||
mBytes = append(mBytes, byte(DecryptInt(indC, privK))) |
|||
} |
|||
m = string(mBytes) |
|||
return m |
|||
} |
|||
|
|||
func EncryptBigInt(bigint *big.Int, pubK RSAPublicKey) *big.Int { |
|||
Me := new(big.Int).Exp(bigint, pubK.E, nil) |
|||
c := new(big.Int).Mod(Me, pubK.N) |
|||
return c |
|||
} |
|||
func DecryptBigInt(bigint *big.Int, privK RSAPrivateKey) *big.Int { |
|||
Cd := new(big.Int).Exp(bigint, privK.D, nil) |
|||
m := new(big.Int).Mod(Cd, privK.N) |
|||
return m |
|||
} |
|||
|
|||
func EncryptInt(char int, pubK RSAPublicKey) int { |
|||
charBig := big.NewInt(int64(char)) |
|||
Me := charBig.Exp(charBig, pubK.E, nil) |
|||
c := Me.Mod(Me, pubK.N) |
|||
return int(c.Int64()) |
|||
} |
|||
func DecryptInt(val int, privK RSAPrivateKey) int { |
|||
valBig := big.NewInt(int64(val)) |
|||
Cd := valBig.Exp(valBig, privK.D, nil) |
|||
m := Cd.Mod(Cd, privK.N) |
|||
return int(m.Int64()) |
|||
} |
|||
|
|||
func Blind(m []int, r int, pubK RSAPublicKey, privK RSAPrivateKey) []int { |
|||
var mBlinded []int |
|||
rBigInt := big.NewInt(int64(r)) |
|||
for i := 0; i < len(m); i++ { |
|||
mBigInt := big.NewInt(int64(m[i])) |
|||
rE := new(big.Int).Exp(rBigInt, pubK.E, nil) |
|||
mrE := new(big.Int).Mul(mBigInt, rE) |
|||
mrEmodN := new(big.Int).Mod(mrE, privK.N) |
|||
mBlinded = append(mBlinded, int(mrEmodN.Int64())) |
|||
} |
|||
return mBlinded |
|||
} |
|||
|
|||
func BlindSign(m []int, pubK RSAPublicKey, 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) |
|||
r = append(r, int(sigma.Int64())) |
|||
} |
|||
return r |
|||
} |
|||
func Unblind(blindsigned []int, r int, pubK RSAPublicKey) []int { |
|||
var mSigned []int |
|||
rBigInt := big.NewInt(int64(r)) |
|||
for i := 0; i < len(blindsigned); i++ { |
|||
bsBigInt := big.NewInt(int64(blindsigned[i])) |
|||
//r1 := new(big.Int).Exp(rBigInt, big.NewInt(int64(-1)), nil)
|
|||
r1 := new(big.Int).ModInverse(rBigInt, pubK.N) |
|||
bsr := new(big.Int).Mul(bsBigInt, r1) |
|||
sig := new(big.Int).Mod(bsr, pubK.N) |
|||
mSigned = append(mSigned, int(sig.Int64())) |
|||
} |
|||
return mSigned |
|||
} |
|||
func Verify(msg []int, mSigned []int, pubK RSAPublicKey) bool { |
|||
if len(msg) != len(mSigned) { |
|||
return false |
|||
} |
|||
var mSignedDecrypted []int |
|||
for _, ms := range mSigned { |
|||
msBig := big.NewInt(int64(ms)) |
|||
//decrypt the mSigned with pubK
|
|||
Cd := new(big.Int).Exp(msBig, pubK.E, nil) |
|||
m := new(big.Int).Mod(Cd, pubK.N) |
|||
mSignedDecrypted = append(mSignedDecrypted, int(m.Int64())) |
|||
} |
|||
fmt.Print("msg signed decrypted: ") |
|||
fmt.Println(mSignedDecrypted) |
|||
r := true |
|||
//check if the mSignedDecrypted == msg
|
|||
for i := 0; i < len(msg); i++ { |
|||
if msg[i] != mSignedDecrypted[i] { |
|||
r = false |
|||
} |
|||
} |
|||
return r |
|||
} |
|||
|
|||
func HomomorphicMultiplication(c1 int, c2 int, pubK RSAPublicKey) int { |
|||
c1BigInt := big.NewInt(int64(c1)) |
|||
c2BigInt := big.NewInt(int64(c2)) |
|||
c1c2 := new(big.Int).Mul(c1BigInt, c2BigInt) |
|||
n2 := new(big.Int).Mul(pubK.N, pubK.N) |
|||
d := new(big.Int).Mod(c1c2, n2) |
|||
r := int(d.Int64()) |
|||
return r |
|||
} |
|||
|
|||
func PubKStringToBigInt(kS RSAPublicKeyString) (RSAPublicKey, error) { |
|||
var k RSAPublicKey |
|||
var ok bool |
|||
k.E, ok = new(big.Int).SetString(kS.E, 10) |
|||
if !ok { |
|||
return k, errors.New("error parsing big int E") |
|||
} |
|||
k.N, ok = new(big.Int).SetString(kS.N, 10) |
|||
if !ok { |
|||
return k, errors.New("error parsing big int N") |
|||
} |
|||
return k, nil |
|||
} |
@ -0,0 +1,27 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"io/ioutil" |
|||
) |
|||
|
|||
//Config reads the config
|
|||
type Config struct { |
|||
IP string `json:"ip"` |
|||
Port string `json:"port"` |
|||
WebServerPort string `json:"webserverport"` |
|||
Mongodb MongoConfig `json:"mongodb"` |
|||
} |
|||
type MongoConfig struct { |
|||
IP string `json:"ip"` |
|||
Database string `json:"database"` |
|||
} |
|||
|
|||
var config Config |
|||
|
|||
func readConfig(path string) { |
|||
file, err := ioutil.ReadFile(path) |
|||
check(err) |
|||
content := string(file) |
|||
json.Unmarshal([]byte(content), &config) |
|||
} |
@ -0,0 +1,47 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"log" |
|||
"net/http" |
|||
"time" |
|||
|
|||
"github.com/gorilla/mux" |
|||
) |
|||
|
|||
type Route struct { |
|||
Name string |
|||
Method string |
|||
Pattern string |
|||
HandlerFunc http.HandlerFunc |
|||
} |
|||
|
|||
func Logger(inner http.Handler, name string) http.Handler { |
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|||
start := time.Now() |
|||
|
|||
inner.ServeHTTP(w, r) |
|||
|
|||
log.Printf( |
|||
"%s\t%s\t%s\t%s", |
|||
r.Method, |
|||
r.RequestURI, |
|||
name, |
|||
time.Since(start), |
|||
) |
|||
}) |
|||
} |
|||
func NewRouter() *mux.Router { |
|||
router := mux.NewRouter().StrictSlash(true) |
|||
for _, route := range routes { |
|||
var handler http.Handler |
|||
handler = route.HandlerFunc |
|||
handler = Logger(handler, route.Name) |
|||
|
|||
router. |
|||
Methods(route.Method). |
|||
Path(route.Pattern). |
|||
Name(route.Name). |
|||
Handler(handler) |
|||
} |
|||
return router |
|||
} |
@ -0,0 +1,36 @@ |
|||
package main |
|||
|
|||
type Routes []Route |
|||
|
|||
var routes = Routes{ |
|||
Route{ |
|||
"Index", |
|||
"GET", |
|||
"/", |
|||
Index, |
|||
}, |
|||
Route{ |
|||
"Signup", |
|||
"POST", |
|||
"/signup", |
|||
Signup, |
|||
}, |
|||
Route{ |
|||
"Login", |
|||
"POST", |
|||
"/login", |
|||
Login, |
|||
}, |
|||
Route{ |
|||
"BlindSign", |
|||
"POST", |
|||
"/blindsign", |
|||
BlindSign, |
|||
}, |
|||
Route{ |
|||
"VerifySign", |
|||
"POST", |
|||
"/verifysign", |
|||
VerifySign, |
|||
}, |
|||
} |
@ -0,0 +1,20 @@ |
|||
echo "" |
|||
echo "sending the signup, response:" |
|||
curl -X POST http://127.0.0.1:3130/signup -d '{"email": "user1@e.com", "password": "user1"}' |
|||
|
|||
echo "" |
|||
echo "sending the login, response:" |
|||
curl -X POST http://127.0.0.1:3130/login -d '{"email": "user1@e.com", "password": "user1"}' |
|||
|
|||
|
|||
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 "serverIDsigner response:" |
|||
BLINDSIGNED=$(curl -X POST http://127.0.0.1:3130/blindsign -d '{"pubKstring": {"e": "65537", "n": "139093"}, "m": "hola"}') |
|||
echo "$BLINDSIGNED" |
|||
|
|||
echo "" |
|||
echo "send blindsigned to the serverIDsigner to verify" |
|||
curl -X POST http://127.0.0.1:3130/verifysign -d '{"m": "hola", "mSigned": "131898 40373 107552 34687"}' |