author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (side-by-side diff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /frontend/beta/js/Clipperz/PM/Proxy | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Proxy') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | frontend/beta/js/Clipperz/PM/Proxy/Proxy.JSON.js | 100 | ||||
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js | 804 | ||||
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.js | 73 | ||||
-rwxr-xr-x | frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js | 259 | ||||
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Proxy/Proxy.Test.js | 94 |
5 files changed, 1330 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.JSON.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.JSON.js new file mode 100755 index 0000000..889e1f1 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.JSON.js @@ -0,0 +1,100 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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; +} + +YAHOO.extendX(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 MochiKit.Async.Deferred(); + deferredResult.addCallback(function (aValue) { + MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'remoteRequestSent'); + return aValue; + }); + deferredResult.addCallback(MochiKit.Async.doXHR, this.url(), { + method:'POST', + sendContent:MochiKit.Base.queryString(parameters), + headers:{"Content-Type":"application/x-www-form-urlencoded"} + }); + deferredResult.addCallback(function (aValue) { + MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'remoteRequestReceived'); + return aValue; + }); +// 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/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js new file mode 100644 index 0000000..4d3ba08 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js @@ -0,0 +1,804 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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._connections = {}; + + this._b = null; + this._B = null; + this._A = null; + this._userData = null; + + return this; +} + +//Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { +Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, { + + //------------------------------------------------------------------------- + + 'isReadOnly': function () { + return this._isReadOnly; + }, + + //------------------------------------------------------------------------- + + 'shouldPayTolls': function() { + return this._shouldPayTolls; + }, + + //------------------------------------------------------------------------- + + 'data': function () { + return this._data; + }, + + //------------------------------------------------------------------------- + + 'tolls': function () { + return this._tolls; + }, + + //------------------------------------------------------------------------- + + 'connections': function () { + return this._connections; + }, + + //========================================================================= + + '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 MochiKit.Async.Deferred(); + c = someData['users'].length; + + for (i=0; i<c; i++) { + var newConnection; + var recordConfiguration; + + deferredResult.addCallback(MochiKit.Base.method(this, 'userSerializedEncryptedData', someData['users'][i])); + deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) { +//console.log("SERIALIZED USER", aUserSerializationContext); + resultData['users'][aUserSerializationContext['credentials']['C']] = { + 's': aUserSerializationContext['credentials']['s'], + 'v': aUserSerializationContext['credentials']['v'], + 'version': aUserSerializationContext['data']['connectionVersion'], + 'userDetails': aUserSerializationContext['encryptedData']['user']['header'], + 'userDetailsVersion': aUserSerializationContext['encryptedData']['user']['version'], + 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'], + 'lock': aUserSerializationContext['encryptedData']['user']['lock'], + 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records']) + } + }, this)); + } + + deferredResult.addCallback(MochiKit.Base.bind(function() { +//console.log("this._data", resultData); + this._data = resultData; + }, this)); + + deferredResult.callback(); +//Clipperz.log("<<< Proxy.Test.setupWithData"); + + return deferredResult; + }, + + //========================================================================= + + 'b': function() { + return this._b; + }, + + 'set_b': function(aValue) { + this._b = aValue; + }, + + //------------------------------------------------------------------------- + + 'B': function() { + return this._B; + }, + + 'set_B': function(aValue) { + this._B = aValue; + }, + + //------------------------------------------------------------------------- + + 'A': function() { + return this._A; + }, + + 'set_A': function(aValue) { + this._A = aValue; + }, + + //------------------------------------------------------------------------- + + 'userData': function() { + return this._userData; + }, + + 'setUserData': function(aValue) { + this._userData = aValue; + }, + + //========================================================================= + + 'getTollForRequestType': function (aRequestType) { + var result; + var targetValue; + var cost; + + targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); + switch (aRequestType) { + case 'REGISTER': + cost = 5; + break; + case 'CONNECT': + cost = 5; + break; + case 'MESSAGE': + cost = 2; + break; + } + + result = { + requestType: aRequestType, + targetValue: targetValue, + cost: cost + } + + if (this.shouldPayTolls()) { + this.tolls()[targetValue] = result; + } + + return result; + }, + + //------------------------------------------------------------------------- + + 'checkToll': function (aFunctionName, someParameters) { + if (this.shouldPayTolls()) { + var localToll; + var tollParameters; + + tollParameters = someParameters['toll']; + localToll = this.tolls()[tollParameters['targetValue']]; + + if (localToll != null) { + if (! Clipperz.PM.Toll.validate(tollParameters['targetValue'], tollParameters['toll'], localToll['cost'])) { + throw "Toll value too low."; + }; + } else { + throw "Missing toll"; + } + } + }, + + //========================================================================= + + 'processMessage': function(aFunctionName, someParameters) { + var result; + + switch(aFunctionName) { + case 'knock': + result = this._knock(someParameters); + break; + case 'registration': + this.checkToll(aFunctionName, someParameters); + result = this._registration(someParameters.parameters); + break; + case 'handshake': + this.checkToll(aFunctionName, someParameters); + result = this._handshake(someParameters.parameters); + break; + case 'message': + this.checkToll(aFunctionName, someParameters); + result = this._message(someParameters.parameters); + break; + case 'logout': + result = this._logout(someParameters.parameters); + break; + } + + return result; + }, + + //========================================================================= + + '_knock': function(someParameters) { + var result; + + result = { + toll: this.getTollForRequestType(someParameters['requestType']) +// toll: { +// requestType: someParameters['requestType'], +// targetValue: "3a1ba0be23580f902885c6c8a6b035e228ed1ca74d77de5f9bb0e0c899f07cfe", +// cost: +// } + } + + return result; + }, + + //------------------------------------------------------------------------- + + '_registration': function(someParameters) { +//console.log("_registration", someParameters); + if (this.isReadOnly() == false) { + if (typeof(this.data()['users'][someParameters['credentials']['C']]) == 'undefined') { + this.data()['users'][someParameters['credentials']['C']] = { + 's': someParameters['credentials']['s'], + 'v': someParameters['credentials']['v'], + 'version': someParameters['credentials']['version'], + // 'lock': someParameters['user']['lock'], + 'lock': Clipperz.Crypto.Base.generateRandomSeed(), + // 'maxNumberOfRecords': '100', + 'userDetails': someParameters['user']['header'], + 'statistics': someParameters['user']['statistics'], + 'userDetailsVersion': someParameters['user']['version'], + 'records': {} + } + } else { + throw "user already exists"; + } + } else { + throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; + } + + result = { + result: { + 'lock': this.data()['users'][someParameters['credentials']['C']]['lock'], + 'result': 'done' + }, + toll: this.getTollForRequestType('CONNECT') + } + + return MochiKit.Async.succeed(result); + }, + + //------------------------------------------------------------------------- + + '_handshake': function(someParameters) { + var result; + var nextTollRequestType; + +//Clipperz.log(">>> Proxy.Offline.DataStore._handshake"); + result = {}; + if (someParameters.message == "connect") { + var userData; + var randomBytes; + var b, B, v; + +//console.log(">>> Proxy.Offline.DataStore._handshake.connect", someParameters); + userData = this.data()['users'][someParameters.parameters.C]; + + if ((typeof(userData) != 'undefined') && (userData['version'] == someParameters.version)) { + this.setUserData(userData); + } else { + this.setUserData(this.data()['users']['catchAllUser']); + } + + randomBytes = Clipperz.Crypto.Base.generateRandomSeed(); + this.set_b(new Clipperz.Crypto.BigInt(randomBytes, 16)); + v = new Clipperz.Crypto.BigInt(this.userData()['v'], 16); + this.set_B(v.add(Clipperz.Crypto.SRP.g().powerModule(this.b(), Clipperz.Crypto.SRP.n()))); + + this.set_A(someParameters.parameters.A); + + result['s'] = this.userData()['s']; + result['B'] = this.B().asString(16); + + nextTollRequestType = 'CONNECT'; + } else if (someParameters.message == "credentialCheck") { + var v, u, S, A, K, M1; + +//console.log(">>> Proxy.Offline.DataStore._handshake.credentialCheck", someParameters); + v = new Clipperz.Crypto.BigInt(this.userData()['v'], 16); + u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(this.B().asString(10))).toHexString(), 16); + A = new Clipperz.Crypto.BigInt(this.A(), 16); + S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(this.b(), Clipperz.Crypto.SRP.n()); + + K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2); + + M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + this.B().asString(10) + K)).toHexString().slice(2); + if (someParameters.parameters.M1 == M1) { + var M2; + + M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2); + result['M2'] = M2; + } else { + throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); + } + + nextTollRequestType = 'MESSAGE'; + } else if (someParameters.message == "oneTimePassword") { + var otpData; + +//console.log("HANDSHAKE WITH OTP", someParameters.parameters.oneTimePasswordKey); +//console.log("someParameters", someParameters); +//console.log("data.OTP", Clipperz.Base.serializeJSON(this.data()['onetimePasswords'])); + 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); + } +//console.log("<<< Proxy.Offline._handshake", result); + + result = { + result: result, + toll: this.getTollForRequestType(nextTollRequestType) + } + + return MochiKit.Async.succeed(result); + }, + + //------------------------------------------------------------------------- + + '_message': function(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; + +//try { + recordsStats = {}; + for (recordReference in this.userData()['records']) { + recordsStats[recordReference] = { + 'updateDate': this.userData()['records'][recordReference]['updateDate'] + } + } + + result['header'] = this.userDetails(); + result['statistics'] = this.statistics(); + result['maxNumberOfRecords'] = this.userData()['maxNumberOfRecords']; + result['version'] = this.userData()['userDetailsVersion']; + result['recordsStats'] = recordsStats; + + if (this.isReadOnly() == false) { + var lock; + + if (typeof(this.userData()['lock']) == 'undefined') { + this.userData()['lock'] = "<<LOCK>>"; + } + + result['lock'] = this.userData()['lock']; + } +//} catch (exception) { +// console.log("*#*#*#*#*#*#*", exception); +// throw exception; +//} + //===================================================================== + } else if (someParameters.message == 'getRecordDetail') { + 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']; + } + + //===================================================================== + // + // 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; + parameters = someParameters.parameters; + + if (parameters['C'] == null) { + result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; + } else if (parameters['s'] == null) { + result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; + } else if (parameters['v'] == null) { + result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; + } else if (parameters['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) { + result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; + } else { + 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<c; i++) { + var currentRecord; + var currentRecordData; + + currentRecordData = someParameters['parameters']['records'][i]; + currentRecord = this.userData()['records'][currentRecordData['record']['reference']]; + + if (currentRecord == null) { + } + + currentRecord['data'] = currentRecordData['record']['data']; + currentRecord['version'] = currentRecordData['record']['version']; + currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; + + currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { + 'data': currentRecordData['currentRecordVersion']['data'], + 'version': currentRecordData['currentRecordVersion']['version'], + 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], + 'previousVersionKey': currentRecordData['currentRecordVersion']['previousVersionKey'] + } + } + + this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); + result['lock'] = this.userData()['lock']; + result['result'] = 'done'; +//console.log("###<<< userData", Clipperz.Base.serializeJSON(this.userData())); + } else { + throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; + } +*/ //===================================================================== + } else if (someParameters.message == 'saveChanges') { + if (this.isReadOnly() == false) { + var i, c; + +//console.log("###==============================================================="); +//console.log("###>>>", 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 (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']['updated'].length; + for (i=0; i<c; i++) { + var currentRecord; + var currentRecordData; + + currentRecordData = someParameters['parameters']['records']['updated'][i]; + currentRecord = this.userData()['records'][currentRecordData['record']['reference']]; + + if ( + (typeof(this.userData()['records'][currentRecordData['record']['reference']]) == 'undefined') + && + (typeof(currentRecordData['currentRecordVersion']) == 'undefined') + ) { +//console.log("######## SHIT HAPPENS"); + throw "Record added without a recordVersion"; + } + + if (currentRecord == null) { + currentRecord = {}; + currentRecord['versions'] = {}; + currentRecord['creationDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); + currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); + + this.userData()['records'][currentRecordData['record']['reference']] = currentRecord; + } + + currentRecord['data'] = currentRecordData['record']['data']; + currentRecord['version'] = currentRecordData['record']['version']; + currentRecord['updateDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); + + if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') { + currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; + currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { + 'data': currentRecordData['currentRecordVersion']['data'], + 'version': currentRecordData['currentRecordVersion']['version'], + 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], + 'previousVersionKey': currentRecordData['currentRecordVersion']['previousVersionKey'], + 'creationDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), + 'updateDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), + 'accessDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()) + } + } + } + + c = someParameters['parameters']['records']['deleted'].length; + for (i=0; i<c; i++) { + var currentRecordReference; + + currentRecordReference = someParameters['parameters']['records']['deleted'][i]; +//console.log("DELETING records", currentRecordReference); + delete this.userData()['records'][currentRecordReference]; + } + + this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); + result['lock'] = this.userData()['lock']; + result['result'] = 'done'; +//console.log("###<<< userData", Clipperz.Base.serializeJSON(this.userData())); + } else { + throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; + } + + //===================================================================== + // + // U N H A N D L E D M e t h o d + // + //===================================================================== + } else { + MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message); + } + + result = { + result: result, + toll: this.getTollForRequestType('MESSAGE') + } + + return MochiKit.Async.succeed(result); + }, + + //------------------------------------------------------------------------- + + '_logout': function(someParameters) { + return MochiKit.Async.succeed({result: 'done'}); + }, + + //========================================================================= + //######################################################################### + + 'isTestData': function() { + return (typeof(this.userData()['__masterkey_test_value__']) != 'undefined'); + }, + + 'userDetails': function() { + var result; + + if (this.isTestData()) { + var serializedHeader; + var version; + +//MochiKit.Logging.logDebug("### test data"); + version = this.userData()['userDetailsVersion']; + serializedHeader = Clipperz.Base.serializeJSON(this.userData()['userDetails']); + result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(this.userData()['__masterkey_test_value__'], serializedHeader); + } else { +//MochiKit.Logging.logDebug("### NOT test data"); + result = this.userData()['userDetails']; + } + + return result; + }, + + 'statistics': function() { + var result; + + if (this.userData()['statistics'] != null) { + if (this.isTestData()) { + var serializedStatistics; + var version; + + version = this.userData()['userDetailsVersion']; + serializedStatistics = Clipperz.Base.serializeJSON(this.userData()['statistics']); + result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(this.userData()['__masterkey_test_value__'], serializedStatistics); + } else { + result = this.userData()['statistics']; + } + } else { + result = null; + } + + return result; + }, + +/* + 'userSerializedEncryptedData': function(someData) { + var deferredResult; + var deferredContext; + + deferredContext = { 'data': someData }; + + deferredResult = new Clipperz.Async.Deferred('Proxy.Test.serializeUserEncryptedData', {trace:false}); + deferredResult.addCallback(MochiKit.Base.bind(function(aDeferredContext) { + aDeferredContext['user'] = this.createUserUsingConfigurationData(aDeferredContext['data']); + return aDeferredContext; + }, this)); + deferredResult.addCallback(function(aDeferredContext) { +// return aDeferredContext['user'].encryptedDataUsingVersion(aDeferredContext['data']['version']); + return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); + }); + deferredResult.addCallback(function(aUserEncryptedData) { + deferredContext['encryptedData'] = aUserEncryptedData; + return deferredContext; + }); + deferredResult.addCallback(function(aDeferredContext) { + var connection; + + connection = new Clipperz.PM.Connection.communicationProtocol.versions[aDeferredContext['data']['connectionVersion']]() + aDeferredContext['credentials'] = connection.serverSideUserCredentials(aDeferredContext['user'].username(),aDeferredContext['user'].passphrase()); + + return aDeferredContext; + }); + +// deferredResult.addCallback(function(aDeferredContext) { +//console.log("#-#-#-#-#", aDeferredContext); +// return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); +// }, deferredContext); +// deferredResult.addCallback(function(aUserSerializedData) { +//console.log("USER SERIALIZED DATA", aUserSerializedData); +// }); +// +// deferredResult.addCallback(MochiKit.Async.succeed, deferredContext); + deferredResult.callback(deferredContext); + + return deferredResult; + }, + + 'createUserUsingConfigurationData': function(someData) { + var result; + var user; + var recordLabel; + + user = new Clipperz.PM.DataModel.User(); + user.initForTests(); + user.setUsername(someData['username']); + user.setPassphrase(someData['passphrase']); + + for (recordLabel in someData['records']) { + var recordData; + var record; + var i, c; + + recordData = someData['records'][recordLabel]; + record = new Clipperz.PM.DataModel.Record({user:user, label:recordLabel}); + record.setNotes(recordData['notes']); + + c = recordData['fields'].length; + for (i=0; i<c; i++) { + var recordField; + + recordField = new Clipperz.PM.DataModel.RecordField(); + recordField.setLabel(recordData['fields'][i]['name']); + recordField.setValue(recordData['fields'][i]['value']); + recordField.setType(recordData['fields'][i]['type']); + record.addField(recordField); + } + user.addRecord(record, true); + } + + result = user; + + return result; + }, +*/ + //========================================================================= + __syntaxFix__: "syntax fix" +}); + +Clipperz.PM.Proxy.Offline.DataStore['exception'] = { + 'ReadOnly': new MochiKit.Base.NamedError("Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly") +};
\ No newline at end of file diff --git a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.js new file mode 100644 index 0000000..072f9bf --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.js @@ -0,0 +1,73 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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; +} + +YAHOO.extendX(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); + }, + + //------------------------------------------------------------------------- + + 'isReadOnly': function () { + return true; + }, + + //------------------------------------------------------------------------- + + __syntaxFix__: "syntax fix" + +}); + diff --git a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js new file mode 100755 index 0000000..e7c2bc1 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js @@ -0,0 +1,259 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } + +//============================================================================= + +Clipperz.PM.Proxy.PHP = function(args) { + Clipperz.PM.Proxy.PHP.superclass.constructor.call(this, args); +/* + this._tolls = { + 'CONNECT': [], + 'REGISTER': [], + 'MESSAGE': [] + }; +*/ + return this; +} + +YAHOO.extendX(Clipperz.PM.Proxy.PHP, Clipperz.PM.Proxy, { + + 'toString': function() { + return "Clipperz.PM.Proxy.PHP - " + this.args(); + }, + + //========================================================================= +/* + 'tolls': function() { + return this._tolls; + }, +*/ + //------------------------------------------------------------------------- +/* + 'payToll': function(aRequestType, someParameters) { + var deferredResult; + +//MochiKit.Logging.logDebug(">>> Proxy.DWR.payToll: " + aRequestType); + if (this.tolls()[aRequestType].length > 0) { + deferredResult = MochiKit.Async.succeed(this.tolls()[aRequestType].pop()); + } else { +//MochiKit.Logging.logDebug("### " + aRequestType + " toll NOT immediately available; request queued."); + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(function(someParameters) { + return new Clipperz.PM.Toll(someParameters['toll']); + }) + com_clipperz_pm_Proxy.knock(Clipperz.Base.serializeJSON({requestType:aRequestType}), { + callback:MochiKit.Base.method(deferredResult, 'callback'), + errorHandler:MochiKit.Base.method(deferredResult, 'errback') + }); + } + + deferredResult.addCallback(function(aToll) { + return aToll.deferredPay(); + }); + deferredResult.addCallback(function(someParameters, aToll) { + var result; + + result = { + parameters: someParameters, + toll: aToll + } + + return result; + }, someParameters); + + return deferredResult; + }, +*/ + //------------------------------------------------------------------------- +/* + 'addToll': function(aToll) { + this.tolls()[aToll.requestType()].push(aToll); + }, +*/ + //========================================================================= +/* + 'setTollCallback': function(someParameters) { +//MochiKit.Logging.logDebug(">>> Proxy.DWR.setTollCallback"); +//MochiKit.Logging.logDebug("--- Proxy.DWR.setTollCallback - " + Clipperz.Base.serializeJSON(someParameters)); + if (typeof(someParameters['toll']) != 'undefined') { + this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); + } + return someParameters['result']; + }, +*/ + //========================================================================= + + 'registration': function(someParameters) { + return this.sendMessage('registration', someParameters, 'REGISTER'); + }, + + //------------------------------------------------------------------------- + + 'handshake': function(someParameters) { +/* + _s = "e8a2162f29aeaabb729f5625e9740edbf0cd80ac77c6b19ab951ed6c88443b8c"; + _v = new Clipperz.Crypto.BigInt("955e2db0f7844aca372f5799e5f7e51b5866718493096908bd66abcf1d068108", 16); + _b = new Clipperz.Crypto.BigInt("5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53", 16); + + _B = _v.add(Clipperz.Crypto.SRP.g().powerModule(_b, Clipperz.Crypto.SRP.n())); + _u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_B.asString(10))).toHexString(), 16); + _A = new Clipperz.Crypto.BigInt("3b3567ec33d73673552e960872eb154d091a2488915941038aef759236a27e64", 16); + _S = (_A.multiply(_v.powerModule(_u, Clipperz.Crypto.SRP.n()))).powerModule(_b, Clipperz.Crypto.SRP.n()); + _K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_S.asString(10))).toHexString().slice(2); + _M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_A.asString(10) + _B.asString(10) + _K)).toHexString().slice(2); + _M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_A.asString(10) + _M1 + _K)).toHexString().slice(2); + +// MochiKit.Logging.logDebug("b = " + _b.asString(16)); +// MochiKit.Logging.logDebug("v = " + _v.asString(16)); + MochiKit.Logging.logDebug("B = " + _B.asString(16)); + MochiKit.Logging.logDebug("u = " + _u.asString(16)); + MochiKit.Logging.logDebug("S = " + _S.asString(16)); + MochiKit.Logging.logDebug("K = " + _K); + MochiKit.Logging.logDebug("M1 = " + _M1); + MochiKit.Logging.logDebug("M2 = " + _M2); +// MochiKit.Logging.logDebug("someParameters.version: " + someParameters.version); +*/ + return this.sendMessage('handshake', someParameters, 'CONNECT'); + }, + + //------------------------------------------------------------------------- + + 'message': function(someParameters) { + return this.sendMessage('message', someParameters, 'MESSAGE'); + }, + + //------------------------------------------------------------------------- + + 'logout': function(someParameters) { +//MochiKit.Logging.logDebug("=== Proxy.DWR.logout"); + return this.sendMessage('logout', someParameters, 'MESSAGE'); + }, + + //========================================================================= + + 'sendMessage': function(aFunctionName, someParameters, aRequestType) { +/* + var deferredResult; + var proxy; + +//MochiKit.Logging.logDebug(">>> Proxy.DWR.sendMessage - " + aFunctionName + " - " + aRequestType); + proxy = this; + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.1 Proxy.DWR.sendMessage - 1: " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(proxy, 'payToll'), aRequestType); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.2 Proxy.DWR.sendMessage - 2: " + Clipperz.Base.serializeJSON(res)); return res;}); + deferredResult.addCallback(MochiKit.Base.method(proxy, 'sendRemoteMessage'), aFunctionName); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.DWR.sendMessage - 3: " + res); return res;}); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.DWR.sendMessage - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); + deferredResult.callback(someParameters); + +//MochiKit.Logging.logDebug("<<< Proxy.DWR.sendMessage"); + return deferredResult; +*/ + +// return this.sendRemoteMessage(aFunctionName, someParameters); + + + var deferredResult; + var proxy; + + proxy = this; + + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(MochiKit.Base.method(proxy, 'sendRemoteMessage'), aFunctionName); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.PHP.sendMessage - 3: " + res); return res;}); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.PHP.sendMessage - 3.1: " + Clipperz.Base.serializeJSON(res)); return res;}); + + deferredResult.callback(someParameters); + + return deferredResult; + }, + + //========================================================================= + + 'sendRemoteMessage': function(aFunctionName, someParameters) { +/* + var deferredResult; + +//MochiKit.Logging.logDebug(">>> Proxy.DWR.sendRemoteMessage('" + aFunctionName + "', " + Clipperz.Base.serializeJSON(someParameters) + ") - " + this); + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Proxy.DWR.sendRemoteMessage - 1: " + res); return res;}); +// deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Proxy.DWR.sendRemoteMessage - 2: " + res); return res;}); + + com_clipperz_pm_Proxy[aFunctionName](Clipperz.Base.serializeJSON(someParameters), { + callback:MochiKit.Base.method(deferredResult, 'callback'), + errorHandler:MochiKit.Base.method(deferredResult, 'errback') + }); +//MochiKit.Logging.logDebug("<<< Proxy.PHP.sendRemoteMessage - result: " + deferredResult); + + return deferredResult; +*/ + + var deferredResult; + var parameters; + +//MochiKit.Logging.logDebug(">>> Proxy.PHP.sendRemoteMessage('" + aFunctionName + "', " + Clipperz.Base.serializeJSON(someParameters) + ") - " + this); + parameters = {}; + parameters['method'] = aFunctionName; +// parameters['version'] = someParameters['version']; +// parameters['message'] = someParameters['message']; + parameters['parameters'] = Clipperz.Base.serializeJSON(someParameters); +//MochiKit.Logging.logDebug("--- Proxy.PHP.sendRemoteMessage('" + Clipperz.Base.serializeJSON(parameters) + ") - " + this); + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(MochiKit.Async.doXHR, "./php/index.php", { + method:'POST', + sendContent:MochiKit.Base.queryString(parameters), + headers:{"Content-Type":"application/x-www-form-urlencoded"} + }); +//deferredResult.addCallback(function(res) {MochiKit.Logging.logDebug("Proxy.PHP.response - 2: " + res.responseText); return res;}); +//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("Proxy.PHP.response - ERROR: " + res); return res;}); + deferredResult.addCallback(MochiKit.Async.evalJSONRequest); + deferredResult.callback(); + + return deferredResult; + }, + + //========================================================================= + + 'isReadOnly': function() { + return false; + }, + + //========================================================================= + __syntaxFix__: "syntax fix" + +}); + +//============================================================================= + +//Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.PHP("Proxy.PHP - async test"); diff --git a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Test.js new file mode 100644 index 0000000..fd5bf8a --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Test.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 + <http://www.gnu.org/licenses/>. + +*/ + +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) { + args = args || {}; + + Clipperz.PM.Proxy.Offline.call(this, args); + + + + return this; +} + +Clipperz.PM.Proxy.Test.prototype = MochiKit.Base.update(new Clipperz.PM.Proxy.Offline(), { + + 'toString': function() { + return "Clipperz.PM.Proxy.Test"; + }, + + //------------------------------------------------------------------------- + + 'isTestData': function() { + return typeof(this.userData()['__masterkey_test_value__'] != 'undefined'); + }, + + //------------------------------------------------------------------------- + + 'userDetails': function() { + var result; + + if (this.isTestData()) { + var serializedHeader; + var version; + + version = this.userData()['version']; + serializedHeader = Clipperz.Base.serializeJSON(this.userData()['userDetails']); + result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(this.userData()['__masterkey_test_value__'], serializedHeader); + } else { + result = Clipperz.PM.Proxy.Offline.prototype.userDetails.call(this); + } + + return result; + }, + + //------------------------------------------------------------------------- + + 'statistics': function() { + var result; + var serializedStatistics; + var version; + + version = this.userData()['version']; + serializedStatistics = Clipperz.Base.serializeJSON(this.userData()['statistics']); + result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(this.userData()['__masterkey_test_value__'], serializedStatistics); + + return result; + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" + +}); + |