mirror of
https://github.com/nextcloud/passman.git
synced 2025-01-27 17:57:55 +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(){
|
||||
console.log("boom!");
|
||||
ShareService.generateSharedKey(20).then(function(key){
|
||||
console.log(key);
|
||||
var list = $scope.share_settings.credentialSharedWithUserAndGroup;
|
||||
|
@ -108,16 +107,16 @@ angular.module('passmanApp')
|
|||
for (var i = 0; i < list.length; i++){
|
||||
ShareService.getVaultsByUser(list[i].userId).then(function(data){
|
||||
console.log(data);
|
||||
for (var x = 0; x < data.length; x++) {
|
||||
var rsa = ShareService.rsaPublicKeyFromPEM(data[x].public_sharing_key);
|
||||
console.log("parsed RSA public key");
|
||||
var cyphertext = rsa.encrypt(key);
|
||||
console.log(cyphertext);
|
||||
cyphertext= forge.util.encode64(cyphertext);
|
||||
console.log(cyphertext);
|
||||
console.log(cyphertext.length);
|
||||
}
|
||||
})
|
||||
var start = new Date().getTime() / 1000;;
|
||||
ShareService.cypherRSAStringWithPublicKeyBulkAsync(data, key)
|
||||
.progress(function(data){
|
||||
console.log(data);
|
||||
})
|
||||
.then(function(result){
|
||||
console.log(result);
|
||||
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);
|
||||
return $http.get(queryUrl, {search: userId}).then(function (response) {
|
||||
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;
|
||||
} else {
|
||||
return response;
|
||||
|
@ -93,6 +96,37 @@ angular.module('passmanApp')
|
|||
},
|
||||
rsaPublicKeyFromPEM: function(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…
Reference in a new issue