Skip to content

Commit

Permalink
Merge pull request #306 from mynaparrot/e2ee
Browse files Browse the repository at this point in the history
check E2EE status during validation
  • Loading branch information
jibon57 authored Jul 27, 2023
2 parents 6f43dbb + 95a1404 commit d21dfd9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 31 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jordic/lti v0.0.0-20160211051708-2c756eacbab9
github.com/livekit/protocol v1.5.10
github.com/livekit/server-sdk-go v1.0.13
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20230712031721-404781c66d13
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20230726165653-c6a1bb02b9bc
github.com/redis/go-redis/v9 v9.0.5
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -57,7 +57,7 @@ require (
github.com/magefile/mage v1.15.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/nats-io/nats.go v1.28.0 // indirect
github.com/nats-io/nkeys v0.4.4 // indirect
Expand All @@ -82,7 +82,7 @@ require (
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
Expand All @@ -97,11 +97,11 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/grpc v1.56.2 // indirect
)
13 changes: 11 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -381,6 +382,8 @@ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APP
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-slim v0.0.4/go.mod h1:kXIwPrQbAZrhungtweoDO6qQQpUem6XkBg/mXykpoO0=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
Expand All @@ -402,8 +405,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20230712031721-404781c66d13 h1:dPLhkXdUlKo++lUWeDQ//QDoxg2g993WuF+ElYOWnOs=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20230712031721-404781c66d13/go.mod h1:YLy8oW1nek4upINjR2m9FvKpiVzRKmsFWroFrmJN+a8=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20230726165653-c6a1bb02b9bc h1:I8XEoNNG5AeXTblKMpiThmFRDpf/ayRNKADxrNedzu0=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20230726165653-c6a1bb02b9bc/go.mod h1:tbwIhoTVd3uDwDY+qliua6DNLnD3IWJzyM/5zDkIQws=
github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
github.com/nats-io/nats-server/v2 v2.9.8 h1:jgxZsv+A3Reb3MgwxaINcNq/za8xZInKhDg9Q0cGN1o=
github.com/nats-io/nats.go v1.28.0 h1:Th4G6zdsz2d0OqXdfzKLClo6bOfoI/b1kInhRtFIy5c=
Expand Down Expand Up @@ -509,6 +512,8 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=
github.com/prometheus/procfs v0.11.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down Expand Up @@ -642,6 +647,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -1062,6 +1069,8 @@ google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ6
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 h1:Z8qdAF9GFsmcUuWQ5KVYIpP3PCKydn/YKORnghIalu4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e h1:S83+ibolgyZ0bqz7KEsUOPErxcv4VzlszxY+31OfB/E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down
31 changes: 15 additions & 16 deletions pkg/controllers/auth_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ func HandleVerifyToken(c *fiber.Ctx) error {
req.IsProduction = b
}

m := models.NewRoomAuthModel()
status, msg, meta := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: roomId.(string),
})

// if production then we'll check if room is active or not
// if not active then we don't allow to join user
// livekit also don't allow but throw 500 error which make confused to user.
if !status && *req.IsProduction {
return utils.SendCommonProtobufResponse(c, status, msg)
}

livekitHost := strings.Replace(config.AppCnf.LivekitInfo.Host, "host.docker.internal", "localhost", 1) // without this you won't be able to connect
v := version.Version
res := &plugnmeet.VerifyTokenRes{
Expand All @@ -146,25 +158,12 @@ func HandleVerifyToken(c *fiber.Ctx) error {
LivekitHost: &livekitHost,
Token: &token,
ServerVersion: &v,
EnabledE2Ee: false,
}

if !*req.IsProduction {
return utils.SendProtobufResponse(c, res)
}

// if production then we'll check if room is active or not
// if not active then we don't allow to join user
// livekit also don't allow but throw 500 error which make confused to user.
m := models.NewRoomAuthModel()
status, msg := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: roomId.(string),
})

if !status {
return utils.SendCommonProtobufResponse(c, status, msg)
if status && meta != nil {
res.EnabledE2Ee = meta.RoomFeatures.EndToEndEncryptionFeatures.IsEnabled
}

res.Msg = msg
return utils.SendProtobufResponse(c, res)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/lti_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func HandleLTIV1IsRoomActive(c *fiber.Ctx) error {
roomId := c.Locals("roomId")

m := models.NewRoomAuthModel()
status, msg := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
status, msg, _ := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: roomId.(string),
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/room_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func HandleIsRoomActive(c *fiber.Ctx) error {
}

m := models.NewRoomAuthModel()
status, msg := m.IsRoomActive(req)
status, msg, _ := m.IsRoomActive(req)
return utils.SendCommonProtoJsonResponse(c, status, msg)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/models/lti_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (m *LTIV1) LTIV1VerifyHeaderToken(token string) (*LtiClaims, error) {
}

func (m *LTIV1) LTIV1JoinRoom(c *plugnmeet.LtiClaims) (string, error) {
active, _ := m.authModel.IsRoomActive(&plugnmeet.IsRoomActiveReq{
active, _, _ := m.authModel.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: c.RoomId,
})

Expand Down
10 changes: 5 additions & 5 deletions pkg/models/room_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,26 @@ func (am *RoomAuthModel) CreateRoom(r *plugnmeet.CreateRoomReq) (bool, string, *
return true, "room created", room
}

func (am *RoomAuthModel) IsRoomActive(r *plugnmeet.IsRoomActiveReq) (bool, string) {
func (am *RoomAuthModel) IsRoomActive(r *plugnmeet.IsRoomActiveReq) (bool, string, *plugnmeet.RoomMetadata) {
roomDbInfo, _ := am.rm.GetRoomInfo(r.RoomId, "", 1)

if roomDbInfo.Id == 0 {
return false, "room is not active"
return false, "room is not active", nil
}

// let's make sure room actually active
_, err := am.rs.LoadRoomInfo(r.RoomId)
_, meta, err := am.rs.LoadRoomWithMetadata(r.RoomId)
if err != nil {
// room isn't active. Change status
_, _ = am.rm.UpdateRoomStatus(&RoomInfo{
RoomId: r.RoomId,
IsRunning: 0,
Ended: time.Now().Format("2006-01-02 15:04:05"),
})
return false, "room is not active"
return false, "room is not active", nil
}

return true, "room is active"
return true, "room is active", meta
}

func (am *RoomAuthModel) GetActiveRoomInfo(r *plugnmeet.GetActiveRoomInfoReq) (bool, string, *plugnmeet.ActiveRoomWithParticipant) {
Expand Down

0 comments on commit d21dfd9

Please sign in to comment.