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

[WIP] Implement end-to-end encryption #225

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/app/spreed-webrtc-server/channelling.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ type DataIncoming struct {
Sessions *DataSessions
Room *DataRoom
Iid string `json:",omitempty"`

EncryptionRegister *DataEncryptionRegister
EncryptionRequestKeyBundle *DataEncryptionRequestKeyBundle
EncryptionKeyBundle *DataEncryptionKeyBundle
Encrypted *DataEncrypted
}

type DataOutgoing struct {
Expand Down Expand Up @@ -231,3 +236,38 @@ type DataAuthentication struct {
Type string
Authentication *SessionToken
}

type DataEncryptionRegisterSignedPreKey struct {
Id int64
Key string
Signature string
}

type DataEncryptionRegister struct {
RegistrationId int64
Identity string
LastResortSignedPreKey DataEncryptionRegisterSignedPreKey
}

type DataEncryptionRequestKeyBundle struct {
To string `json:",omitempty"`
Type string `json:",omitempty"`
}

type DataEncryptionKeyBundle struct {
To string `json:",omitempty"`
Type string `json:",omitempty"`
Identity string
PreKeyId int64 `json:",omitempty"`
PreKey string `json:",omitempty"`
SignedPreKeyId int64 `json:",omitempty"`
SignedPreKey string `json:",omitempty"`
SignedPreKeySignature string `json:",omitempty"`
}

type DataEncrypted struct {
To string `json:",omitempty"`
Type string `json:",omitempty"`
Message string
Data string
}
63 changes: 63 additions & 0 deletions src/app/spreed-webrtc-server/channelling_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ func (api *channellingAPI) OnIncoming(sender Sender, session *Session, msg *Data
}

return api.HandleRoom(session, msg.Room)
case "EncryptionRegister":
if msg.EncryptionRegister == nil {
return nil, NewDataError("bad_request", "message did not contain EncryptionRegister")
}

api.HandleEncryptionRegister(session, msg.EncryptionRegister)
case "EncryptionRequestKeyBundle":
if msg.EncryptionRequestKeyBundle == nil {
return nil, NewDataError("bad_request", "message did not contain EncryptionRequestKeyBundle")
}

return api.HandleEncryptionRequestKeyBundle(session, msg.EncryptionRequestKeyBundle)
case "EncryptionKeyBundle":
if msg.EncryptionKeyBundle == nil {
return nil, NewDataError("bad_request", "message did not contain EncryptionKeyBundle")
}

return api.HandleEncryptionKeyBundle(session, msg.EncryptionKeyBundle)
case "Encrypted":
if msg.Encrypted == nil {
return nil, NewDataError("bad_request", "message did not contain Encrypted")
}

return api.HandleEncrypted(session, msg.Encrypted)
default:
log.Println("OnText unhandled message type", msg.Type)
}
Expand Down Expand Up @@ -327,3 +351,42 @@ func (api *channellingAPI) HandleRoom(session *Session, room *DataRoom) (*DataRo
}
return room, err
}

func (api *channellingAPI) HandleEncryptionRegister(session *Session, register *DataEncryptionRegister) {
session.encryptionRegistration = register
}

func (api *channellingAPI) HandleEncryptionRequestKeyBundle(session *Session, request *DataEncryptionRequestKeyBundle) (interface{}, error) {
if request.To == "" {
return nil, NewDataError("empty_peer", "cannot send to empty peer")
}
// TODO(fancycode): Check if peer is online and return bundle based on
// registration data if not.
message := &DataEncryptionRequestKeyBundle{
Type: "EncryptionRequestKeyBundle",
}
session.Unicast(request.To, message)
return nil, nil
}

func (api *channellingAPI) HandleEncryptionKeyBundle(session *Session, bundle *DataEncryptionKeyBundle) (interface{}, error) {
if bundle.To == "" {
return nil, NewDataError("empty_peer", "cannot send to empty peer")
}
message := *bundle
message.To = ""
message.Type = "EncryptionKeyBundle"
session.Unicast(bundle.To, message)
return nil, nil
}

