Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sharesecret #268 #652

Merged
merged 2 commits into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/rocketchat-sharedsecret/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Package.describe({
name: 'rocketchat:sharedsecret',
version: '0.0.1',
summary: 'RocketChat libraries',
git: ''
});

Package.onUse(function(api) {
api.versionsFrom('1.0');

api.use([
'coffeescript',
'rocketchat:[email protected]'
]);

api.use(['jparker:crypto-aes'], ['server','client']);

api.addFiles('sharedsecret.coffee', ['server','client']);
});

Package.onTest(function(api) {});
82 changes: 82 additions & 0 deletions packages/rocketchat-sharedsecret/sharedsecret.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
SharedSecret = []

if (Meteor.isServer)
class EncryptMessage
constructor: (message) ->
currentUser = Meteor.user()._id
currentRoomId = message.rid

if(SharedSecret? && SharedSecret[currentUser]? && SharedSecret[currentUser][currentRoomId]?)
currentSecret = SharedSecret[currentUser][currentRoomId]
encrypted = CryptoJS.AES.encrypt(message.msg, currentSecret)
message.msg = encrypted.toString()

#urls
if(message.urls)
for urls in message.urls
urls.url = CryptoJS.AES.encrypt(urls.url, currentSecret).toString()

message.encrypted = true

return message

class HandleSlashCommand
constructor: (command, params, item) ->
if(command == "setsecretkey")
currentUser = Meteor.user()._id
currentRoomId = item.rid
secret = params

if(secret == "off")
secret = null

if(SharedSecret[currentUser]?)
SharedSecret[currentUser][currentRoomId] = secret
else
SharedSecret[currentUser] = []
SharedSecret[currentUser][currentRoomId] = secret

RocketChat.callbacks.add 'beforeSaveMessage', EncryptMessage, 9999 #LAST
RocketChat.slashCommands.add 'setsecretkey', HandleSlashCommand

if (Meteor.isClient)
class DecryptMessage
constructor: (message) ->
if(message.encrypted)
currentRoomId = message.rid
currentSecret = localStorage.getItem("rocket.chat.sharedSecretKey.#{currentRoomId}")

if(currentSecret?)
decrypted = CryptoJS.AES.decrypt(message.msg, currentSecret).toString(CryptoJS.enc.Utf8)

if(decrypted == "")
message.msg = "~ encrypted message ~"
message.html = "~ encrypted message ~"
else
lockImage = "/images/lock8.png"
message.msg = "<img src=#{lockImage} style='width:8px;height:9px;'></img> " + decrypted
message.html = "<img src=#{lockImage} style='width:8px;height:9px;'></img> " + decrypted

#urls
if(message.urls)
for urls in message.urls
urls.url = CryptoJS.AES.decrypt(urls.url, currentSecret).toString(CryptoJS.enc.Utf8)
else
message.msg = "~ encrypted message ~"
message.html = "~ encrypted message ~"

return message

class HandleSlashCommand
constructor: (command, params, item) ->
if(command == "setsecretkey")
secret = params
if(secret == "off")
secret = null
currentRoomId = item.rid
localStorage.setItem("rocket.chat.sharedSecretKey.#{currentRoomId}", secret)



RocketChat.callbacks.add 'renderMessage', DecryptMessage, -9999 #FIRST
RocketChat.slashCommands.add 'setsecretkey', HandleSlashCommand