Question

Je suis en train d'élaborer un client SSL qui va faire une simple demande à un serveur SSL et attendre la réponse.Le handshake SSL et l'écriture se passe bien mais je ne peux pas LIRE les données à partir de la douille.J'ai activé le debug de java.net.ssl et le suivant:

[..] 
main, READ: TLSv1 Change Cipher Spec, length = 1 
[Raw read]: length = 5 0000: 16 03 01 00 20                 .... 
[Raw read]: length = 32 [..] 
main, READ: TLSv1 Handshake, length = 32 Padded plaintext after DECRYPTION:  len = 32 
[..]
    *** Finished verify_data:  { 29, 1, 139, 226, 25, 1, 96, 254, 176, 51, 206, 35 }
    *** %% Didn't cache non-resumable client session: [Session-1, SSL_RSA_WITH_RC4_128_MD5] [read] MD5 and SHA1 hashes:  len = 16 0000: 14 00 00 0C 1D 01 8B E2   19 01 60 FE B0 33 CE 23  ..........`..3.# Padded plaintext before ENCRYPTION:  len = 70 [..]                               a.j.y. 
main, WRITE: TLSv1 Application Data, length = 70 
[Raw write]: length = 75 
[..] 
Padded plaintext before ENCRYPTION:  len = 70 
[..] 
main, WRITE: TLSv1 Application Data, length = 70 
[Raw write]: length = 75 
[..] 
main, received EOFException: ignored main, called closeInternal(false) main, SEND TLSv1 ALERT:  warning, description = close_notify Padded plaintext before ENCRYPTION:  len = 18 [..] 
ain, WRITE: TLSv1 Alert, length = 18 [Raw write]: length = 23 
[..] main, called close() 
main, called closeInternal(true) 
main, called close() 
main, called closeInternal(true)

Le [..] sont la chaîne de certificats.

Voici un extrait de code:

try {
            System.setProperty("javax.net.debug","all");
            /*
             * Set up a key manager for client authentication
             * if asked by the server.  Use the implementation's
             * default TrustStore and secureRandom routines.
             */
            SSLSocketFactory factory = null;
            try {
            SSLContext ctx;
            KeyManagerFactory kmf;
            KeyStore ks;
            char[] passphrase = "importkey".toCharArray();

            ctx = SSLContext.getInstance("TLS");
            kmf = KeyManagerFactory.getInstance("SunX509");
            ks = KeyStore.getInstance("JKS");

            ks.load(new FileInputStream("keystore.jks"), passphrase);

            kmf.init(ks, passphrase);
            ctx.init(kmf.getKeyManagers(), null, null);

            factory = ctx.getSocketFactory();
            } catch (Exception e) {
                throw new IOException(e.getMessage());
            }

            SSLSocket socket = (SSLSocket)factory.createSocket("server ip", 9999);

            /*
             * send http request
             *
             * See SSLSocketClient.java for more information about why
             * there is a forced handshake here when using PrintWriters.
             */
            SSLSession session = socket.getSession();

            [build query]

            byte[] buff = query.toWire();

            out.write(buff);
            out.flush();

            InputStream input = socket.getInputStream();

            int readBytes = -1;
            int randomLength = 1024;
            byte[] buffer  = new byte[randomLength];
            while((readBytes = input.read(buffer, 0, randomLength)) != -1) {
                LOG.debug("Read: " + new String(buffer));
            }
            input.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

Je peux écrire plusieurs fois et je n'ai pas d'erreur mais le EOFException arrive sur la première lecture.

Suis-je en train de faire quelque chose de mal avec la douille ou avec l'authentification SSL?

Je vous remercie.

Était-ce utile?

La solution

Le problème était avec le paquet j'ai été l'envoi.Le serveur a été d'obtenir le paquet, vérifier qu'elle était une mauvaise mise en forme et la suppression de la connexion.La fixation du format de paquet résolu le problème.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top