How does a Certificate Authority send a private key safely to a consumer? - private-key

How does a Certificate Authority send the private key securely to their consumer?

Related

Possibility to bypass the Certificate Verify in mutual authentication (mTLS)

In the TLS handshake process, the Certificate Verify message will follow the Client Key Exchange message after the server requested a client certificate. The Certificate Verify contains a digital signature computed over all previous handshake messages including the type and length fields of the handshake messages. This process allows the client to prove that it owns the private key of the client certificate it sends to the server.
The idea came from a practical problem. There is an mTLS enabled server that conducts different action policies based on the client certificate received, for example, different welcome pages for different client certificates. If a layer-7 reverse proxy service like the load balancer is placed in front of the proxied server which also requires decrypting the TLS traffic. The proxied server can only get the client certificate information from the HTTP header (for example, set proxy_set_header with $ssl_client_cert variable in NGINX) which requires modifying the logic of the server.
A simple but very troublesome solution is the reverse proxy service stores all the client certificates and their private keys. The reverse proxy service will use the same client certificate it received during the mTLS handshake process to establish the mTLS connection with the proxied server.
Since the reverse proxy service can choose whether to trust the client or not with its own implementation, it is possible to forge the Certificate Verify message by asking the client to send a second Certificate Verify signature when the proxied server needs the reverse proxy service to do so (I know it's like a man-in-the-middle attack)?

ssh between client and server : How does server decrypt the data send by client to it?

I am trying to understand SSH mechanics; as I understand, using ssh we can secure connection between a client and server.
A client will create private and public key (say using ssh-keygen); pass on public key to server.
Now, we have this flow:
Client -> Server; the client has both pair of keys, so if server sends data (which is being encrypted by public key, then the client can decrypt it); but how does server decrypt the data which is being sent from the client -> server; the client will use the public key to encrypt the data; since the server has only the public key, how does it decrypt the data which client sends to it?
Server -> Client; the server has only public key; so I think this is ok; the server will use the public key to encrypt the data, and then a client will use its private key to decrypt the data.
but how does server decrypt the data which is being sent from the client -> server
Because after the server is verified, both the parties negotiate a session key using a version of something called the Diffie-Hellman algorithm.
This algorithm is designed in such a way that both the parties contribute equally in generation of session key.
The generated session key is shared symmetric key i.e. the same key is used for encryption and decryption.
See more at "Understanding SSH workflow" from Mudit Maheshwari
And "SSH (Key gen)":

HTTPS and MITM attack

I plan to run the logged-in portion of my app in HTTPS, starting with from the log-in screen. Once the user is logged-in and continues his session entirely in HTTPS, how could a MITM attack be performed? Isn't this kind of attack dependent on figuring out what the two parties are saying?
I'm using asp.net with WCF services, and later will port to Azure.
Thanks.
If your login session is encrypted with HTTPS, then you're secure against MITM attacks. The client will send data to the server encrypted using the server's public key, which can only be decrypted with the server's private key. The client and server will then use this secure channel to agree on a secret key to use for their communication.
The MITM attacker cannot get at the private key because it's private. They can't present a certificate for the target domain because certificates can only be obtained from a CA, and (theoretically) the CAs your browser trusts won't sign a certificate for a domain unless they prove they own it. They can't get at the session key, so a MITM attack is impossible.

How does simple SSL accomplish server-to-client communication?

Does an SSL server randomly generate a temporary key pair for every client that connects?
I understand how public-key encryption works -- public encryption key, secret decryption key. That explains how a host with an SSL certificate can receive encrypted data from a client. But how does an SSL server send encrypted data back to the client?
(There was a discussion on this topic in this question, although it was edited a number of times, so it may be confusing.)
The public key in the server certificate is only used during the handshake.
During the handshake, the client and server negotiate a secret shared key (a new one for each session) that they use for the actual encryption.
How this secret is negotiated depends on the cipher suite: RSA or Diffie-Hellman key exchange. When using RSA key exchange, the client encrypts the pre-master-secret and sends it to the server (who is the only one able to decrypt it). When using DH, the client verifies the signature of the temporary parameters sent by the server during the DH exchange: the end result is also a shared pre-master-secret. This is then used with the exchanged random values by both parties to compute the master secret.
There are more details in the TLS specification section called "Handshake Protocol Overview".

SSL works without Client certificate

There is something I don't understand, When I don't put certificate at all, the SSL connection is established successfully, I wonder how the server decrypt the message without client certificate.
What is client side certificate is for?
Thanks
As I understand it (the 15000 metre view.)
The server has a public key it publishes in its cert. This is used by your browser to encrypt everything it sends. Only the server can decrypt the info as only it (hopefully) has the private key.
If you have a client cert then you give this to the server to ensure that it encrypts stuff to you so only you can decrypt it (again with your private key).
So to me: You can send your credit card info completely freely, knowing that only the server can read it. The client can either then send a proper cert or create a 'temp' one for the session and then the 'public' encryption key to the server secure in the knowledge that no one else will have sent it. Then the comms are encrypted both ways, but separately.
Now from here
A TLS client and server negotiate a
stateful connection by using a
handshaking procedure. During this
handshake, the client and server agree
on various parameters used to
establish the connection's security.
The handshake begins when a client
connects to a TLS-enabled server
requesting a secure connection, and
presents a list of supported
CipherSuites (ciphers and hash
functions).
From this list, the server
picks the strongest cipher and hash
function that it also supports and
notifies the client of the decision.
The server sends back its
identification in the form of a
digital certificate. The certificate
usually contains the server name, the
trusted certificate authority (CA),
and the server's public encryption
key.
The client may contact the server
that issued the certificate (the
trusted CA as above) and confirm that
the certificate is authentic before
proceeding.
In order to generate the
session keys used for the secure
connection, the client encrypts a
random number (RN) with the server's
public key (PbK), and sends the result
to the server. Only the server should
be able to decrypt it (with its
private key (PvK)): this is the one
fact that makes the keys hidden from
third parties, since only the server
and the client have access to this
data. The client knows PbK and RN, and
the server knows PvK and (after
decryption of the client's message)
RN. A third party may only know RN if
PvK has been compromised. From the
random number, both parties generate
key material for encryption and
decryption.
This concludes the
handshake and begins the secured
connection, which is encrypted and
decrypted with the key material until
the connection closes.
This wikipedia article probably gives more info than you'll ever want.
Think about certificate not in terms of encrypting-decrypting, but in terms of authentication. Encryption can be done without certificates at all - just knowing open key is enough. But certificate contains different fields, among them is personality of certificate owner. For web this value is the domain name of the server you wish to connect to. As there are means to check that IP address of the server is always equal to name stated in certificate (forward and backward DNS requests), you can be sure that you're talking to the one you wish to.
In this terms, client certificate issue should be much simpler to understand. Client certificate allows server to authenticate client, so the authentication will be mutual. Server could check, for example, that the client certificate is valid (not expired, not black-listed, etc.).
Using a certificate from either the server or the client will give the endpoints a means of exchanging a shared secret (a symmetric encryption key - or seed).
A secondary purpose for the certificate (and one that's much less well-leveraged these days, relative to "encrypting the channel between endpoints") is to authenticate the endpoint supplying their digital certificate (using the cert and the proof of possession that they also send).
The overwhelming majority of SSL transactions these days are effectively only worried about the "encryption of the channel", not to authenticate the endpoint. (Practically speaking, it's a side benefit on the commercial internet, though the mass of man-in-the-middle attacks out there give us increasing incentive to try to figure out how to really know you're talking to the server - or client - that you think you are.)
In other words, the client certificate would be useful to authenticate (in a more or less "stronger" manner) that the server is interacting with either (a) a "more trusted" client (if all you were doing was ensuring that the cert is among a pool of certs you trust - e.g. mapped to an LDAP/AD directory of users you deem "trusted", or issued from a CA whose issuing practices you "trust") or (b) a specific user that you authenticate (e.g. again, through an LDAP/AD database of user, one - or more uncommonly, or more - of which has been mapped to that certificate through some automated or out-of-band - but either way, hopefully a sufficiently secure - process).

Resources