diff --git a/clientApp/GUI/views/id/id.html b/clientApp/GUI/views/id/id.html index 7a305f2..2cf1bef 100644 --- a/clientApp/GUI/views/id/id.html +++ b/clientApp/GUI/views/id/id.html @@ -7,6 +7,11 @@

ID: {{id.id}}

+
+ +
{{id.date | date: "dd.MM.y, HH:mm:ss"}}h @@ -23,7 +28,7 @@
PoD:
{{decryptData.m}} -
+
Proof of decrypt
@@ -42,7 +47,7 @@ placeholder="Encrypted data..." >
-
+
Encrypt
diff --git a/clientApp/GUI/views/main/main.html b/clientApp/GUI/views/main/main.html index 6487830..c8cbff9 100755 --- a/clientApp/GUI/views/main/main.html +++ b/clientApp/GUI/views/main/main.html @@ -26,7 +26,7 @@
Add to blockchain
- + Use ID
diff --git a/clientApp/clientApp.go b/clientApp/clientApp.go index b78a7fa..d426947 100644 --- a/clientApp/clientApp.go +++ b/clientApp/clientApp.go @@ -8,6 +8,7 @@ import ( "crypto/sha1" "encoding/json" "fmt" + "io/ioutil" "net/http" "os/exec" "time" @@ -37,8 +38,16 @@ func NewID() []Key { key.PrivK = id + "private.pem" key.PubK = id + "public.pem" + time.Sleep(time.Second * 2) + + b, err := ioutil.ReadFile(keysDir + "/" + key.PubK) + if err != nil { + fmt.Print(err) + } + key.PublicKey = string(b) + key.Date = time.Now() - fmt.Println(key) + fmt.Println(key.PublicKey) keys := readKeys() keys = append(keys, key) diff --git a/clientApp/keys.go b/clientApp/keys.go index cb4624b..1a9522b 100644 --- a/clientApp/keys.go +++ b/clientApp/keys.go @@ -19,6 +19,7 @@ type Key struct { ID string `json:"id"` PrivK string `json:"privK"` //path of the PrivK file PubK string `json:"pubK"` //path of the PubK file + PublicKey string `json:"publicKey"` Date time.Time `json:"date"` Hashed []byte `json:"hashed"` UnblindedSig []byte `json:"unblindedsig"` diff --git a/clientApp/main.go b/clientApp/main.go index b73d0e9..8b90d42 100644 --- a/clientApp/main.go +++ b/clientApp/main.go @@ -40,6 +40,6 @@ func main() { func GUI() { //here, run webserver log.Println("webserver in port " + "8080") - http.Handle("/", http.FileServer(http.Dir("./web"))) + http.Handle("/", http.FileServer(http.Dir("./GUI"))) http.ListenAndServe(":"+"8080", nil) } diff --git a/darkID-library-login-example/.gitignore b/darkID-library-login-example/.gitignore index 8afb6b9..51c0ee8 100644 --- a/darkID-library-login-example/.gitignore +++ b/darkID-library-login-example/.gitignore @@ -1,3 +1,2 @@ keys.json keys -web diff --git a/darkID-library-login-example/RESTfunctions.go b/darkID-library-login-example/RESTfunctions.go index 340d8c0..9960cb8 100644 --- a/darkID-library-login-example/RESTfunctions.go +++ b/darkID-library-login-example/RESTfunctions.go @@ -1,11 +1,16 @@ package main import ( + "crypto/rand" + "crypto/rsa" + "crypto/sha1" "encoding/json" + "errors" "fmt" + mrand "math/rand" "net/http" + "strings" - "github.com/cryptoballot/rsablind" "github.com/fatih/color" "gopkg.in/mgo.v2/bson" @@ -22,54 +27,89 @@ func Index(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "clientApp") } -func Signup(w http.ResponseWriter, r *http.Request) { +type Proof struct { + PublicKey string `json:"publicKey"` + Clear string `json:"clear"` + Question []byte `json:"question"` + Answer string `json:"answer"` +} + +var proofs []Proof + +func GetProof(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) - var user User - err := decoder.Decode(&user) + var receivedProof Proof + err := decoder.Decode(&receivedProof) if err != nil { panic(err) } defer r.Body.Close() + //TODO check if the user password exists in the database + + stringPublicKey := strings.Replace(receivedProof.PublicKey, " ", "\n", -1) + stringPublicKey = strings.Replace(stringPublicKey, "-----BEGIN\n", "-----BEGIN ", -1) + stringPublicKey = strings.Replace(stringPublicKey, "-----END\n", "-----END ", -1) + stringPublicKey = strings.Replace(stringPublicKey, "PUBLIC\n", "PUBLIC ", -1) + color.Green(stringPublicKey) + publicKey, err := ParseRsaPublicKeyFromPemStr(stringPublicKey) + check(err) - fmt.Print("user signup: ") - fmt.Println(user) + var proof Proof + proof.Clear = RandStringRunes(40) - jResp, err := json.Marshal(user) + out, err := rsa.EncryptOAEP(sha1.New(), rand.Reader, &publicKey, []byte(proof.Clear), []byte("orders")) + check(err) + proof.Question = out + + proofs = append(proofs, proof) + + proof.Clear = "" + jResp, err := json.Marshal(proof) if err != nil { panic(err) } fmt.Fprintln(w, string(jResp)) } - -func Login(w http.ResponseWriter, r *http.Request) { +func AnswerProof(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) - var key Key - err := decoder.Decode(&key) + var ansProof Proof + err := decoder.Decode(&ansProof) if err != nil { panic(err) } defer r.Body.Close() - //TODO check if the user password exists in the database - fmt.Print("key login: ") - fmt.Println(key) - token, err := newToken() - check(err) + proof, err := getProofFromStorage(ansProof.PublicKey) + if err != nil { - //validate if the pubK darkID is in the blockchain + } + if ansProof.Answer == proof.Clear { + token, err := newToken() + check(err) + fmt.Fprintln(w, string(token)) + } - //verify that the darkID is signed - if err := rsablind.VerifyBlindSignature(key.ServerVerifier, key.Hashed, key.UnblindedSig); err != nil { - fmt.Println(err) - } else { - color.Green("blind signature verified") + fmt.Fprintln(w, string("fail")) +} +func getProofFromStorage(publicKey string) (Proof, error) { + var voidProof Proof + for _, proof := range proofs { + if proof.PublicKey == publicKey { + return proof, nil + } } + return voidProof, errors.New("proof not exist in storage") +} - /*jResp, err := json.Marshal(token) - if err != nil { - panic(err) - }*/ - fmt.Fprintln(w, string(token)) +//function to generate random string of fixed length +var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + +func RandStringRunes(n int) string { + b := make([]rune, n) + for i := range b { + b[i] = letterRunes[mrand.Intn(len(letterRunes))] + } + return string(b) } diff --git a/darkID-library-login-example/config.json b/darkID-library-login-example/config.json index dfefadd..5834e77 100755 --- a/darkID-library-login-example/config.json +++ b/darkID-library-login-example/config.json @@ -1,3 +1,4 @@ { - "port": "5000" + "port": "5010", + "webserverport": "5011" } diff --git a/darkID-library-login-example/main.go b/darkID-library-login-example/main.go index eb43162..cd0e495 100644 --- a/darkID-library-login-example/main.go +++ b/darkID-library-login-example/main.go @@ -3,7 +3,9 @@ package main import ( "fmt" "log" + "math/rand" "net/http" + "time" "github.com/fatih/color" "github.com/gorilla/handlers" @@ -19,9 +21,10 @@ func main() { readConfig("config.json") fmt.Println(config) - /*//create keys directory - _ = os.Mkdir(keysDir, os.ModePerm)*/ + //initialize rand + rand.Seed(time.Now().UnixNano()) + //initialize token initializeToken() //run thw webserver @@ -40,7 +43,7 @@ func main() { func GUI() { //here, run webserver - log.Println("webserver in port " + "8080") + log.Println("webserver in port " + config.WebServerPort) http.Handle("/", http.FileServer(http.Dir("./web"))) - http.ListenAndServe(":"+"8080", nil) + http.ListenAndServe(":"+config.WebServerPort, nil) } diff --git a/darkID-library-login-example/readConfig.go b/darkID-library-login-example/readConfig.go index 9b7e71d..6c41418 100755 --- a/darkID-library-login-example/readConfig.go +++ b/darkID-library-login-example/readConfig.go @@ -7,7 +7,8 @@ import ( //Config reads the config type Config struct { - Port string `json:"port"` + Port string `json:"port"` + WebServerPort string `json:"webserverport"` } var config Config diff --git a/darkID-library-login-example/restRoutes.go b/darkID-library-login-example/restRoutes.go index e053e94..b0f4535 100755 --- a/darkID-library-login-example/restRoutes.go +++ b/darkID-library-login-example/restRoutes.go @@ -10,15 +10,15 @@ var routes = Routes{ Index, }, Route{ - "Signup", + "GetProof", "POST", - "/signup", - Signup, + "/getproof", + GetProof, }, Route{ - "Login", + "AnswerProof", "POST", - "/login", - Login, + "/answerproof", + AnswerProof, }, } diff --git a/darkID-library-login-example/testUser.sh b/darkID-library-login-example/testUser.sh deleted file mode 100644 index 01b1ef7..0000000 --- a/darkID-library-login-example/testUser.sh +++ /dev/null @@ -1,20 +0,0 @@ -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"}' diff --git a/darkID-library-login-example/web/.bowerrc b/darkID-library-login-example/web/.bowerrc new file mode 100644 index 0000000..baa91a3 --- /dev/null +++ b/darkID-library-login-example/web/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "bower_components" +} \ No newline at end of file diff --git a/darkID-library-login-example/web/.gitignore b/darkID-library-login-example/web/.gitignore new file mode 100644 index 0000000..7bf6eb1 --- /dev/null +++ b/darkID-library-login-example/web/.gitignore @@ -0,0 +1,2 @@ +bower_components +node_modules diff --git a/darkID-library-login-example/web/app.js b/darkID-library-login-example/web/app.js new file mode 100644 index 0000000..aa82ddf --- /dev/null +++ b/darkID-library-login-example/web/app.js @@ -0,0 +1,63 @@ +'use strict'; + + +var urlapi = "http://127.0.0.1:5010/"; + +// Declare app level module which depends on views, and components +angular.module('app', [ + 'ngRoute', + 'ngMessages', + 'angularBootstrapMaterial', + 'ui.bootstrap', + 'toastr', + 'app.main', + 'app.login' +]). +config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) { + $locationProvider.hashPrefix('!'); + $routeProvider.otherwise({ + redirectTo: '/login' + }); + }]) + .config(function(toastrConfig) { + angular.extend(toastrConfig, { + autoDismiss: false, + containerId: 'toast-container', + maxOpened: 0, + newestOnTop: true, + positionClass: 'toast-bottom-right', + preventDuplicates: false, + preventOpenDuplicates: false, + target: 'body' + }); + }) + .factory('httpInterceptor', function httpInterceptor() { + return { + request: function(config) { + return config; + }, + + requestError: function(config) { + return config; + }, + + response: function(res) { + return res; + }, + + responseError: function(res) { + return res; + } + }; + }) + .factory('api', function($http) { + return { + init: function() { + /*$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('block_webapp_token'); + $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('block_webapp_token');*/ + } + }; + }) + .run(function(api) { + api.init(); + }); diff --git a/darkID-library-login-example/web/bower.json b/darkID-library-login-example/web/bower.json new file mode 100644 index 0000000..7d64bd4 --- /dev/null +++ b/darkID-library-login-example/web/bower.json @@ -0,0 +1,19 @@ +{ + "name": "darkID-library-login-example", + "description": "", + "version": "0.0.0", + "homepage": "", + "license": "MIT", + "private": true, + "dependencies": { + "angular": "^1.6.2", + "angular-route": "^1.6.1", + "angular-messages": "^1.6.5", + "angular-bootstrap-material": "abm#^0.1.4", + "angular-bootstrap": "^2.5.0", + "components-font-awesome": "^4.7.0", + "angular-toastr": "^2.1.1", + "cssMaterialColors": "*", + "angular-chart.js": "^1.1.1" + } +} diff --git a/darkID-library-login-example/web/css/own.css b/darkID-library-login-example/web/css/own.css new file mode 100644 index 0000000..e69de29 diff --git a/darkID-library-login-example/web/index.html b/darkID-library-login-example/web/index.html new file mode 100644 index 0000000..17b16fa --- /dev/null +++ b/darkID-library-login-example/web/index.html @@ -0,0 +1,74 @@ + + + + + + library-login-example + + + + + + + + + + + + + + + + + +



+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/darkID-library-login-example/web/package.json b/darkID-library-login-example/web/package.json new file mode 100644 index 0000000..fc7c68d --- /dev/null +++ b/darkID-library-login-example/web/package.json @@ -0,0 +1,11 @@ +{ + "name": "darkID-library-login-example", + "version": "1.0.0", + "description": "darkID-library-login-example", + "scripts": { + "postinstall": "bower install", + "prestart": "npm install", + "start": "http-server" + }, + "license": "MIT" +} diff --git a/darkID-library-login-example/web/views/login/login.html b/darkID-library-login-example/web/views/login/login.html new file mode 100755 index 0000000..2f06835 --- /dev/null +++ b/darkID-library-login-example/web/views/login/login.html @@ -0,0 +1,43 @@ +
+
+
+ +
+
+
+
+

+ Some platform login example +

+
+ +
+
+
Proof of darkID
+
+
+ Proof question: +
+
+ +
+ +
+
Send answer
+
+
+
+
+
+ + +
+ +
+
+
diff --git a/darkID-library-login-example/web/views/login/login.js b/darkID-library-login-example/web/views/login/login.js new file mode 100755 index 0000000..acf477b --- /dev/null +++ b/darkID-library-login-example/web/views/login/login.js @@ -0,0 +1,64 @@ +'use strict'; + +angular.module('app.login', ['ngRoute']) + + .config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/login', { + templateUrl: 'views/login/login.html', + controller: 'LoginCtrl' + }); + }]) + + .controller('LoginCtrl', function($scope, $rootScope, $http, $routeParams, toastr) { + $rootScope.server = "" + $scope.proof = { + publicKey: "", + clear: "", + question: "", + answer: "" + }; + $scope.getproof = function() { + $http({ + url: urlapi + 'getproof', + method: "POST", + headers: { + "Content-Type": undefined + }, + data: $scope.proof + }) + .then(function(data) { + console.log("data: "); + console.log(data.data); + $scope.proof = data.data; + }, + function(data) { + console.log(data); + toastr.error("error: bad darkID PublicKey") + }); + + }; + $scope.sendanswer = function() { + $http({ + url: urlapi + 'answerproof', + method: "POST", + headers: { + "Content-Type": undefined + }, + data: $scope.proof + }) + .then(function(data) { + console.log("data: "); + console.log(data.data); + if(data.data=="fail\n") { + toastr.error("Proof of darkID failed"); + }else{ + toastr.success("You are logged with darkID!"); + window.location="#!/main"; + } + }, + function(data) { + console.log(data); + }); + + }; + }); diff --git a/darkID-library-login-example/web/views/main/main.html b/darkID-library-login-example/web/views/main/main.html new file mode 100755 index 0000000..f01a63a --- /dev/null +++ b/darkID-library-login-example/web/views/main/main.html @@ -0,0 +1,19 @@ +
+
+
+ +
+
+

+ You are logged! +

+
+ +
+
+
+ +
+ +
+
diff --git a/darkID-library-login-example/web/views/main/main.js b/darkID-library-login-example/web/views/main/main.js new file mode 100755 index 0000000..ebed1dc --- /dev/null +++ b/darkID-library-login-example/web/views/main/main.js @@ -0,0 +1,15 @@ +'use strict'; + +angular.module('app.main', ['ngRoute']) + + .config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/main', { + templateUrl: 'views/main/main.html', + controller: 'MainCtrl' + }); + }]) + + .controller('MainCtrl', function($scope, $rootScope, $http) { + + + }); diff --git a/runTmuxTestPeers.sh b/runTmuxTestPeers.sh index 7fd19e2..7e61cee 100644 --- a/runTmuxTestPeers.sh +++ b/runTmuxTestPeers.sh @@ -1,11 +1,18 @@ SESSION='darkIDtest' tmux new-session -d -s $SESSION -tmux split-window -d -t 0 -v tmux split-window -d -t 0 -h +tmux split-window -d -t 0 -v + + tmux send-keys -t 0 'cd serverIDsigner && go run *.go' enter -tmux send-keys -t 1 'cd clientApp && go run *.go' enter -tmux send-keys -t 2 'cd clientApp/GUI && http-server' enter +tmux send-keys -t 2 'cd clientApp && go run *.go' enter +tmux send-keys -t 1 'cd darkID-library-login-example && go run *.go' enter tmux attach + + +# websites: +# 127.0.0.1:8080 darkID client +# 127.0.0.1:5011 library login example with darkID