Skip to content

Commit

Permalink
add new web backend
Browse files Browse the repository at this point in the history
  • Loading branch information
SSilence committed Aug 9, 2014
1 parent 169c2fe commit 20b5143
Show file tree
Hide file tree
Showing 288 changed files with 48,477 additions and 49 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Special thanks to the great programmers of this libraries which will be used in
* grunt coverage template: https://github.com/maenu/grunt-template-jasmine-istanbul
* jasmine unit test: http://jasmine.github.io/
* wait for images: https://github.com/alexanderdickson/waitForImages
* request: https://github.com/mikeal/request

[1]: http://nodejs.org/
[2]: http://www.jrsoftware.org/isinfo.php
9 changes: 6 additions & 3 deletions app/default.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; backend: use file or web for user management
backend = file
; use file or web for user management
userlist = file

; url for backend file
web_url =
web_url = http://localhost/sum/backend.php

; web backend aes key
web_aes_key = secret
Expand All @@ -16,6 +16,9 @@ user_file_extended = c:/tmp/?
; path of lock file
lock_file = c:/tmp/userfile.lock

; initialization vector for aes encryption
iv = fio78JKHaids

; path of version file
version_file = c:/tmp/version

Expand Down
3 changes: 2 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ <h1>R&auml;ume <span id="rooms-add" class="ion-plus-round"></span></h1>
<script src="sum-init.js"></script>
<script src="sum-emoticons.js"></script>
<script src="sum-backend.js"></script>
<script src="sum-backend-userlist.js"></script>
<script src="sum-backend-userlist-file.js"></script>
<script src="sum-backend-userlist-web.js"></script>
<script src="sum-backend-helpers.js"></script>
<script src="sum-backend-client.js"></script>
<script src="sum-backend-server.js"></script>
Expand Down
5 changes: 3 additions & 2 deletions app/sum-backend-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if (typeof base64 == 'undefined') base64 = require('base64-stream');
if (typeof fs == 'undefined') fs = require('fs');
if (typeof http == 'undefined') http = require('http');

/**
* client for sending encrypted chat messages and status updates
Expand Down Expand Up @@ -30,7 +31,7 @@ define('sum-backend-client', Class.extend({
*/
send: function(receiver, message, success, error) {
// encrypt message
var encMessage = this.backendHelpers.encrypt(new NodeRSA(receiver.key), message);
var encMessage = this.backendHelpers.rsaencrypt(new NodeRSA(receiver.key), message);

// send message
var request = http.request({
Expand All @@ -39,7 +40,7 @@ define('sum-backend-client', Class.extend({
path: '/',
method: 'POST',
headers: {
'Content-Txype': 'application/json',
'Content-Type': 'application/json',
'Content-Length': encMessage.length
}
}, function(res) {
Expand Down
8 changes: 1 addition & 7 deletions app/sum-backend-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ define('sum-backend-command', Class.extend({
backend: injected('sum-backend'),


/**
* backends userlist updater
*/
backendUserlist: injected('sum-backend-userlist'),


/**
* execute command.
* @param (string) command given by message input
Expand Down Expand Up @@ -97,7 +91,7 @@ define('sum-backend-command', Class.extend({

// /reload
} else if(command == '/reload') {
this.backendUserlist.userlistUpdateTimer();
this.backend.backendUserlist.userlistUpdateTimer();
this.backend.renderSystemMessage('userlist reload', conversation);


Expand Down
76 changes: 54 additions & 22 deletions app/sum-backend-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,60 @@ define('sum-backend-helpers', Class.extend({
},


/**
* decrypt with AES
* @return (string) decrypted text
* @param (string) cryptkey password
* @param (string) encryptdata encrypted data to decrypt
*/
aesdecrypt: function(cryptkey, encryptdata) {
cryptkey = crypto.createHash('sha256').update(cryptkey).digest();
encryptdata = new Buffer(encryptdata, 'base64').toString('binary');
var decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, config.iv);
var decoded = decipher.update(encryptdata, 'binary', 'utf8');
decoded += decipher.final('utf8');
return decoded;
},


/**
* encrypt with AES
* @return (string) clear text
* @param (string) cryptkey password
* @param (string) encryptdata cleartext to encrypt
*/
aesencrypt: function(cryptkey, cleardata) {
cryptkey = crypto.createHash('sha256').update(cryptkey).digest();
var encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, config.iv);
var encryptdata = encipher.update(cleardata, 'utf8', 'binary');
encryptdata += encipher.final('binary');
encode_encryptdata = new Buffer(encryptdata, 'binary').toString('base64');
return encode_encryptdata;
},


/**
* encrypt with RSA
* @return encrypted string
* @param key (string) public key for encryption
* @param data (mixed) data for encryption
*/
rsaencrypt: function(key, data) {
return key.encrypt(data, 'base64');
},


/**
* decrypt with RSA
* @return (string) decrypted string
* @param key (string) public key for decryption
* @param data (mixed) data for decryption
*/
rsadecrypt: function(key, data) {
return key.decrypt(data).toString();
},


/**
* returns current ip
* @return (string or boolean) the ip of the current user
Expand Down Expand Up @@ -186,28 +240,6 @@ define('sum-backend-helpers', Class.extend({
},


/**
* encrypt with RSA
* @return encrypted string
* @param key (string) public key for encryption
* @param data (mixed) data for encryption
*/
encrypt: function(key, data) {
return key.encrypt(data, 'base64');
},


/**
* decrypt with RSA
* @return (string) decrypted string
* @param key (string) public key for decryption
* @param data (mixed) data for decryption
*/
decrypt: function(key, data) {
return key.decrypt(data).toString();
},


/**
* search user in userlist
* @return (object or boolean) user object or false if none was found
Expand Down
2 changes: 1 addition & 1 deletion app/sum-backend-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define('sum-backend-server', Class.extend({
// parse decrypted json
var req = {};
try {
var reqStr = that.backendHelpers.decrypt(that.backend.key, body);
var reqStr = that.backendHelpers.rsadecrypt(that.backend.key, body);
req = JSON.parse(reqStr);
} catch(e) {
that.backend.error('Ungueltige Nachricht erhalten (verschluesselung oder JSON konnte nicht verarbeitet werden)');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* handels userlist file update
* handels userlist file update by using a file in shared file system
*
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
*/
define('sum-backend-userlist', Class.extend({
define('sum-backend-userlist-file', Class.extend({

/**
* backends
Expand Down
Loading

0 comments on commit 20b5143

Please sign in to comment.