I have a question, or rather multiple questions that all relate to the same topic.
I am building an application with both a frontend (FE) and a backend (BE). All communication between FE and BE is protected with TLS. The BE contains an endpoint on which the frontend can register a new session. When setting up such a new session, a few things happen:
- FE sends a request (TLS protected) to BE, sharing a Curve25519 public key from a freshly generated Curve25519 keypair.
- BE receives this request. Creates a new Curve25519 keypair, uses HKDF to calculate a shared secret (using as input FE public key, BE private key and a salt) and ultimately create a new symmetric session key (ChaCha20-Poly1305)
- BE creates a new 32-byte (256-bit) session ID and keeps it in memory together with the session key.
- BE sends back the session ID + salt + public key from freshly generated Curve25519 keypair.
- FE uses BE public key + salt + FE private key to calculate same secret and create the session key.
Again I want to emphasise all of the above communication (so the request + response) happens over TLS. For all future communication, FE will encrypt all requests using the session key. The encrypted request is encoded to base64, and put in a JSON request body together with the unencrypted sessionID:
"encryptedRequest: "base64 encrypted request"
These requests are then send (along with the unencrypted session ID) over a TLS connection, resulting in double encryption. When BE receives these requests, it will lookup the required session key by using the provided session ID. Then, it will decrypt the
encryptedRequest field and forward it to the appropriate endpoint.
Some questions I have with this setup are:
- Because all requests are encrypted with the session key, can that act as a form of proof that the client is the real owner of the session ID? e.g. If the session ID somehow is stolen, it can still not be used to communicate to the backend as you still would need to have ownership over the shared secret.
- How much added security does this setup give if for some reason the TLS connection is broken into? (e.g. due to MITM, or because the TLS-level encryption is broken)
- Does this setup aid in API obfuscation? E.g. client-side you can install software that - prior to TLS encryption occurring - can inspect all incoming and outgoing traffic. For my application, they would only see requests that are already encrypted. Is it easy to work around this?
I'm curious about what you guys think. I've been experimenting a bit with these topics (i'm by no means a cryptography expert) and I would love to learn more.