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 4 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
6 changes: 3 additions & 3 deletions static/js/directives/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
}
_.delay(function() {
mediaStream.api.apply("sendChat", {
send: function(type, data) {
send: function(type, data, origType, origData) {
// We also send to self, to display our own stuff.
if (!noloop) {
mediaStream.api.received({
Type: data.Type,
Data: data,
Type: origData.Type,
Data: origData,
From: mediaStream.api.id,
To: peercall.id
});
Expand Down
Loading