fix: outgoing messages should not be decrypted

This commit is contained in:
kaichaosun 2025-11-28 16:09:02 +08:00
parent c6e03686fe
commit 523dca43e1
No known key found for this signature in database
GPG Key ID: 223E0F992F4F03BF
3 changed files with 6 additions and 1 deletions

View File

@ -94,6 +94,10 @@ proc decrypt*(convo: PrivateV1, enc: EncryptedPayload): Result[seq[byte], ChatEr
)
copyMem(addr header.dhPublic[0], unsafeAddr dr.dh[0], dr.dh.len) # TODO: Avoid this copy
if convo.doubleratchet.dhSelf.public == header.dhPublic:
info "outgoing message, no need to decrypt"
return err(ChatError(code: errDecryptOutgoing, context: "Attempted to decrypt outgoing message"))
convo.doubleratchet.decrypt(header, dr.ciphertext, @[]).mapErr(proc(e: NaxolotlError): ChatError = ChatError(code: errWrapped, context: repr(e) ))

View File

@ -8,6 +8,7 @@ type
ErrorCode* = enum
errTypeError
errWrapped
errDecryptOutgoing
proc `$`*(x: ChatError): string =

View File

@ -16,7 +16,7 @@ const maxSkip = 10
type Doubleratchet* = object
dhSelf: PrivateKey
dhSelf*: PrivateKey
dhRemote: PublicKey
rootKey: RootKey