Skip to content

Commit 523dca4

Browse files
committed
fix: outgoing messages should not be decrypted
1 parent c6e0368 commit 523dca4

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/chat_sdk/conversations/private_v1.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ proc decrypt*(convo: PrivateV1, enc: EncryptedPayload): Result[seq[byte], ChatEr
9494
)
9595
copyMem(addr header.dhPublic[0], unsafeAddr dr.dh[0], dr.dh.len) # TODO: Avoid this copy
9696

97+
if convo.doubleratchet.dhSelf.public == header.dhPublic:
98+
info "outgoing message, no need to decrypt"
99+
return err(ChatError(code: errDecryptOutgoing, context: "Attempted to decrypt outgoing message"))
100+
97101
convo.doubleratchet.decrypt(header, dr.ciphertext, @[]).mapErr(proc(e: NaxolotlError): ChatError = ChatError(code: errWrapped, context: repr(e) ))
98102

99103

src/chat_sdk/errors.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type
88
ErrorCode* = enum
99
errTypeError
1010
errWrapped
11+
errDecryptOutgoing
1112

1213

1314
proc `$`*(x: ChatError): string =

src/naxolotl/naxolotl.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const maxSkip = 10
1616

1717

1818
type Doubleratchet* = object
19-
dhSelf: PrivateKey
19+
dhSelf*: PrivateKey
2020
dhRemote: PublicKey
2121

2222
rootKey: RootKey

0 commit comments

Comments
 (0)