passman/js/app/services/shareservice.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
/**
* @ngdoc service
* @name passmanApp.ShareService
* @description
* # ShareService
* Service in the passmanApp.
*/
angular.module('passmanApp')
2016-09-26 04:02:58 +08:00
.service('ShareService', ['$http', 'VaultService', 'EncryptService', function ($http, VaultService, EncryptService) {
return {
search: function (string) {
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/search');
return $http.post(queryUrl, {search: string}).then(function (response) {
if (response.data) {
return response.data;
} else {
return response;
}
});
},
2016-09-26 00:42:41 +08:00
generateRSAKeys: function(key_length, progress, callback){
var state = forge.pki.rsa.createKeyPairGenerationState(key_length, 0x10001);
var step = function() {
// run for 100 ms
if(!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) {
// console.log(state);
if (state.p !== null) {
progress(50);
}
else {
progress(0);
}
2016-09-26 00:42:41 +08:00
setTimeout(step, 1);
}
else {
callback(state.keys);
}
};
setTimeout(step, 100);
},
rsaKeyPairToPEM: function(keypair){
return {
'publicKey' : forge.pki.publicKeyToPem(keypair.publicKey),
'privateKey' : forge.pki.privateKeyToPem(keypair.privateKey)
};
2016-09-26 00:42:41 +08:00
},
2016-09-26 04:02:58 +08:00
getSharingKeys: function(){
var vault = VaultService.getActiveVault();
return{
'private_sharing_key': EncryptService.decryptString(angular.copy(vault.private_sharing_key)),
'public_sharing_key': vault.public_sharing_key
};
},
2016-09-26 00:42:41 +08:00
rsaPrivateKeyFromPEM: function(private_pem) {
return forge.pki.privateKeyFromPem(private_pem);
},
rsaPublicKeyFromPEM: function(public_pem){
return forge.pki.publicKeyFromPem(public_pem);
}
}
}]);