From 541bb378ddece2eab135a8066a16994e94436dea Mon Sep 17 00:00:00 2001 From: Giulio Cesare Solaroli Date: Mon, 03 Oct 2011 16:04:12 +0000 Subject: Merge pull request #1 from gcsolaroli/master First version of the restructured repository --- (limited to 'frontend/gamma/js/Clipperz/PM/Proxy') diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.JSON.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.JSON.js new file mode 100755 index 0000000..65b46de --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.JSON.js @@ -0,0 +1,94 @@ +/* + +Copyright 2008-2011 Clipperz Srl + +This file is part of Clipperz's Javascript Crypto Library. +Javascript Crypto Library provides web developers with an extensive +and efficient set of cryptographic functions. The library aims to +obtain maximum execution speed while preserving modularity and +reusability. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library is free software: you can redistribute + it and/or modify it under the terms of the GNU Affero General Public + License as published by the Free Software Foundation, either version + 3 of the License, or (at your option) any later version. + +* Javascript Crypto Library is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the implied + warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + +* You should have received a copy of the GNU Affero General Public + License along with Javascript Crypto Library. If not, see + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } + +//============================================================================= + +Clipperz.PM.Proxy.JSON = function(args) { + Clipperz.PM.Proxy.JSON.superclass.constructor.call(this, args); + + this._url = args.url || Clipperz.Base.exception.raise('MandatoryParameter'); + + return this; +} + +Clipperz.Base.extend(Clipperz.PM.Proxy.JSON, Clipperz.PM.Proxy, { + + 'toString': function() { + return "Clipperz.PM.Proxy.JSON"; + }, + + //========================================================================= + + 'url': function () { + return this._url; + }, + + //========================================================================= + + 'sendMessage': function(aFunctionName, someParameters) { + var deferredResult; + var parameters; + + parameters = { + method: aFunctionName, +// version: someParameters['version'], +// message: someParameters['message'], + parameters: Clipperz.Base.serializeJSON(someParameters) + }; + + deferredResult = new Clipperz.Async.Deferred("Proxy.JSON.sendMessage", {trace:false}); + deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'remoteRequestSent'); + deferredResult.addCallback(MochiKit.Async.doXHR, this.url(), { + method:'POST', + sendContent:MochiKit.Base.queryString(parameters), + headers:{"Content-Type":"application/x-www-form-urlencoded"} + }); + deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'remoteRequestReceived'); +// deferredResult.addCallback(MochiKit.Async.evalJSONRequest); + deferredResult.addCallback(MochiKit.Base.itemgetter('responseText')); + deferredResult.addCallback(Clipperz.Base.evalJSON); + deferredResult.addCallback(function (someValues) { + if (someValues['result'] == 'EXCEPTION') { + throw someValues['message']; + } + + return someValues; + }) +// return MochiKit.Base.evalJSON(req.responseText); + deferredResult.callback(); + + return deferredResult; + }, + + //========================================================================= + __syntaxFix__: "syntax fix" + +}); diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js new file mode 100644 index 0000000..de8e7f6 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js @@ -0,0 +1,811 @@ +/* + +Copyright 2008-2011 Clipperz Srl + +This file is part of Clipperz's Javascript Crypto Library. +Javascript Crypto Library provides web developers with an extensive +and efficient set of cryptographic functions. The library aims to +obtain maximum execution speed while preserving modularity and +reusability. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library is free software: you can redistribute + it and/or modify it under the terms of the GNU Affero General Public + License as published by the Free Software Foundation, either version + 3 of the License, or (at your option) any later version. + +* Javascript Crypto Library is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the implied + warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + +* You should have received a copy of the GNU Affero General Public + License along with Javascript Crypto Library. If not, see + . + +*/ + +try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) { + throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!"; +} + +//============================================================================= + +Clipperz.PM.Proxy.Offline.DataStore = function(args) { + args = args || {}; + + this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); + this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); + this._shouldPayTolls = args.shouldPayTolls || false; + + this._tolls = {}; + this._currentStaticConnection = null; + + return this; +} + +Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { + + //------------------------------------------------------------------------- + + 'isReadOnly': function () { + return this._isReadOnly; + }, + + //------------------------------------------------------------------------- + + 'shouldPayTolls': function() { + return this._shouldPayTolls; + }, + + //------------------------------------------------------------------------- + + 'data': function () { + return this._data; + }, + + //------------------------------------------------------------------------- + + 'tolls': function () { + return this._tolls; + }, + + //========================================================================= + + 'resetData': function() { + this._data = { + 'users': { + 'catchAllUser': { + __masterkey_test_value__: 'masterkey', + s: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00', + v: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00' + } + } + }; + }, + + //------------------------------------------------------------------------- + + 'setupWithEncryptedData': function(someData) { + this._data = Clipperz.Base.deepClone(someData); + }, + + //------------------------------------------------------------------------- + + 'setupWithData': function(someData) { + var deferredResult; + var resultData; + var i, c; + +//Clipperz.log(">>> Proxy.Test.setupWithData"); + resultData = this._data; + + deferredResult = new Clipperz.Async.Deferred("Proxy.Test.seupWithData", {trace:false}); + c = someData['users'].length; + + for (i=0; i, received <" + someParameters.parameters.M1 + ">.", "Error"); + } + + nextTollRequestType = 'MESSAGE'; + } else if (someParameters.message == "oneTimePassword") { + var otpData; + + otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; + + try { + if (typeof(otpData) != 'undefined') { + if (otpData['status'] == 'ACTIVE') { + if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { + result = { + 'data': otpData['data'], + 'version': otpData['version'] + } + + otpData['status'] = 'REQUESTED'; + } else { + otpData['status'] = 'DISABLED'; + throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; + } + } else { + throw "The requested One Time Password was not active"; + } + } else { + throw "The requested One Time Password has not been found" + } + } catch (exception) { + result = { + 'data': Clipperz.PM.Crypto.randomKey(), + 'version': Clipperz.PM.Connection.communicationProtocol.currentVersion + } + } + nextTollRequestType = 'CONNECT'; + } else { + MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); + } + + result = { + result: result, + toll: this.getTollForRequestType(nextTollRequestType) + } + + return result; + }, + + //------------------------------------------------------------------------- + + '_message': function(aConnection, someParameters) { + var result; + + result = {}; + + //===================================================================== + // + // R E A D - O N L Y M e t h o d s + // + //===================================================================== + if (someParameters.message == 'getUserDetails') { + var recordsStats; + var recordReference; + + recordsStats = {}; + for (recordReference in aConnection['userData']['records']) { + recordsStats[recordReference] = { + 'updateDate': aConnection['userData']['records'][recordReference]['updateDate'] + } + } + + result['header'] = this.userDetails(aConnection); + result['statistics'] = this.statistics(aConnection); + result['maxNumberOfRecords'] = aConnection['userData']['maxNumberOfRecords']; + result['version'] = aConnection['userData']['userDetailsVersion']; + result['recordsStats'] = recordsStats; + + if (this.isReadOnly() == false) { + var lock; + + if (typeof(aConnection['userData']['lock']) == 'undefined') { + aConnection['userData']['lock'] = "<>"; + } + + result['lock'] = aConnection['userData']['lock']; + } + + //===================================================================== + } else if (someParameters.message == 'getRecordDetail') { +/* + var recordData; + var currentVersionData; + + recordData = this.userData()['records'][someParameters['parameters']['reference']]; + result['reference'] = someParameters['parameters']['reference']; + result['data'] = recordData['data']; + result['version'] = recordData['version']; + result['creationData'] = recordData['creationDate']; + result['updateDate'] = recordData['updateDate']; + result['accessDate'] = recordData['accessDate']; + + currentVersionData = recordData['versions'][recordData['currentVersion']]; + + result['currentVersion'] = {}; + result['currentVersion']['reference'] = recordData['currentVersion']; + result['currentVersion']['version'] = currentVersionData['version']; + result['currentVersion']['header'] = currentVersionData['header']; + result['currentVersion']['data'] = currentVersionData['data']; + result['currentVersion']['creationData'] = currentVersionData['creationDate']; + result['currentVersion']['updateDate'] = currentVersionData['updateDate']; + result['currentVersion']['accessDate'] = currentVersionData['accessDate']; + if (typeof(currentVersionData['previousVersion']) != 'undefined') { + result['currentVersion']['previousVersionKey'] = currentVersionData['previousVersionKey']; + result['currentVersion']['previousVersion'] = currentVersionData['previousVersion']; + } +*/ + MochiKit.Base.update(result, aConnection['userData']['records'][someParameters['parameters']['reference']]); + result['reference'] = someParameters['parameters']['reference']; + + //===================================================================== + // + // R E A D - W R I T E M e t h o d s + // + //===================================================================== + } else if (someParameters.message == 'upgradeUserCredentials') { + if (this.isReadOnly() == false) { + var parameters; + var credentials; + + parameters = someParameters['parameters']; + credentials = parameters['credentials']; + + if ((credentials['C'] == null) + || (credentials['s'] == null) + || (credentials['v'] == null) + || (credentials['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) + ) { + result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; + } else { + var oldCValue; + oldCValue = aConnection['C']; + + this.data()['users'][credentials['C']] = aConnection['userData']; + aConnection['C'] = credentials['C']; + + aConnection['userData']['s'] = credentials['s']; + aConnection['userData']['v'] = credentials['v']; + aConnection['userData']['version'] = credentials['version']; + + aConnection['userData']['userDetails'] = parameters['user']['header']; + aConnection['userData']['userDetailsVersion'] = parameters['user']['version']; + aConnection['userData']['statistics'] = parameters['user']['statistics']; + + aConnection['userData']['lock'] = parameters['user']['lock']; + + delete this.data()['users'][oldCValue]; + + result = {result:"done", parameters:parameters}; + } + } else { + throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; + } + //===================================================================== +/* } else if (someParameters.message == 'updateData') { + if (this.isReadOnly() == false) { + var i, c; + +//console.log("###==============================================================="); +//console.log("###>>>", Clipperz.Base.serializeJSON(someParameters)); +//console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData())); + if (this.userData()['lock'] != someParameters['parameters']['user']['lock']) { + throw "the lock attribute is not processed correctly" + } + + this.userData()['userDetails'] = someParameters['parameters']['user']['header']; + this.userData()['statistics'] = someParameters['parameters']['user']['statistics']; + this.userData()['userDetailsVersions'] = someParameters['parameters']['user']['version']; + + c = someParameters['parameters']['records'].length; + for (i=0; i>>", someParameters); +//console.log("###>>>", Clipperz.Base.serializeJSON(someParameters)); +//console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData())); +//console.log("###==============================================================="); +//console.log("--- userData.lock ", this.userData()['lock']); +//console.log("--- parameters.lock", someParameters['parameters']['user']['lock']); + if (aConnection['userData']['lock'] != someParameters['parameters']['user']['lock']) { + throw "the lock attribute is not processed correctly" + } + + aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; + aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; + aConnection['userData']['userDetailsVersions'] = someParameters['parameters']['user']['version']; + + c = someParameters['parameters']['records']['updated'].length; + for (i=0; i. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } + +//============================================================================= + +Clipperz.PM.Proxy.Offline = function(args) { + args = args || {}; + + Clipperz.PM.Proxy.Offline.superclass.constructor.call(this, args); + + this._dataStore = args.dataStore || new Clipperz.PM.Proxy.Offline.DataStore(args); + + return this; +} + +Clipperz.Base.extend(Clipperz.PM.Proxy.Offline, Clipperz.PM.Proxy, { + + 'toString': function () { + return "Clipperz.PM.Proxy.Offline"; + }, + + //------------------------------------------------------------------------- + + 'dataStore': function () { + return this._dataStore; + }, + + //------------------------------------------------------------------------- + + 'sendMessage': function(aFunctionName, someParameters) { + return this.dataStore().processMessage(aFunctionName, someParameters); + }, + + //------------------------------------------------------------------------- + + __syntaxFix__: "syntax fix" + +}); + diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js new file mode 100644 index 0000000..be1c337 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js @@ -0,0 +1,167 @@ +/* + +Copyright 2008-2011 Clipperz Srl + +This file is part of Clipperz's Javascript Crypto Library. +Javascript Crypto Library provides web developers with an extensive +and efficient set of cryptographic functions. The library aims to +obtain maximum execution speed while preserving modularity and +reusability. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library is free software: you can redistribute + it and/or modify it under the terms of the GNU Affero General Public + License as published by the Free Software Foundation, either version + 3 of the License, or (at your option) any later version. + +* Javascript Crypto Library is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the implied + warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + +* You should have received a copy of the GNU Affero General Public + License along with Javascript Crypto Library. If not, see + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Proxy) == 'undefined') { Clipperz.PM.Proxy = {}; } + +//============================================================================= + +Clipperz.PM.Proxy.Test = function(args) { + Clipperz.PM.Proxy.Test.superclass.constructor.call(this, args); + + args = args || {}; + + this._expectedRequests = (args.shouldCheckExpectedRequests === true) ? [] : null; + this._isExpectingRequests = true; + this._unexpectedRequests = []; + + this.dataStore().resetData(); + + return this; +} + +Clipperz.Base.extend(Clipperz.PM.Proxy.Test, Clipperz.PM.Proxy.Offline, { + + 'toString': function() { + return "Clipperz.PM.Proxy.Test"; + }, + + //========================================================================= + + 'expectedRequests': function () { + return this._expectedRequests; + }, + + //------------------------------------------------------------------------- + + 'shouldCheckExpectedRequests': function () { + return (this._expectedRequests != null); + }, + + 'setShouldCheckExpectedRequests': function(aValue) { + if (aValue) { + this._expectedRequests = aValue; + } else { + this._expectedRequests = null; + } + }, + + //------------------------------------------------------------------------- + + 'shouldNotReceiveAnyFurtherRequest': function () { + this._isExpectingRequests = false; + }, + + 'mayReceiveMoreRequests': function () { + this._isExpectingRequests = true; + this.resetUnexpectedRequests(); + }, + + 'isExpectingRequests': function () { + return this._isExpectingRequests; + }, + + //------------------------------------------------------------------------- + + 'unexpectedRequests': function () { + return this._unexpectedRequests; + }, + + 'resetUnexpectedRequests': function () { + this._unexpectedRequests = []; + }, + + //------------------------------------------------------------------------- + + 'testExpectedRequestParameters': function (aPath, anActualRequest, anExpectedRequest) { + var aKey; +//console.log(">>> Proxy.testExpectedRequestParameters [" + aPath + "]", anActualRequest, anExpectedRequest); + for (aKey in anExpectedRequest) { + if (typeof(anActualRequest[aKey]) == 'undefined') { + throw "the expected paramter [" + aKey + "] is missing from the actual request"; + } + if (typeof(anExpectedRequest[aKey]) == 'object') { + this.testExpectedRequestParameters(aPath + "." + aKey, anActualRequest[aKey], anExpectedRequest[aKey]) + } else { + if (! anExpectedRequest[aKey](anActualRequest[aKey])) { + throw "wrong value for paramter [" + aKey + "]; got '" + anActualRequest[aKey] + "'"; + } + } + } +//console.log("<<< Proxy.testExpectedRequestParameters"); + }, + + //------------------------------------------------------------------------- + + 'checkRequest': function(aFunctionName, someParameters) { + if (this.shouldCheckExpectedRequests()) { + var expectedRequest; + +//console.log(">>> Proxy.Test.checkRequest - " + aFunctionName, someParameters); + expectedRequest = this.expectedRequests().pop(); +//console.log("--- Proxy.Test.checkRequest - expectedRequest", expectedRequest); + if (expectedRequest == null) { + throw "Proxy.Test.sentMessage: no expected result specified. Got request '" + aFunctionName + "': " + someParameters; + } + + try { + if (aFunctionName != expectedRequest.functionName) { + throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'"; + } + + this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters); + } catch(exception) { +//console.log("EXCEPTION: Proxy.Test.sentMessage[" + expectedRequest.name + "]", exception) + throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception; + } + } +//console.log("<<< Proxy.Test.checkRequest"); + }, + + //========================================================================= + + 'sendMessage': function(aFunctionName, someParameters) { + var result; + + if (this.isExpectingRequests() == false) { +// throw Clipperz.PM.Connection.exception.UnexpectedRequest; +Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */); + this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); + }; + this.checkRequest(aFunctionName, someParameters); + result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); + + return result; + }, + + //========================================================================= + __syntaxFix__: "syntax fix" + +}); + -- cgit v0.9.0.2