mirror of
https://github.com/nextcloud/passman.git
synced 2024-12-27 01:52:56 +08:00
Show message if an credential is expired
This commit is contained in:
parent
2b8efe22fa
commit
306bdbda8b
3 changed files with 59 additions and 47 deletions
|
@ -6,7 +6,7 @@
|
||||||
* Controller of the passmanApp
|
* Controller of the passmanApp
|
||||||
*/
|
*/
|
||||||
angular.module('passmanApp')
|
angular.module('passmanApp')
|
||||||
.controller('PublicSharedCredential', ['$scope', 'ShareService', function ($scope, ShareService) {
|
.controller('PublicSharedCredential', ['$scope', 'ShareService','$window', function ($scope, ShareService, $window) {
|
||||||
$scope.test = 'hello world';
|
$scope.test = 'hello world';
|
||||||
|
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
|
@ -75,12 +75,18 @@ angular.module('passmanApp')
|
||||||
|
|
||||||
$scope.loadSharedCredential = function () {
|
$scope.loadSharedCredential = function () {
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
ShareService.getPublicSharedCredential().then(function (sharedCredential) {
|
var guid = $window.location.hash.replace('#','');
|
||||||
//Decrypt stuff here
|
ShareService.getPublicSharedCredential(guid).then(function (sharedCredential) {
|
||||||
|
|
||||||
//And then set it
|
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.shared_credential = example_shared_credential;
|
console.log(sharedCredential)
|
||||||
|
if(sharedCredential.status === 200){
|
||||||
|
$scope.shared_credential = example_shared_credential;
|
||||||
|
} else {
|
||||||
|
$scope.expired = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, function(error){
|
||||||
|
return false;
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ angular.module('passmanApp')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
shareWithUser: function (credential, target_user_data){
|
shareWithUser: function (credential, target_user_data) {
|
||||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/share');
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/share');
|
||||||
return $http.post(queryUrl,
|
return $http.post(queryUrl,
|
||||||
{
|
{
|
||||||
|
@ -37,10 +37,10 @@ angular.module('passmanApp')
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getVaultsByUser: function (userId) {
|
getVaultsByUser: function (userId) {
|
||||||
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++){
|
for (var i = 0; i < response.data.length; i++) {
|
||||||
response.data[i].public_sharing_key = forge.pki.publicKeyFromPem(response.data[i].public_sharing_key);
|
response.data[i].public_sharing_key = forge.pki.publicKeyFromPem(response.data[i].public_sharing_key);
|
||||||
}
|
}
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -52,7 +52,7 @@ angular.module('passmanApp')
|
||||||
getPendingRequests: function () {
|
getPendingRequests: function () {
|
||||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/pending');
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/pending');
|
||||||
return $http.get(queryUrl).then(function (response) {
|
return $http.get(queryUrl).then(function (response) {
|
||||||
if(response.data){
|
if (response.data) {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -68,34 +68,37 @@ angular.module('passmanApp')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
unshareCredential: function (credential) {
|
unshareCredential: function (credential) {
|
||||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/unshare/'+ credential.guid);
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/unshare/' + credential.guid);
|
||||||
return $http.delete(queryUrl).then(function (response) {
|
return $http.delete(queryUrl).then(function (response) {
|
||||||
return response.data;
|
return response.data;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getPublicSharedCredential: function (credential_guid) {
|
getPublicSharedCredential: function (credential_guid) {
|
||||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/credential/'+ credential_guid);
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/credential/' + credential_guid);
|
||||||
|
return $http.get(queryUrl).then(function (response) {
|
||||||
|
if (response.data) {
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (result) {
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getCredendialsSharedWithUs: function (vault_guid) {
|
||||||
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/vault/' + vault_guid + '/get');
|
||||||
return $http.get(queryUrl).then(function (response) {
|
return $http.get(queryUrl).then(function (response) {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
return response.data;
|
return response.data;
|
||||||
} else {
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getCredendialsSharedWithUs: function (vault_guid) {
|
encryptSharedCredential: function (credential, sharedKey) {
|
||||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/vault/'+ vault_guid +'/get');
|
|
||||||
return $http.get(queryUrl).then(function (response) {
|
|
||||||
if(response.data){
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
encryptSharedCredential: function(credential, sharedKey){
|
|
||||||
var _credential = angular.copy(credential);
|
var _credential = angular.copy(credential);
|
||||||
_credential.shared_key = EncryptService.encryptString(sharedKey);
|
_credential.shared_key = EncryptService.encryptString(sharedKey);
|
||||||
var encrypted_fields = CredentialService.getEncryptedFields();
|
var encrypted_fields = CredentialService.getEncryptedFields();
|
||||||
for(var i = 0; i < encrypted_fields.length; i++){
|
for (var i = 0; i < encrypted_fields.length; i++) {
|
||||||
var field = encrypted_fields[i];
|
var field = encrypted_fields[i];
|
||||||
var fieldValue = angular.copy(credential[field]);
|
var fieldValue = angular.copy(credential[field]);
|
||||||
_credential[field] = EncryptService.encryptString(JSON.stringify(fieldValue), sharedKey);
|
_credential[field] = EncryptService.encryptString(JSON.stringify(fieldValue), sharedKey);
|
||||||
|
@ -108,7 +111,7 @@ angular.module('passmanApp')
|
||||||
for (var i = 0; i < encrypted_fields.length; i++) {
|
for (var i = 0; i < encrypted_fields.length; i++) {
|
||||||
var field = encrypted_fields[i];
|
var field = encrypted_fields[i];
|
||||||
var fieldValue = angular.copy(_credential[field]);
|
var fieldValue = angular.copy(_credential[field]);
|
||||||
if(_credential.hasOwnProperty(field)) {
|
if (_credential.hasOwnProperty(field)) {
|
||||||
try {
|
try {
|
||||||
var field_decrypted_value = EncryptService.decryptString(fieldValue, sharedKey);
|
var field_decrypted_value = EncryptService.decryptString(fieldValue, sharedKey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -126,12 +129,12 @@ angular.module('passmanApp')
|
||||||
return _credential;
|
return _credential;
|
||||||
},
|
},
|
||||||
|
|
||||||
generateRSAKeys: function(key_length, progress, callback){
|
generateRSAKeys: function (key_length, progress, callback) {
|
||||||
var p = new C_Promise(function(){
|
var p = new C_Promise(function () {
|
||||||
var state = forge.pki.rsa.createKeyPairGenerationState(key_length, 0x10001);
|
var state = forge.pki.rsa.createKeyPairGenerationState(key_length, 0x10001);
|
||||||
var step = function() {
|
var step = function () {
|
||||||
// run for 100 ms
|
// run for 100 ms
|
||||||
if(!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) {
|
if (!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) {
|
||||||
// console.log(state);
|
// console.log(state);
|
||||||
if (state.p !== null) {
|
if (state.p !== null) {
|
||||||
// progress(50);
|
// progress(50);
|
||||||
|
@ -152,46 +155,46 @@ angular.module('passmanApp')
|
||||||
});
|
});
|
||||||
return p;
|
return p;
|
||||||
},
|
},
|
||||||
generateSharedKey: function(size){
|
generateSharedKey: function (size) {
|
||||||
size = size || 20;
|
size = size || 20;
|
||||||
return new C_Promise(function(){
|
return new C_Promise(function () {
|
||||||
var t = this;
|
var t = this;
|
||||||
CRYPTO.PASSWORD.generate(size,
|
CRYPTO.PASSWORD.generate(size,
|
||||||
function(pass) {
|
function (pass) {
|
||||||
t.call_then(pass);
|
t.call_then(pass);
|
||||||
},
|
},
|
||||||
function(progress) {
|
function (progress) {
|
||||||
t.call_progress(progress);
|
t.call_progress(progress);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
rsaKeyPairToPEM: function(keypair){
|
rsaKeyPairToPEM: function (keypair) {
|
||||||
return {
|
return {
|
||||||
'publicKey' : forge.pki.publicKeyToPem(keypair.publicKey),
|
'publicKey': forge.pki.publicKeyToPem(keypair.publicKey),
|
||||||
'privateKey' : forge.pki.privateKeyToPem(keypair.privateKey)
|
'privateKey': forge.pki.privateKeyToPem(keypair.privateKey)
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getSharingKeys: function(){
|
getSharingKeys: function () {
|
||||||
var vault = VaultService.getActiveVault();
|
var vault = VaultService.getActiveVault();
|
||||||
return{
|
return {
|
||||||
'private_sharing_key': EncryptService.decryptString(angular.copy(vault.private_sharing_key)),
|
'private_sharing_key': EncryptService.decryptString(angular.copy(vault.private_sharing_key)),
|
||||||
'public_sharing_key': vault.public_sharing_key
|
'public_sharing_key': vault.public_sharing_key
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
rsaPrivateKeyFromPEM: function(private_pem) {
|
rsaPrivateKeyFromPEM: function (private_pem) {
|
||||||
return forge.pki.privateKeyFromPem(private_pem);
|
return forge.pki.privateKeyFromPem(private_pem);
|
||||||
},
|
},
|
||||||
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
|
* Cyphers an array of string in a non-blocking way
|
||||||
* @param vaults[] An array of vaults with the processed public keys
|
* @param vaults[] An array of vaults with the processed public keys
|
||||||
* @param string The string to cypher
|
* @param string The string to cypher
|
||||||
*/
|
*/
|
||||||
cypherRSAStringWithPublicKeyBulkAsync: function(vaults, string){
|
cypherRSAStringWithPublicKeyBulkAsync: function (vaults, string) {
|
||||||
var workload = function(){
|
var workload = function () {
|
||||||
if (this.current_index < this.vaults.length > 0 && this.vaults.length > 0) {
|
if (this.current_index < this.vaults.length > 0 && this.vaults.length > 0) {
|
||||||
var _vault = angular.copy(this.vaults[this.current_index]);
|
var _vault = angular.copy(this.vaults[this.current_index]);
|
||||||
_vault.key = forge.util.encode64(
|
_vault.key = forge.util.encode64(
|
||||||
|
@ -205,11 +208,11 @@ angular.module('passmanApp')
|
||||||
this.call_progress(this.current_index);
|
this.call_progress(this.current_index);
|
||||||
setTimeout(workload.bind(this), 1);
|
setTimeout(workload.bind(this), 1);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
this.call_then(this.data);
|
this.call_then(this.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return new C_Promise(function(){
|
return new C_Promise(function () {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
this.vaults = vaults;
|
this.vaults = vaults;
|
||||||
this.string = string;
|
this.string = string;
|
||||||
|
|
|
@ -64,7 +64,7 @@ style('passman', 'public-page');
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-8 col-xs-push-2 col-xs-pull-2 credential_container">
|
<div class="col-xs-8 col-xs-push-2 col-xs-pull-2 credential_container">
|
||||||
<h2>Passman</h2>
|
<h2>Passman</h2>
|
||||||
<div ng-if="!shared_credential">
|
<div ng-if="!shared_credential && !expired">
|
||||||
<span class="text">{name} has shared a credential with you.</span>
|
<span class="text">{name} has shared a credential with you.</span>
|
||||||
<button class="button-geen" ng-if="!loading"
|
<button class="button-geen" ng-if="!loading"
|
||||||
ng-click="loadSharedCredential()">Click here to request
|
ng-click="loadSharedCredential()">Click here to request
|
||||||
|
@ -74,6 +74,9 @@ style('passman', 'public-page');
|
||||||
class="fa fa-spinner fa-spin"></i>Loading...
|
class="fa fa-spinner fa-spin"></i>Loading...
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div ng-if="expired">
|
||||||
|
Awwhh.... this credential is expired :(.
|
||||||
|
</div>
|
||||||
<div ng-if="shared_credential">
|
<div ng-if="shared_credential">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr ng-show="shared_credential.label">
|
<tr ng-show="shared_credential.label">
|
||||||
|
|
Loading…
Reference in a new issue