func (api *channellingAPI) HandleEncrypted(session *Session, data *DataEncrypted) (interface{}, error) {
if data.To == "" {
return nil, NewDataError("empty_peer", "cannot send to empty peer")
}
message := *data
message.To = ""
message.Type = "Encrypted"
session.Unicast(data.To, message)
return nil, nil
}
2 changes: 2 additions & 0 deletions src/app/spreed-webrtc-server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Session struct {
subscribers map[string]*Session
disconnected bool
replaced bool

encryptionRegistration *DataEncryptionRegister
}

func NewSession(manager SessionManager, unicaster Unicaster, broadcaster Broadcaster, rooms RoomStatusManager, buddyImages ImageCache, attestations *securecookie.SecureCookie, id, sid string) *Session {
Expand Down
27 changes: 27 additions & 0 deletions src/styles/components/_chat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@
}
}

.identityhint {
color: $chat-typing;
font-size: .8em;
height: 16px;
overflow: hidden;
padding: 0 6px;
white-space: nowrap;

@include breakpt($breakpoint-chat-small, max-height) {
display: none;
}
}

.inputbox {
position: relative;

Expand Down Expand Up @@ -349,6 +362,15 @@
width: 12px;
}

&:after {
float: right;
font-family: FontAwesome;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties should be ordered float, font-family, left, margin-left, text-align, width

left: 0;
margin-left: 1em;
text-align: center;
width: 12px;
}

&.unread:before {
color: $chat-msg-unread-icon-color;
content: $chat-msg-unread-icon;
Expand Down Expand Up @@ -378,6 +400,11 @@
color: $chat-msg-read-icon-color;
content: $chat-msg-read-icon;
}

&.encrypted:after {
color: $chat-msg-encrypted-icon-color;
content: $chat-msg-encrypted-icon;
}
}

.buddyPicture {
Expand Down
2 changes: 2 additions & 0 deletions src/styles/global/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ $chat-msg-sent-icon-color: #5882fa !default;
$chat-msg-delivered-icon-color: #5882fa !default;
$chat-msg-received-icon-color: #84b819 !default;
$chat-msg-read-icon-color: $chat-msg-default-icon-color !default;
$chat-msg-encrypted-icon-color: $chat-msg-default-icon-color !default;

$chat-msg-unread-icon: '\f0eb' !default;
$chat-msg-sending-icon: '\f0ec' !default;
$chat-msg-sent-icon: '\f003' !default;
$chat-msg-delivered-icon: '\f019' !default;
$chat-msg-received-icon: '\f06e' !default;
$chat-msg-read-icon: '\f00c' !default;
$chat-msg-encrypted-icon: '\f023' !default;

$chat-msg-self-background: #fff !default;
$chat-msg-self-color: $font-color !default;
Expand Down
26 changes: 16 additions & 10 deletions static/js/controllers/chatroomcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p

}

$scope.display = function(s, nodes, extra_css, title, picture) {
$scope.display = function(s, nodes, extra_css, title, picture, encrypted) {

var container;
var element;
Expand All @@ -235,6 +235,9 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
lastMessageContainer = $("<ul>").appendTo(container);
if ($.trim(s)) {
element = $("<li>").html(s);
if (encrypted) {
element.addClass("encrypted");
}
element.prepend('<div class="timestamp-space">');
element.appendTo(lastMessageContainer);
}
Expand Down Expand Up @@ -267,7 +270,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
$scope.display(s, nodes);
});

$scope.append = function(s, nodes) {
$scope.append = function(s, nodes, encrypted) {

if (!lastMessageContainer) {
return;
Expand All @@ -276,6 +279,9 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
var scroll = this.canScroll();

var li = $("<li>");
if (encrypted) {
li.addClass("encrypted");
}
li.html(s)
lastMessageContainer.append(li)

Expand Down Expand Up @@ -325,7 +331,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p

};

$scope.showmessage = function(from, timestamp, message, nodes) {
$scope.showmessage = function(from, timestamp, message, nodes, encrypted) {

var sessonid = $scope.$parent.$parent.id;

Expand Down Expand Up @@ -354,7 +360,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
var strMessage = s.join(" ");

if (!is_new_message) {
var element = this.append(strMessage, nodes);
var element = this.append(strMessage, nodes, encrypted);
if (element) {
return element;
}
Expand All @@ -375,7 +381,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
nodes = ts;
}
}
return $scope.display(strMessage, nodes, msg.extra_css, msg.title, msg.picture);
return $scope.display(strMessage, nodes, msg.extra_css, msg.title, msg.picture, encrypted);

};

Expand Down Expand Up @@ -406,7 +412,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
$scope.focus();
});

