Skip to content

Commit 622fe0a

Browse files
committed
chore: not expose private dh key.
1 parent 523dca4 commit 622fe0a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/chat_sdk/conversations/private_v1.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ 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-
10197
convo.doubleratchet.decrypt(header, dr.ciphertext, @[]).mapErr(proc(e: NaxolotlError): ChatError = ChatError(code: errWrapped, context: repr(e) ))
10298

10399

@@ -194,6 +190,10 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T,
194190
let enc = decode(bytes, EncryptedPayload).valueOr:
195191
raise newException(ValueError, fmt"Failed to decode EncryptedPayload: {repr(error)}")
196192

193+
if convo.doubleratchet.dhSelfPublic() == enc.doubleratchet.dh:
194+
info "outgoing message, no need to handle", convo = convo.id()
195+
return
196+
197197
let plaintext = convo.decrypt(enc).valueOr:
198198
error "decryption failed", error = error
199199
return

src/chat_sdk/errors.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ type
88
ErrorCode* = enum
99
errTypeError
1010
errWrapped
11-
errDecryptOutgoing
12-
1311

1412
proc `$`*(x: ChatError): string =
1513
fmt"ChatError(code={$x.code}, context: {x.context})"

src/naxolotl/naxolotl.nim

Lines changed: 4 additions & 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
@@ -187,3 +187,6 @@ func initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRem
187187

188188
if isSending:
189189
result.dhRatchetSend()
190+
191+
func dhSelfPublic*(self: Doubleratchet): PublicKey =
192+
self.dhSelf.public

0 commit comments

Comments
 (0)