Browse Source

added proof-of-decrypt, encrypt, decrypt

master
arnaucode 7 years ago
parent
commit
6cdeaf4695
8 changed files with 230 additions and 3 deletions
  1. +3
    -2
      clientApp/GUI/app.js
  2. +1
    -0
      clientApp/GUI/index.html
  3. +55
    -0
      clientApp/GUI/views/id/id.html
  4. +76
    -0
      clientApp/GUI/views/id/id.js
  5. +1
    -1
      clientApp/GUI/views/navbar.html
  6. +23
    -0
      clientApp/clientApp.go
  7. +53
    -0
      clientApp/clientAppRESTFunctions.go
  8. +18
    -0
      clientApp/restRoutes.go

+ 3
- 2
clientApp/GUI/app.js

@ -1,6 +1,6 @@
'use strict';
//var urlapi = "http://127.0.0.1:3130/";
var clientapi = "http://127.0.0.1:4100/";
// Declare app level module which depends on views, and components
@ -13,7 +13,8 @@ angular.module('app', [
'app.navbar',
'app.main',
'app.signup',
'app.login'
'app.login',
'app.id'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');

+ 1
- 0
clientApp/GUI/index.html

@ -58,6 +58,7 @@ Works for both browser and electron with the same code -->
<script src="views/main/main.js"></script>
<script src="views/signup/signup.js"></script>
<script src="views/login/login.js"></script>
<script src="views/id/id.js"></script>
<!-- ELECTRON

+ 55
- 0
clientApp/GUI/views/id/id.html

@ -0,0 +1,55 @@
<div class="container">
<div class="row">
<div class="col-sm-2">
</div>
<div class="col-sm-8">
<div class="card">
<div class="card-body">
<h4>ID: {{id.id}}</h4>
<span class="pull-right">{{id.date | date: "dd.MM.y, HH:mm:ss"}}h</span>
<span class="badge c_o_red300" ng-show="!id.verified">Not verified</span>
<span class="badge c_o_green300" ng-show="id.verified">Verified</span>
<span class="badge c_o_orange300" ng-show="!id.unblindedsig">Not signed</span>
<span class="badge c_o_blue300" ng-show="id.unblindedsig">Signed</span>
<span class="badge c_o_deepPurple300" ng-show="id.blockchainref">in Blockchain</span>
<div class="row">
<textarea style="color:#000000;width:100%;" rows="4"
ng-model="decryptData.c"
placeholder="Enter here the proof-of-decrypt..."
></textarea>
</div>
{{decryptData.m}}
<div ng-click="decrypt()" ng-show="id.blockchainref" class="btn btn-raised pull-right c_o_pink300">
Proof of decrypt
</div>
</div>
</div>
<br><br><br><br><br>
<hr>
<div class="row">
<h5>Testing only:</h5>
<div class="row">
<textarea style="color:#000000;width:100%;" rows="4"
ng-model="encryptData.m"
placeholder="Enter here the unencrypted..."
></textarea>
</div>
<textarea style="backgroud:grey;color:#000000;width:100%;" rows="4"
ng-model="encryptData.c"
placeholder="Encrypted data..."
></textarea>
<div ng-click="encrypt()" ng-show="id.blockchainref" class="btn btn-raised pull-right c_o_orange300">
Encrypt
</div>
</div>
</div>
<div class="col-sm-2">
</div>
</div>
</div>

+ 76
- 0
clientApp/GUI/views/id/id.js

@ -0,0 +1,76 @@
'use strict';
angular.module('app.id', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/id/:keyid', {
templateUrl: 'views/id/id.html',
controller: 'IdCtrl'
});
}])
.controller('IdCtrl', function($scope, $rootScope, $http, $routeParams) {
$scope.keyid = $routeParams.keyid;
$scope.decryptData = {
m:"",
c:""
};
$scope.encryptData = {
m:"",
c:""
};
$rootScope.server = JSON.parse(localStorage.getItem("darkID_server"));
$scope.id = {};
$scope.clientApp = function(route, param) {
$http.get(clientapi + route + '/' + param)
.then(function(data) {
console.log('data success');
console.log(data);
$scope.id = data.data;
}, function(data) {
console.log('data error');
});
};
$scope.clientApp('id', $routeParams.keyid);
$scope.decrypt = function() {
$http({
url: clientapi + 'decrypt/' + $routeParams.keyid,
method: "POST",
headers: {
"Content-Type": undefined
},
data: $scope.decryptData
})
.then(function(data) {
console.log("data: ");
console.log(data.data);
$scope.decryptData = data.data;
},
function(data) {
console.log(data);
});
};
$scope.encrypt = function() {
$http({
url: clientapi + 'encrypt/' + $routeParams.keyid,
method: "POST",
headers: {
"Content-Type": undefined
},
data: $scope.encryptData
})
.then(function(data) {
console.log("data: ");
console.log(data.data);
$scope.encryptData = data.data;
},
function(data) {
console.log(data);
});
};
});