$scope.$on("received", function(event, from, data) {
$scope.$on("received", function(event, from, data, encrypted) {

var sessionid = $scope.$parent.$parent.id;
var mid = data.Mid || null;
Expand Down Expand Up @@ -482,7 +488,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
subscope.from = from;
fileInfo(subscope, function(clonedElement, scope) {
var text = fromself ? translation._("You share file:") : translation._("Incoming file:");
element = $scope.showmessage(from, timestamp, text, clonedElement);
element = $scope.showmessage(from, timestamp, text, clonedElement, encrypted);
});
noop = true;
}
Expand All @@ -494,7 +500,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
subscope.from = from;
geoLocation(subscope, function(clonedElement, scope) {
var text = fromself ? translation._("You shared your location:") : translation._("Location received:");
element = $scope.showmessage(from, timestamp, text, clonedElement);
element = $scope.showmessage(from, timestamp, text, clonedElement, encrypted);
});
noop = true;
}
Expand Down Expand Up @@ -527,7 +533,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
}
}
}
element = $scope.showmessage(from, timestamp, text, clonedElement);
element = $scope.showmessage(from, timestamp, text, clonedElement, encrypted);
});
noop = true;
}
Expand All @@ -550,7 +556,7 @@ define(['jquery', 'underscore', 'moment', 'text!partials/fileinfo.html', 'text!p
message = safeMessage(data.Message);
}
// Show the beast.
element = $scope.showmessage(from, timestamp, message, nodes);
element = $scope.showmessage(from, timestamp, message, nodes, encrypted);
}

if (element && mid && !$scope.isgroupchat) {
Expand Down
11 changes: 10 additions & 1 deletion static/js/controllers/uicontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"use strict";
define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapter'], function($, _, BigScreen, moment, sjcl, Modernizr) {

return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", "localStatus", "dialogs", "rooms", "constraints", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, localStatus, dialogs, rooms, constraints) {
return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", "localStatus", "dialogs", "rooms", "constraints", "endToEndEncryption", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, localStatus, dialogs, rooms, constraints, endToEndEncryption) {

alertify.dialog.registerCustom({
baseType: 'notify',
Expand Down Expand Up @@ -116,6 +116,7 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
$scope.id = $scope.myid = null;
$scope.userid = $scope.myuserid = null;
$scope.suserid = null;
$scope.fingerprint = null;
$scope.peer = null;
$scope.dialing = null;
$scope.conference = null;
Expand Down Expand Up @@ -536,6 +537,14 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
}
});

endToEndEncryption.events.on("identity.own", function(event, identity) {
if (identity) {
$scope.fingerprint = identity.getFingerprint();
} else {
$scope.fingerprint = null;
}
});

// Start heartbeat timer.
$window.setInterval(function() {
mediaStream.api.heartbeat(5000, 11500)
Expand Down
5 changes: 4 additions & 1 deletion static/js/directives/buddylist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
define(['underscore', 'text!partials/buddylist.html'], function(_, template) {

// buddyList
return ["buddyList", "api", "webrtc", "contacts", function(buddyList, api, webrtc, contacts) {
return ["buddyList", "api", "webrtc", "contacts", "endToEndEncryption", function(buddyList, api, webrtc, contacts, endToEndEncryption) {

//console.log("buddyList directive");

Expand Down Expand Up @@ -125,6 +125,9 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
onContactUpdated(data);
});

endToEndEncryption.events.on("identity.received", function(event, peer, identity) {
buddylist.onIdentityReceived(peer, identity);
});
}];

var link = function(scope, iElement, iAttrs, controller) {
Expand Down
Loading