mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
chore: not expose private dh key.
This commit is contained in:
parent
523dca43e1
commit
622fe0a78b
@ -94,10 +94,6 @@ 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) ))
|
||||
|
||||
|
||||
@ -194,6 +190,10 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T,
|
||||
let enc = decode(bytes, EncryptedPayload).valueOr:
|
||||
raise newException(ValueError, fmt"Failed to decode EncryptedPayload: {repr(error)}")
|
||||
|
||||
if convo.doubleratchet.dhSelfPublic() == enc.doubleratchet.dh:
|
||||
info "outgoing message, no need to handle", convo = convo.id()
|
||||
return
|
||||
|
||||
let plaintext = convo.decrypt(enc).valueOr:
|
||||
error "decryption failed", error = error
|
||||
return
|
||||
|
||||
@ -8,8 +8,6 @@ type
|
||||
ErrorCode* = enum
|
||||
errTypeError
|
||||
errWrapped
|
||||
errDecryptOutgoing
|
||||
|
||||
|
||||
proc `$`*(x: ChatError): string =
|
||||
fmt"ChatError(code={$x.code}, context: {x.context})"
|
||||
|
||||
@ -16,7 +16,7 @@ const maxSkip = 10
|
||||
|
||||
|
||||
type Doubleratchet* = object
|
||||
dhSelf*: PrivateKey
|
||||
dhSelf: PrivateKey
|
||||
dhRemote: PublicKey
|
||||
|
||||
rootKey: RootKey
|
||||
@ -187,3 +187,6 @@ func initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRem
|
||||
|
||||
if isSending:
|
||||
result.dhRatchetSend()
|
||||
|
||||
func dhSelfPublic*(self: Doubleratchet): PublicKey =
|
||||
self.dhSelf.public
|
||||
Loading…
x
Reference in New Issue
Block a user