mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-08 20:46:12 +08:00
Sharing RSA cypher async
This commit is contained in:
parent
07b7aa8787
commit
b45d5b3634
2 changed files with 45 additions and 12 deletions
|
@ -97,10 +97,9 @@ angular.module('passmanApp')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
$scope.applyShare = function(){
|
$scope.applyShare = function(){
|
||||||
console.log("boom!");
|
|
||||||
ShareService.generateSharedKey(20).then(function(key){
|
ShareService.generateSharedKey(20).then(function(key){
|
||||||
console.log(key);
|
console.log(key);
|
||||||
var list = $scope.share_settings.credentialSharedWithUserAndGroup;
|
var list = $scope.share_settings.credentialSharedWithUserAndGroup;
|
||||||
|
@ -108,16 +107,16 @@ angular.module('passmanApp')
|
||||||
for (var i = 0; i < list.length; i++){
|
for (var i = 0; i < list.length; i++){
|
||||||
ShareService.getVaultsByUser(list[i].userId).then(function(data){
|
ShareService.getVaultsByUser(list[i].userId).then(function(data){
|
||||||
console.log(data);
|
console.log(data);
|
||||||
for (var x = 0; x < data.length; x++) {
|
var start = new Date().getTime() / 1000;;
|
||||||
var rsa = ShareService.rsaPublicKeyFromPEM(data[x].public_sharing_key);
|
ShareService.cypherRSAStringWithPublicKeyBulkAsync(data, key)
|
||||||
console.log("parsed RSA public key");
|
.progress(function(data){
|
||||||
var cyphertext = rsa.encrypt(key);
|
console.log(data);
|
||||||
console.log(cyphertext);
|
})
|
||||||
cyphertext= forge.util.encode64(cyphertext);
|
.then(function(result){
|
||||||
console.log(cyphertext);
|
console.log(result);
|
||||||
console.log(cyphertext.length);
|
console.log("Took: " + ((new Date().getTime() / 1000) - start) + "s to cypher the string for user [" + data[0].user_id + "]");
|
||||||
}
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@ angular.module('passmanApp')
|
||||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/vaults/'+ userId);
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/vaults/'+ userId);
|
||||||
return $http.get(queryUrl, {search: userId}).then(function (response) {
|
return $http.get(queryUrl, {search: userId}).then(function (response) {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
|
for (var i = 0; i < response.data.length; i++){
|
||||||
|
response.data[i].public_sharing_key = forge.pki.publicKeyFromPem(response.data[i].public_sharing_key);
|
||||||
|
}
|
||||||
return response.data;
|
return response.data;
|
||||||
} else {
|
} else {
|
||||||
return response;
|
return response;
|
||||||
|
@ -93,6 +96,37 @@ angular.module('passmanApp')
|
||||||
},
|
},
|
||||||
rsaPublicKeyFromPEM: function(public_pem){
|
rsaPublicKeyFromPEM: function(public_pem){
|
||||||
return forge.pki.publicKeyFromPem(public_pem);
|
return forge.pki.publicKeyFromPem(public_pem);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Cyphers an array of string in a non-blocking way
|
||||||
|
* @param vaults[] An array of vaults with the processed public keys
|
||||||
|
* @param string The string to cypher
|
||||||
|
*/
|
||||||
|
cypherRSAStringWithPublicKeyBulkAsync: function(vaults, string){
|
||||||
|
var workload = function(){
|
||||||
|
if (this.current_index < this.vaults.length > 0 && this.vaults.length > 0) {
|
||||||
|
this.data.push(
|
||||||
|
forge.util.encode64(
|
||||||
|
this.vaults[this.current_index].public_sharing_key.encrypt(this.string)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
this.current_index++;
|
||||||
|
|
||||||
|
this.call_progress(this.current_index);
|
||||||
|
setTimeout(workload.bind(this), 1);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.call_then(this.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new C_Promise(function(){
|
||||||
|
this.data = [];
|
||||||
|
this.vaults = vaults;
|
||||||
|
this.string = string;
|
||||||
|
this.current_index = 0;
|
||||||
|
|
||||||
|
setTimeout(workload.bind(this), 0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue