Commit 9b51aecb authored by Sascha Pfeiffer's avatar Sascha Pfeiffer

added Decrypt Message Button to GPG entries

Signed-off-by: default avatarSascha Pfeiffer <sascha.pfeiffer@psono.com>
parent 4dc3dd76
......@@ -170,6 +170,7 @@ var build = function(build_path, type) {
"src/common/data/js/controller/modal/PickUserCtrl.js",
"src/common/data/js/controller/modal/EditGroupCtrl.js",
"src/common/data/js/controller/modal/EncryptMessageGPGCtrl.js",
"src/common/data/js/controller/modal/DecryptMessageGPGCtrl.js",
"src/common/data/js/controller/modal/EditGPGUserCtrl.js",
"src/common/data/js/controller/modal/GenerateNewMailGPGKeyCtrl.js",
"src/common/data/js/controller/modal/ImportMailGPGKeyAsTextCtrl.js",
......
......@@ -170,6 +170,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -97,6 +97,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -388,6 +388,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -170,6 +170,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -463,6 +463,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -159,7 +159,7 @@
remove_receiver(receiver['email'])
}
}, function(error) {
remove_receiver(receiver['email'])
remove_receiver(receiver['email']);
console.log(error);
});
}
......@@ -169,7 +169,7 @@
if ($scope.data.receiver[i]['status'] !== 'not searched') {
continue;
}
if (hkp_search) {
if (hkp_search && $scope.data.receiver[i]['email'] && $scope.data.receiver[i]['email'].length) {
lookup_from_hkp($scope.data.receiver[i]);
} else {
remove_receiver($scope.data.receiver[i]['email'])
......
(function(angular) {
'use strict';
/**
* @ngdoc controller
* @name psonocli.controller:ModalDecryptMessageGPGCtrl
* @requires $scope
* @requires $uibModalInstance
* @requires $routeParams
* @requires $uibModal
* @requires psonocli.cryptoLibrary
* @requires psonocli.managerDatastorePassword
* @requires psonocli.settings
*
* @description
* Controller for the Group view
*/
angular.module('psonocli').controller('ModalDecryptMessageGPGCtrl', ["$scope", "$uibModalInstance", "$timeout", "$routeParams", "$uibModal", "cryptoLibrary", "managerDatastorePassword", "settings",
function ($scope, $uibModalInstance, $timeout, $routeParams, $uibModal, cryptoLibrary, managerDatastorePassword, settings) {
$scope.decrypt = decrypt;
$scope.cancel = cancel;
$scope.data = {
decrypting: false,
message: '',
sender: ''
};
$scope.errors = [];
activate();
function activate() {
}
/**
* @ngdoc
* @name psonocli.controller:ModalDecryptMessageGPGCtrl#decrypt
* @methodOf psonocli.controller:ModalDecryptMessageGPGCtrl
*
* @description
* Triggered once someone clicks the "Decrypt" button
*/
function decrypt() {
$scope.errors = [];
$scope.data['decrypting'] = true;
if (!$scope.data.message) {
$scope.errors = ['You have to provide an encrypted message'];
$scope.data['decrypting'] = false;
return;
}
var pgp_sender = [];
function decrypt(public_key) {
return managerDatastorePassword.get_all_own_pgp_keys().then(function(private_keys) {
var private_key_string = private_keys.join("\n");
//console.log(pgp_sender);
if (public_key) {
options = {
message: openpgp.message.readArmored($scope.data.message), // parse armored message
publicKeys: openpgp.key.readArmored(public_key).keys,
privateKeys: openpgp.key.readArmored(private_key_string).keys
};
} else {
options = {
message: openpgp.message.readArmored($scope.data.message), // parse armored message
privateKeys: openpgp.key.readArmored(private_key_string).keys
};
}
openpgp.decrypt(options).then(function(plaintext) {
$scope.$evalAsync(function() {
$scope.data.decrypted_message = plaintext.data;
$scope.data.decrypting_complete = true;
$scope.data.decrypting = false;
});
}, function(error) {
$scope.$evalAsync(function() {
console.log(error);
$scope.errors.push(error.message);
$scope.data.decrypting = false;
});
});
});
}
var gpg_hkp_search = new openpgp.HKP(settings.get_setting('gpg_hkp_search'));
if (gpg_hkp_search && pgp_sender && pgp_sender.length) {
var hkp = new openpgp.HKP(settings.get_setting('gpg_hkp_key_server'));
var options = {
query: pgp_sender
};
hkp.lookup(options).then(function(public_key) {
decrypt(public_key);
}, function(error) {
console.log(error);
console.log(error.message);
decrypt();
});
} else {
decrypt();
}
}
/**
* @ngdoc
* @name psonocli.controller:ModalDecryptMessageGPGCtrl#cancel
* @methodOf psonocli.controller:ModalDecryptMessageGPGCtrl
*
* @description
* Triggered once someone clicks the close button in the modal
*/
function cancel() {
$uibModalInstance.dismiss('close');
}
}]);
}(angular));
\ No newline at end of file
......@@ -160,7 +160,8 @@
{ name: "mail_gpg_own_key_publish", field: "input", type:"checkbox", title: "Publish Public Key", hidden: true},
{ name: "mail_gpg_own_key_generate_new", field: "button", type: "button", title: "Generate New", hidden: true, class: 'btn-primary', onClick:"onClickGenerateNewButton" },
{ name: "mail_gpg_own_key_generate_import_text", field: "button", type: "button", title: "Import (as text)", hidden: true, class: 'btn-primary', onClick:"onClickImportAsTextButton" },
{ name: "mail_gpg_own_key_encrypt_message", field: "button", type: "button", title: "Encrypt Message", hidden: true, class: 'btn-default', onClick:"onClickEncryptMessageButton" }
{ name: "mail_gpg_own_key_encrypt_message", field: "button", type: "button", title: "Encrypt Message", hidden: true, class: 'btn-default', onClick:"onClickEncryptMessageButton" },
{ name: "mail_gpg_own_key_decrypt_message", field: "button", type: "button", title: "Decrypt Message", hidden: true, class: 'btn-default', onClick:"onClickDecryptMessageButton" }
],
/**
* triggered whenever the "Generate New" button is clicked.
......@@ -271,8 +272,8 @@
},
/**
* triggered whenever the "Import (as text)" button is clicked.
* Will open a new modal so the user can copy paste his keys, and once the modal closes show the details for this entry.
* triggered whenever the "Encrypt Message" button is clicked.
* Will open a new modal where the user can encrypt a message for specific receivers.
*
* @param node
* @param fields
......@@ -298,9 +299,45 @@
// cancel triggered
});
},
/**
* triggered whenever the "Decrypt Message" button is clicked.
* Will open a new modal where the user can decrypt a message.
*
* @param node
* @param fields
* @param errors
* @param form_control
* @param selected_server_domain
*/
onClickDecryptMessageButton: function(node, fields, errors, form_control, selected_server_domain){
var modalInstance = $uibModal.open({
templateUrl: 'view/modal-decrypt-message-gpg.html',
controller: 'ModalDecryptMessageGPGCtrl',
backdrop: 'static',
resolve: {
secret_id: function() {
return node.secret_id;
}
}
});
modalInstance.result.then(function (data) {
// pass
}, function () {
// cancel triggered
});
},
onEditModalOpen: function(node) {
var showInEditOnly = ["mail_gpg_own_key_title", "mail_gpg_own_key_email", "mail_gpg_own_key_name", "mail_gpg_own_key_public", "mail_gpg_own_key_encrypt_message"];
var showInEditOnly = [
"mail_gpg_own_key_title",
"mail_gpg_own_key_email",
"mail_gpg_own_key_name",
"mail_gpg_own_key_public",
"mail_gpg_own_key_encrypt_message",
"mail_gpg_own_key_decrypt_message"
];
for (var i = 0; i < node.fields.length; i++) {
node.fields[i].hidden = !(showInEditOnly.indexOf(node.fields[i].name) > -1);
}
......
......@@ -557,11 +557,6 @@
var private_key_string = private_keys.join("\n");
console.log(pgp_message);
console.log(pgp_sender);
console.log(public_key);
console.log(private_key_string);
if (public_key) {
options = {
message: openpgp.message.readArmored(pgp_message), // parse armored message
......@@ -576,8 +571,6 @@
}
openpgp.decrypt(options).then(function(plaintext) {
console.log(plaintext);
return sendResponse({
public_key: public_key,
sender: pgp_sender,
......@@ -594,7 +587,9 @@
});
}
if (pgp_sender) {
var gpg_hkp_search = new openpgp.HKP(settings.get_setting('gpg_hkp_search'));
if (gpg_hkp_search && pgp_sender && pgp_sender.length) {
var hkp = new openpgp.HKP(settings.get_setting('gpg_hkp_key_server'));
var options = {
......
......@@ -234,6 +234,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -144,6 +144,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -362,6 +362,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -137,6 +137,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
......@@ -194,6 +194,7 @@
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGPGUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GenerateNewMailGPGKeyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/ImportMailGPGKeyAsTextCtrl.js" type="application/javascript"></script>
......
<form name="modalDecryptMessageGPGForm" novalidate>
<div class="modal-header">
<button type="button" class="close" ng-click="cancel()"><span aria-hidden="true">&times;</span></button>
<h3 class="modal-title">Decrypt Message</h3>
</div>
<div class="modal-body" ng-if="!data.decrypting && !data.decrypting_complete">
<div class="form-group">
<label>Encrypted Message:</label>
<textarea class="form-control"
placeholder="Your Message"
ng-model="data.message"></textarea>
</div>
<div class="form-group alert alert-danger" ng-repeat="e in errors">
<strong>Error:</strong> {{e}}
</div>
<div class="form-group">
<button ng-click="decrypt()" type="submit-" class="btn btn-primary">Decrypt</button>
</div>
</div>
<div class="modal-body" ng-if="data.decrypting && !data.decrypting_complete">
<div>
<div class="big-font-icon-and-msg">
<i style="
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
text-rendering: auto;
font-size: 3em;
text-align: center;
animation: fa-spin 2s infinite linear;
vertical-align: middle;">&#xf110;</i>
Decrypting
</div>
</div>
</div>
<div class="modal-body" ng-if="data.decrypting_complete">
<div class="form-group">
<label>Decrypted Message:</label>
<div class="yui3-cssreset">
<!-- message contains potentially dangerous html content, so we are using angularjs sanitizer -->
<div ng-if="data.decrypted_message" ng-bind-html="data.decrypted_message"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn" type="button" ng-click="cancel();">Close</button>
</div>
</form>
\ No newline at end of file
......@@ -72,6 +72,7 @@
"../src/common/data/js/controller/modal/PickUserCtrl.js",
"../src/common/data/js/controller/modal/EditGroupCtrl.js",
"../src/common/data/js/controller/modal/EncryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/DecryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/EditGPGUserCtrl.js",
"../src/common/data/js/controller/modal/GenerateNewMailGPGKeyCtrl.js",
"../src/common/data/js/controller/modal/ImportMailGPGKeyAsTextCtrl.js",
......
......@@ -76,6 +76,7 @@
"../src/common/data/js/controller/modal/PickUserCtrl.js",
"../src/common/data/js/controller/modal/EditGroupCtrl.js",
"../src/common/data/js/controller/modal/EncryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/DecryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/EditGPGUserCtrl.js",
"../src/common/data/js/controller/modal/GenerateNewMailGPGKeyCtrl.js",
"../src/common/data/js/controller/modal/ImportMailGPGKeyAsTextCtrl.js",
......
......@@ -72,6 +72,7 @@
"../src/common/data/js/controller/modal/PickUserCtrl.js",
"../src/common/data/js/controller/modal/EditGroupCtrl.js",
"../src/common/data/js/controller/modal/EncryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/DecryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/EditGPGUserCtrl.js",
"../src/common/data/js/controller/modal/GenerateNewMailGPGKeyCtrl.js",
"../src/common/data/js/controller/modal/ImportMailGPGKeyAsTextCtrl.js",
......
......@@ -72,6 +72,7 @@
"../src/common/data/js/controller/modal/PickUserCtrl.js",
"../src/common/data/js/controller/modal/EditGroupCtrl.js",
"../src/common/data/js/controller/modal/EncryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/DecryptMessageGPGCtrl.js",
"../src/common/data/js/controller/modal/EditGPGUserCtrl.js",
"../src/common/data/js/controller/modal/GenerateNewMailGPGKeyCtrl.js",
"../src/common/data/js/controller/modal/ImportMailGPGKeyAsTextCtrl.js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment