Do we always use Asymmetrical Encryption?
- Now most people assume that we use Asymmetrical Encryption in all types of SSH connections entirely which isn't wholly accurate.
- Actually, this connection is only used during the Key Exchange Algorithm of Symmetric Encryption.
- If you can recall, we only need one key to be exchanged for the entire connection in Symmetrical Encryption, so we use Asymmetrical encryption only to exchange that key in a secure fashion.
- So, Whenever a new SSH connection is being initiated, both parties generate temporary public and private keys and share the respective public keys with one another at this point, we are able to get the symmetric key so we can exchange information using something called
Diffie Hellman Key Exchange.
Diffie Hellman Key Exchange: Makes it possible for each party to combine their own private data with public data from other systems to arrive at an identical secret session key. Woah! 🥵 seems confusing? Don't worry I am attaching a few resources which you can use to understand it better. ☺️
- By now we should know how we are able to generate a symmetric key using asymmetrical encryption, using the Diffie Hellman Key Exchange. And in this way, the Symmetrical Key is going to stay private to us.
Isn't it kind of funny?
- That is the name of the "Key Exchange" because we aren't actually exchanging the keys 🥹otherwise, it will be out in the public which we never want to happen! we actually just share pieces of public variables such as our public keys from each computer and we generate the key separately in our own private space.
Also, now you might be thinking: Fine! enough about all these encryptions 🥲
But trust me, these types of encryptions are everywhere!
You are probably using it right now while reading this blog!
To read this blog, you are using Diffie Hellman Key Exchange or when we use our phone to use anything when it connects to a server, it uses Diffie Hellman Key Exchange, and as a developer, we should know how these things work, right? and not just on the surface level.🥹
So to summarize we learned everything till now, SSH uses both symmetric and asymmetric encryption, since asymmetric encryption is more time-consuming most SSH connections use symmetric encryption as we have discussed.
The idea behind this is that asymmetric encryption is used to share only the public key. Then finally, use that key symmetric encryption for further communication, so it's swift.
Once secure symmetric communication has been established. The Server uses the client's public key and generates a challenge which is transmitted to the client for authentication. If the client successfully decrypts the message, the client holds the private key required for connection, and the session finally begins.
There is again one issue in this whole connection. What if a third party tries to act as the client or server and temper or modify the data if they somehow convince the client that they are the host or vice versa they can exchange the keys with them and the information can flow thru that middle man.
To solve this issue, we will talk about something called hashing.