dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit df44790d7f7bbd4aa123efc8d2cac4308df1cf7a
parent 07effebf242db8ced67d4d8355cf5a6c8023659f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 25 May 2023 07:02:46 -0700

Fix stream for encrypted rooms

Diffstat:
Mpkg/database/tableChatMessages.go | 9+++++++++
Mpkg/web/handlers/handlers.go | 18++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/pkg/database/tableChatMessages.go b/pkg/database/tableChatMessages.go @@ -19,6 +19,15 @@ import ( type ChatMessages []ChatMessage +func (m *ChatMessage) Decrypt(key string) error { + aesgcm, _, err := utils.GetGCM(key) + if err != nil { + return err + } + m.Message = decrypt(m.Message, aesgcm) + return nil +} + func (m ChatMessages) DecryptAll(key string) error { aesgcm, _, err := utils.GetGCM(key) if err != nil { diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5061,6 +5061,15 @@ func ChatStreamMessagesHandler(c echo.Context) error { displayHellbanned := authUser.DisplayHellbanned || authUser.IsHellbanned displayIgnoredMessages := false msgs, _ := db.GetChatMessages(room.ID, authUser.Username, authUser.ID, pmOnlyQuery, mentionsOnlyQuery, displayHellbanned, authUser.DisplayIgnored, authUser.DisplayModerators, displayIgnoredMessages) + if room.IsProtected() { + key, err := hutils.GetRoomKeyCookie(c, int64(room.ID)) + if err != nil { + return c.Redirect(http.StatusFound, "/") + } + if err := msgs.DecryptAll(key.Value); err != nil { + return c.Redirect(http.StatusFound, "/") + } + } data.Messages = msgs bools := []bool{authUser.DisplayDeleteButton} if authUser.IsModerator() { @@ -5126,6 +5135,15 @@ Loop: } msg := msgTyp.Msg + if room.IsProtected() { + key, err := hutils.GetRoomKeyCookie(c, int64(room.ID)) + if err != nil { + return c.Redirect(http.StatusFound, "/") + } + if err := msg.Decrypt(key.Value); err != nil { + return c.Redirect(http.StatusFound, "/") + } + } if !verifyMsgAuth(db, authUser, msg) || !applyUserFilters(db, authUser, msg, pmOnlyQuery, displayHellbanned, mentionsOnlyQuery) {