Java SSL sockets without authentication or stores?

I have two java applications that need to talk to each other through an encrypted TCP socket, but they do not need to authenticate each other (one of them will accept () a connection from the other). Can someone point me to a tutorial / code snippet that will help me tweak them?

I am looking for something fairly simple, and I would not want to provide key store material or trusted material.

EDIT: I have to be more specific here. I meant that they do not need to authenticate each other via SSL . I have non-trivial authentication that I have to perform at the application level, so I cannot use any SSL based authentication scheme.

In addition, some links in answers posted so far (starting noon on 3/10/2010) require keystore files. Is there an easy way I can programmatically generate the keys I need?

+4
source share
3 answers

Repeat Chris Jetter-Jung's recommendation - if you don’t have authentication, then you can communicate securely, but you don’t know who you are talking to. You could just communicate very well with the bad guy himself (who conveys everything you say to the person you hoped to speak directly).

However, there is a fairly lightweight authentication scheme that can meet your goals, called TOFU (Trust on First Use). Here you use SSL and generate self-signed certificates for each side - however, you will not miss certificate verification. Instead, the first time you connect to this partner, you accept any certificate and store it locally; on subsequent connections to this partner, you only accept this saved certificate. This is similar to how ssh works by default for host authentication and provides the authentication "the guy I'm talking to right now is the same guy I talked to yesterday."

+2
source

You can use the anonymous Diffie-Hellman cyperiums if you insist on ignoring Chris Jet-Jung's advice. These ciphersuites are not enabled by default, you must explicitly enable them, for example, using the SSLSocket.setEnabledCipherSuites() method.

+1
source

If you absolutely do not want to use SSL with certificates, you can minimize your own, although this is clearly not so secure. I'm just improvising here, mixing a little asymmetric crypto with a knock port.

First, create a random RSA key pair in the client, in memory, no need to store it anywhere. Then, the client connects to the server using a simple Socket, and when connected, sends the server a public key (encode as you wish, so that you can easily read it on the server). The server then generates a random 128-bit key, launches the ANOTHER ServerSocket on a random port and encrypts the 128-bit key and the new server port number using the client’s public key, and sends the data back to the client. The server must wait a short period of time to receive a connection from the same client on the new port.

The client closes the connection, decrypts the data, and opens a new Socket server on the specified port. Then both the client and server should wrap the InputStream and OutputStream socket on CipherInputStream and CipherOutputStream using AES / CBC / PKCS5Padding (or RC4, if you want) with the specified 128-bit key. Voilá, you have a secure connection between the client and server without authentication.

If you want to handle authentication, you can do it over a secure connection or on the first connection the server can have a pair of RSA keys, they exchange keys, and the server can send a call to the client (the server sends a call to the client using the client’s public key, and the client answers the call using a public server key). But this is unnecessarily complicated, and I think that you still better use standard SSL with key stores ... maybe you can create a KeyStore in memory on the server and send it to the server, as described above, using the first connection (encrypt the keystore with the public key of the server), and then you can configure a second connection to use SSL with this keystore, which is temporary and will be discarded when the client disconnects.

0
source

Source: https://habr.com/ru/post/1303614/


All Articles