Multiple fixes to Vereign siging code

- unify signing sttaus messages
- extract new identity creation (verignNewIdentity) to a new func.
- handle 'IdentityNotLoaded' event
- remove unneded calls on 'Authenticated' event
-

Change-Id: Ib70e1893f966adb29e8de4e396c08260021755e1
Reviewed-on: https://gerrit.libreoffice.org/65786
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl 2019-01-01 22:10:28 +01:00 committed by Tomaž Vajngerl
parent 8ddfbead3c
commit 35986764eb

View file

@ -51,18 +51,16 @@ function getCurrentDocumentFilename(documentType) {
} }
function updateIndentity() { function updateIndentity() {
if (library) { if (library && identity) {
if (identity) { library.getIdentityProfile(identity.authentication.publicKey).then(function(result) {
library.getIdentityProfile(identity.authentication.publicKey).then(function(result) { var initials = result.data.initials;
var initials = result.data.initials; w2ui['document-signing-bar'].get('identity').html = '<p>' + initials + '</p>';
w2ui['document-signing-bar'].get('identity').html = '<p>' + initials + '</p>';
w2ui['document-signing-bar'].refresh();
});
}
else {
w2ui['document-signing-bar'].get('identity').html = '';
w2ui['document-signing-bar'].refresh(); w2ui['document-signing-bar'].refresh();
} });
}
else {
w2ui['document-signing-bar'].get('identity').html = '';
w2ui['document-signing-bar'].refresh();
} }
} }
@ -174,7 +172,6 @@ function adjustUIState() {
} }
w2ui['document-signing-bar'].get('current-document-status').html = '<p>' + currentDocumentSigningStatus + '</p>'; w2ui['document-signing-bar'].get('current-document-status').html = '<p>' + currentDocumentSigningStatus + '</p>';
w2ui['document-signing-bar'].refresh(); w2ui['document-signing-bar'].refresh();
} }
@ -183,19 +180,16 @@ function vereignPinCodeDialog(selectedIdentityKey) {
message: _('PIN Code'), message: _('PIN Code'),
input: '<input name="pincode" type="password" value="" required />', input: '<input name="pincode" type="password" value="" required />',
callback: function(data) { callback: function(data) {
console.log(data.pincode); if (data.pincode != null && data.pincode != '' && library) {
if (data.pincode) { return library.loadIdentity(selectedIdentityKey, data.pincode).then(function(result) {
if (library) { if (isSuccess(result)) {
return library.loadIdentity(selectedIdentityKey, data.pincode).then(function(result) { identity = result.data;
if (isSuccess(result)) { vereignLogin();
identity = result.data; }
vereignLogin(); else {
} identity = null;
else { }
identity = null; });
}
});
}
} }
} }
}); });
@ -203,36 +197,47 @@ function vereignPinCodeDialog(selectedIdentityKey) {
function vereignLogin() { function vereignLogin() {
if (library && identity) { if (library && identity) {
library.login(identity, 'previousaddeddevice').then(function(result) { library.login(identity, 'previousaddeddevice', '', '').then(function(result) {
console.log(result);
if (isSuccess(result)) { if (isSuccess(result)) {
updateIndentity(); console.log(result);
updatePassportList();
adjustUIState();
} }
updateIndentity();
updatePassportList();
adjustUIState();
}); });
} }
} }
function verignNewIdentity(newIdentity) {
library.login(newIdentity, 'newdevice', '', '').then(function(result) {
if (isSuccess(result)) {
vex.open({
content: '<div id="image-container"></div>',
showCloseButton: true,
escapeButtonCloses: true,
overlayClosesOnClick: true,
buttons: {},
afterOpen: function($vexContent) {
var container = $vexContent.find('#image-container');
var image = $('<img style="display: block; margin-left: auto; margin-right: auto"/>');
image.attr('src', result.data.image);
container.append(image);
}
});
}
else {
vex.dialog.alert(_('Couldn\'t get the QR code image.'));
console.log('Login Error: ' + result);
library.clearIdentities();
}
});
}
function verignQrDialog() { function verignQrDialog() {
if (library) { if (library) {
library.createIdentity('00000000').then(function(result) { library.createIdentity('00000000').then(function(result) {
if (isSuccess(result)) { if (isSuccess(result)) {
library.login(result.data, 'newdevice').then(function(result) { verignNewIdentity(result.data);
vex.open({
content: '<div id="image-container"></div>',
showCloseButton: true,
escapeButtonCloses: true,
overlayClosesOnClick: true,
buttons: {},
afterOpen: function($vexContent) {
var container = $vexContent.find('#image-container');
var image = $('<img style="display: block; margin-left: auto; margin-right: auto"/>');
image.attr('src', result.data.image);
container.append(image);
},
});
});
} }
}); });
} }
@ -283,8 +288,8 @@ function vereignRestoreIdentity() {
} }
library.getCurrentlyAuthenticatedIdentity().then(function(result) { library.getCurrentlyAuthenticatedIdentity().then(function(result) {
if (isSuccess(result)) { if (isSuccess(result)) {
vex.closeAll();
identity = result.data; identity = result.data;
vex.closeAll();
updateIndentity(); updateIndentity();
updatePassportList(); updatePassportList();
adjustUIState(); adjustUIState();
@ -480,17 +485,12 @@ L.Map.include({
case 'ActionConfirmedAndExecuted': case 'ActionConfirmedAndExecuted':
console.log('event ActionConfirmedAndExecuted'); console.log('event ActionConfirmedAndExecuted');
break; break;
case 'IdentityNotLoaded':
vereignPinCodeDialog(event.payloads[0]);
break;
case 'Authenticated': case 'Authenticated':
console.log('event Authenticated'); console.log('event Authenticated');
library.hasSession().then(function(result) { vereignRestoreIdentity();
if (isSuccess(result)) {
library.listIdentities().then(function(result) {
if (isSuccess(result)) {
vereignRestoreIdentity();
}
});
}
});
break; break;
case 'Logout': case 'Logout':
console.log('event Logout'); console.log('event Logout');
@ -518,7 +518,7 @@ L.Map.include({
currentPassport = { uuid: uuid, text: text }; currentPassport = { uuid: uuid, text: text };
updateCurrentPassport(); updateCurrentPassport();
library.passportGetAvatarByPassport(uuid).then(function(result) { library.passportGetAvatarByPassport(uuid).then(function(result) {
console.log(result); console.log(result); // TODO
}); });
adjustUIState(); adjustUIState();
} }
@ -550,23 +550,23 @@ L.Map.include({
currentDocumentSigningStatus = _('Not Signed'); currentDocumentSigningStatus = _('Not Signed');
break; break;
case '1': case '1':
statusText = _('Document signed and validated.'); statusText = _('This document is digitally signed and the signature is valid.');
currentDocumentSigningStatus = _('Signed and validated'); currentDocumentSigningStatus = _('Signed and validated');
break; break;
case '2': case '2':
statusText = _('Document signed but signature is broken.'); statusText = _('This document has an invalid signature.');
currentDocumentSigningStatus = _('Signature broken'); currentDocumentSigningStatus = _('Signature broken');
break; break;
case '3': case '3':
statusText = _('Document signed but the document is already modified.'); statusText = _('The signature was valid, but the document has been modified');
currentDocumentSigningStatus = _('Signed but document modified'); currentDocumentSigningStatus = _('Signed but document modified');
break; break;
case '4': case '4':
statusText = _('Document signed but can not be validated.'); statusText = _('The signature is OK, but the certificate could not be validated.');
currentDocumentSigningStatus = _('Signed but not validated'); currentDocumentSigningStatus = _('Signed but not validated');
break; break;
case '5': case '5':
statusText = _('Document signed but not all files are signed.'); statusText = _('The signature is OK, but the document is only partially signed');
currentDocumentSigningStatus = _('Signed but not all files are signed'); currentDocumentSigningStatus = _('Signed but not all files are signed');
break; break;
} }