this post was submitted on 28 Apr 2024
1 points (100.0% liked)

Security

4914 readers
2 users here now

Confidentiality Integrity Availability

founded 4 years ago
MODERATORS
 

There’s a server, a client, and a hacker in a network. For encryption, the client and the server need to share their private keys. Wouldn’t the hacker be able to grab those during their transmission and decrypt further messages as they please?

top 6 comments
sorted by: hot top controversial new old
[–] RegalPotoo@lemmy.world 0 points 3 months ago (2 children)

You've missed a key detail in how asymmetric encryption works:

  • For asymmetric encryption algorithms, you essentially have two keys - a "private" key, and a "public" key
  • If you know the private key it is trivial to calculate the public key, but the reverse isn't true - just given the public key, it is essentially impossible to calculate the private key in a reasonable amount of time
  • If you encrypt something with the public key you must use the private key to decrypt it, and if you encrypt with the private key you can only use the public key for decryption
  • This means that my server can advertise a public key, and you can use that to encrypt the traffic so that only the server that knows the private key can decrypt it
[–] sukhmel@programming.dev 0 points 3 months ago (1 children)

I used to know that and still struggle to understand how a handshake wouldn't allow MitM. Later I found out that it requires a third party with a trusted and known certificate for signing handshake exchange messages in order to ensure there's no man in the middle: https://stackoverflow.com/a/10496684

[–] Turun@feddit.de 0 points 3 months ago

Yes, that's why https needs certificates (and sometimes shows a broken lock) and why you need to accept the fingerprint when first connecting to a server via ssh.

[–] Turun@feddit.de 0 points 3 months ago* (last edited 3 months ago) (1 children)

Just a nitpick:

If you know the private key it is trivial to calculate the public key, but the reverse isn't true

~~The public key and the private key are just two big prime numbers. The "trivial to compute" part only works once more information has been shared over the network, like it happens during key exchange. If you were to swap the prime number before initiating any contact it would work the same way.~~

Edit: I probably confused different encryption concepts

[–] RegalPotoo@lemmy.world 0 points 3 months ago (1 children)

In RSA, the private key is a pair of big semi-primes, and the public key is derived from those numbers. I think you are confusing DHKE and RSA with your other points, the private key is never transmitted over the network. For TLS you typically use an asymmetric crypto system to validate identities and encrypt the key exchange to prevent person-in-the-middle, but the key that is agreed using that process is a symmetric key for AES or similar, but that is specific to TLS.

Also, there are other asymmetric systems that don't use primes at all - eliptic curve crypto is based on completely different math

[–] Turun@feddit.de 0 points 3 months ago

Oh, I may actually have confused that. Thanks for pointing it out.