[Libreoffice-commits] online.git: kit/ChildSession.cpp loleaflet/js loleaflet/src

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 30 10:29:52 UTC 2018


 kit/ChildSession.cpp                  |   31 ++++++++++++
 loleaflet/js/toolbar.js               |    3 +
 loleaflet/src/control/Signing.js      |   85 ++++++++++++++++++++++++++++++++--
 loleaflet/src/layer/tile/TileLayer.js |   32 ------------
 4 files changed, 114 insertions(+), 37 deletions(-)

New commits:
commit e82c2180d1176a75d3deadc43597591c94f0bbdb
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Nov 30 11:24:55 2018 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Nov 30 11:29:34 2018 +0100

    Show and check document status when log in into vereign
    
    This shows what the current document status is in the signing
    infobar.
    
    When logging in into vereign we need to check the current document
    as we have all the needed certificates avaliable.
    
    Change-Id: I7fb4420d0b80a6d0fa553fca2f0be7b6dec6249f
    Reviewed-on: https://gerrit.libreoffice.org/64333
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 856940c96..d30bfb5a9 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -1404,10 +1404,39 @@ bool ChildSession::signDocumentContent(const char* buffer, int length, const std
     return bResult;
 }
 
-bool ChildSession::askSignatureStatus(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& /*tokens*/)
+bool ChildSession::askSignatureStatus(const char* buffer, int length, const std::vector<std::string>& /*tokens*/)
 {
     std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
 
+    bool bResult = true;
+
+    const std::string firstLine = getFirstLine(buffer, length);
+    const char* data = buffer + firstLine.size() + 1;
+    const int size = length - firstLine.size() - 1;
+    std::string json(data, size);
+
+    Poco::JSON::Parser parser;
+    Poco::JSON::Object::Ptr root = parser.parse(json).extract<Poco::JSON::Object::Ptr>();
+
+    if (root)
+    {
+        for (auto& rChainPtr : *root->getArray("certificates"))
+        {
+            if (!rChainPtr.isString())
+                return false;
+
+            std::string chainCertificate = rChainPtr;
+            std::vector<unsigned char> binaryChainCertificate = decodeBase64(extractCertificate(chainCertificate));
+
+            bResult = getLOKitDocument()->addCertificate(
+                binaryChainCertificate.data(),
+                binaryChainCertificate.size());
+
+            if (!bResult)
+                return false;
+        }
+    }
+
     int nStatus = getLOKitDocument()->getSignatureState();
 
     sendTextFrame("signaturestatus: " + std::to_string(nStatus));
diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js
index 9485d77cc..d3fce4866 100644
--- a/loleaflet/js/toolbar.js
+++ b/loleaflet/js/toolbar.js
@@ -952,6 +952,9 @@ function initNormalToolbar(toolItems) {
 				{type: 'break' },
 				{type: 'menu', id: 'passport', caption: _('Select passport'), items: []},
 				{type: 'html', id: 'current-passport', html: 'Passport: N/A'},
+				{type: 'break' },
+				{type: 'html', id: 'current-document-status-label', html: '<p><b>Status:</b></p>'},
+				{type: 'html', id: 'current-document-status', html: 'N/A'},
 				{type: 'spacer'},
 				{type: 'button',  id: 'logout',  caption: 'Logout', img: '', hint: _('Logout')},
 				{type: 'button',  id: 'login',  caption: 'Login', img: '', hint: _('Login')},
diff --git a/loleaflet/src/control/Signing.js b/loleaflet/src/control/Signing.js
index fcfcd970b..2181e22ee 100644
--- a/loleaflet/src/control/Signing.js
+++ b/loleaflet/src/control/Signing.js
@@ -3,13 +3,16 @@
  * Document Signing
  */
 
-/* global window setupViamAPI w2ui vex $ */
+/* global window setupViamAPI w2ui vex Promise $ */
 
 var library = null;
 var identity = null;
 var currentPassport = null;
+var passportCertificates = [];
 
 var oldtoolbarSize = null;
+var _map = null;
+var currentDocumentSigningStatus = 'N/A'
 
 function isSuccess(result) {
 	return result.code == '200';
@@ -48,6 +51,30 @@ function addPassportToToolbar(passport, i) {
 	w2ui['document-signing-bar'].get('passport').items.push(
 		{ text: name, id: 'item ' + (i+1), value: passport.uuid }
 	);
+
+	var promise = library.getCertificateByPassport(passport.uuid);
+	promise = promise.then(function(result) {
+		if (isSuccess(result)) {
+			var chain = result.data.chain;
+			for (var i = 0; i < chain.length; i++) {
+				if (passportCertificates.indexOf(chain[i]) == -1) {
+					passportCertificates.push(chain[i]);
+				}
+			}
+			passportCertificates.push(result.data.x509Certificate);
+		}
+	});
+	return promise;
+}
+
+function checkCurrentDocument() {
+	var certificates = {
+		certificates: passportCertificates
+	};
+	var blob = new Blob(['asksignaturestatus\n', JSON.stringify(certificates)]);
+	if (_map) {
+		_map._socket.sendMessage(blob);
+	}
 }
 
 function updatePassportList() {
@@ -55,13 +82,19 @@ function updatePassportList() {
 		library.passportListPassports().then(function(result) {
 			if (isSuccess(result))
 			{
+				passportCertificates = [];
 				w2ui['document-signing-bar'].get('passport').items = [];
 				var passports = result.data;
+				var promises = [];
 				for (var i = 0; i < passports.length; i++) {
-					addPassportToToolbar(passports[i], i);
+					promises.push(addPassportToToolbar(passports[i], i));
 				}
-				updateCurrentPassport();
-				adjustUIState();
+				// wait for all promises to complete
+				Promise.all(promises).then(function() {
+					updateCurrentPassport();
+					checkCurrentDocument();
+					adjustUIState();
+				});
 			}
 		});
 	}
@@ -109,6 +142,9 @@ function adjustUIState() {
 		w2ui['document-signing-bar'].hide('passport');
 		w2ui['document-signing-bar'].hide('current-passport');
 	}
+
+	w2ui['document-signing-bar'].get('current-document-status').html = '<p>' + currentDocumentSigningStatus + '</p>';
+
 	w2ui['document-signing-bar'].refresh();
 }
 
@@ -251,6 +287,7 @@ L.Map.include({
 						var otp = result.data;
 						var blob = new Blob(['signdocument\n', JSON.stringify(otp)]);
 						map._socket.sendMessage(blob);
+						checkCurrentDocument();
 					}
 				});
 			}
@@ -351,7 +388,7 @@ L.Map.include({
 		var vereignURL = window.documentSigningURL == null ? '' : window.documentSigningURL;
 		if (vereignURL.length == 0)
 			return;
-
+		_map = this;
 		setupViamAPI(
 			'signdocument-iframe-content',
 			{
@@ -405,5 +442,43 @@ L.Map.include({
 			this.setCurrentPassport(item.value, item.text);
 		}
 		return false;
+	},
+	onChangeSignStatus: function(signstatus) {
+		var statusText = '';
+		switch (signstatus) {
+		case '0':
+			currentDocumentSigningStatus = 'Not Signed';
+			break;
+		case '1':
+			statusText = 'Document signed and validated.';
+			currentDocumentSigningStatus = 'Signed and validated';
+			break;
+		case '2':
+			statusText = 'Document signed but signatue is broken.';
+			currentDocumentSigningStatus = 'Signature broken';
+			break;
+		case '3':
+			statusText = 'Document signed but the document is already modified.';
+			currentDocumentSigningStatus = 'Signed but document modified';
+			break;
+		case '4':
+			statusText = 'Document signed but can not be validated.';
+			currentDocumentSigningStatus = 'Signed but not validated';
+			break;
+		case '5':
+			statusText = 'Document signed but not all files are signed.';
+			currentDocumentSigningStatus = 'Signed but not all files are signed';
+			break;
+		}
+
+		if (statusText) {
+			this.fire('infobar', {
+				msg: statusText,
+				action: null,
+				actionLabel: null
+			});
+		}
+
+		adjustUIState();
 	}
 });
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index f543be0f7..182f553a6 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -484,37 +484,7 @@ L.TileLayer = L.GridLayer.extend({
 		}
 		else if (textMsg.startsWith('signaturestatus:')) {
 			var signstatus = textMsg.substring('signaturestatus:'.length + 1);
-
-			if (signstatus == '1') {
-				this._map.fire('infobar',
-					{
-						msg: 'Document signed and validated.', action: null, actionLabel: null
-					});
-			}
-			else if (signstatus == '2') {
-				this._map.fire('infobar',
-					{
-						msg: 'Document signed but signatue is broken.', action: null, actionLabel: null
-					});
-			}
-			else if (signstatus == '3') {
-				this._map.fire('infobar',
-					{
-						msg: 'Document signed but the document is already modified.', action: null, actionLabel: null
-					});
-			}
-			else if (signstatus == '4') {
-				this._map.fire('infobar',
-					{
-						msg: 'Document signed but can not be validated.', action: null, actionLabel: null
-					});
-			}
-			else if (signstatus == '5') {
-				this._map.fire('infobar',
-					{
-						msg: 'Document signed but not all files are signed.', action: null, actionLabel: null
-					});
-			}
+			this._map.onChangeSignStatus(signstatus);
 		}
 	},
 


More information about the Libreoffice-commits mailing list