Browse Source

Implement new message types required for encryption support.

pull/225/head
Joachim Bauch 11 years ago
parent
commit
6e091c26bf
  1. 40
      src/app/spreed-webrtc-server/channelling.go
  2. 63
      src/app/spreed-webrtc-server/channelling_api.go
  3. 2
      src/app/spreed-webrtc-server/session.go

40
src/app/spreed-webrtc-server/channelling.go

@ -195,6 +195,11 @@ type DataIncoming struct {
Sessions *DataSessions Sessions *DataSessions
Room *DataRoom Room *DataRoom
Iid string `json:",omitempty"` Iid string `json:",omitempty"`
EncryptionRegister *DataEncryptionRegister
EncryptionRequestKeyBundle *DataEncryptionRequestKeyBundle
EncryptionKeyBundle *DataEncryptionKeyBundle
Encrypted *DataEncrypted
} }
type DataOutgoing struct { type DataOutgoing struct {
@ -231,3 +236,38 @@ type DataAuthentication struct {
Type string Type string
Authentication *SessionToken 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
src/app/spreed-webrtc-server/channelling_api.go

@ -156,6 +156,30 @@ func (api *channellingAPI) OnIncoming(sender Sender, session *Session, msg *Data
} }
return api.HandleRoom(session, msg.Room) 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: default:
log.Println("OnText unhandled message type", msg.Type) log.Println("OnText unhandled message type", msg.Type)
} }
@ -327,3 +351,42 @@ func (api *channellingAPI) HandleRoom(session *Session, room *DataRoom) (*DataRo
} }
return room, err 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
src/app/spreed-webrtc-server/session.go

@ -56,6 +56,8 @@ type Session struct {
subscribers map[string]*Session subscribers map[string]*Session
disconnected bool disconnected bool
replaced bool replaced bool
encryptionRegistration *DataEncryptionRegister
} }
func NewSession(manager SessionManager, unicaster Unicaster, broadcaster Broadcaster, rooms RoomStatusManager, buddyImages ImageCache, attestations *securecookie.SecureCookie, id, sid string) *Session { func NewSession(manager SessionManager, unicaster Unicaster, broadcaster Broadcaster, rooms RoomStatusManager, buddyImages ImageCache, attestations *securecookie.SecureCookie, id, sid string) *Session {

Loading…
Cancel
Save