+ 1
- 1
clientApp/GUI/views/navbar.html

@ -7,7 +7,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/" title="darkID">
<a class="navbar-brand" href="#!/" title="darkID">
<img src="img/darkID-logo-white.png" style="width:30px;height:30px;display:inline;" alt=""> <b>darkID</b>
</a>
</div>

+ 23
- 0
clientApp/clientApp.go

@ -5,6 +5,7 @@ import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
"encoding/json"
"fmt"
"net/http"
@ -140,3 +141,25 @@ func Delete(keyID string) []Key {
saveKeys(keys)
return keys
}
func Encrypt(keyID string, encryptData EncryptData) EncryptData {
key := getKeyByKeyID(keyID)
pubK, err := openPublicPEMKey(keysDir + "/" + key.PubK)
check(err)
out, err := rsa.EncryptOAEP(sha1.New(), rand.Reader, &pubK, []byte(encryptData.M), []byte("orders"))
check(err)
fmt.Println(string(out))
encryptData.C = out
return encryptData
}
func Decrypt(keyID string, encryptData EncryptData) EncryptData {
key := getKeyByKeyID(keyID)
privK, err := openPEMKey(keysDir + "/" + key.PrivK)
check(err)
out, err := rsa.DecryptOAEP(sha1.New(), rand.Reader, privK, []byte(encryptData.C), []byte("orders"))
check(err)
fmt.Println(string(out))
encryptData.M = string(out)
return encryptData
}

+ 53
- 0
clientApp/clientAppRESTFunctions.go

@ -26,6 +26,15 @@ func GetIDs(w http.ResponseWriter, r *http.Request) {
check(err)
fmt.Fprintln(w, string(jResp))
}
func GetID(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
keyID := vars["keyid"]
key := getKeyByKeyID(keyID)
jResp, err := json.Marshal(key)
check(err)
fmt.Fprintln(w, string(jResp))
}
func GetNewID(w http.ResponseWriter, r *http.Request) {
key := NewID()
@ -70,3 +79,47 @@ func GetDelete(w http.ResponseWriter, r *http.Request) {
check(err)
fmt.Fprintln(w, string(jResp))
}
type EncryptData struct {
M string `json:"m"`
C []byte `json:"c"`
}
func PostEncrypt(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
keyID := vars["keyid"]
//get ciphertext from POST json
decoder := json.NewDecoder(r.Body)
var encryptData EncryptData
err := decoder.Decode(&encryptData)
if err != nil {
panic(err)
}
defer r.Body.Close()
encryptData = Encrypt(keyID, encryptData)
jResp, err := json.Marshal(encryptData)
check(err)
fmt.Fprintln(w, string(jResp))
}
func PostDecrypt(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
keyID := vars["keyid"]
//get ciphertext from POST json
decoder := json.NewDecoder(r.Body)
var encryptData EncryptData
err := decoder.Decode(&encryptData)
if err != nil {
panic(err)
}
defer r.Body.Close()
encryptData = Decrypt(keyID, encryptData)
jResp, err := json.Marshal(encryptData)
check(err)
fmt.Fprintln(w, string(jResp))
}

+ 18
- 0
clientApp/restRoutes.go

@ -21,6 +21,12 @@ var routes = Routes{
"/ids",
GetIDs,
},
Route{
"GetID",
"GET",
"/id/{keyid}",
GetID,
},
Route{
"GetNewID",
"GET",
@ -45,4 +51,16 @@ var routes = Routes{
"/delete/{keyid}",
GetDelete,
},
Route{
"PostEncrypt",
"POST",
"/encrypt/{keyid}",
PostEncrypt,
},
Route{
"PostDecrypt",
"POST",
"/decrypt/{keyid}",
PostDecrypt,
},
}

Loading…
Cancel
Save