Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Connection to an SSL socket server

Thread view: 
max@utm-appliance.com - 01 May 2006 16:50 GMT
I try to establish a connection to a SSL socket server , by using ssl
socket client (code below) and I got an exception, can you help me pls?
The server is ok I did a connection with sslopen client.
thanks

public class ClientSSL {
    static int port = 1111;

    static String hostname = "myIP";

    public static void main(String[] arstring) {
        try {
            SSLSocketFactory sslsocketfactory =(SSLSocketFactory) SSLSocketFactory
                    .getDefault();
            SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(
                    hostname, port);
            String[] prot = new String[1];
            prot[0]="SSLv3";
       sslsocket.setEnabledProtocols(prot);
           
           String[] newcipher = new String[1];
           newcipher[0]="TLS_DH_anon_WITH_AES_128_CBC_SHA";
   
           sslsocket.setEnabledCipherSuites(newcipher);   
       
           String[] cipher = sslsocket.getEnabledCipherSuites();
           for(int i=0;i<cipher.length;i++){
               System.out.println(cipher[i]);
           }

            OutputStream outputstream = sslsocket.getOutputStream();
            BufferedOutputStream outbuff = new BufferedOutputStream (outputstream);

            byte[] test = new byte[4];
            test[0]=8;
            test[1]=1;
            test[2]=3;
            test[3]=6;       

            outbuff.write(test);
            outbuff.flush();
            sslsocket.close();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

}

output:
TLS_DH_anon_WITH_AES_128_CBC_SHA

javax.net.ssl.SSLException: java.lang.RuntimeException: Could not
generate DH keypair
    at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:166)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal
(SSLSocketImpl.java:1476)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal
(SSLSocketImpl.java:1443)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException
(SSLSocketImpl.java:1426)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write
(AppOutputStream.java:64)
    at java.io.BufferedOutputStream.flushBuffer
(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at ClientSSL.main(ClientSSL.java:58)
Caused by: java.lang.RuntimeException: Could not generate DH keypair
    at com.sun.net.ssl.internal.ssl.DHKeyExchange.generateKeyPair
(DHKeyExchange.java:137)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.getDHephemeral
(ClientHandshaker.java:370)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverKeyExchange
(ClientHandshaker.java:385)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage
(ClientHandshaker.java:121)
    at com.sun.net.ssl.internal.ssl.Handshaker.processLoop
(Handshaker.java:495)
    at com.sun.net.ssl.internal.ssl.Handshaker.process_record
(Handshaker.java:433)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord
(SSLSocketImpl.java:815)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake
(SSLSocketImpl.java:1025)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord
(SSLSocketImpl.java:619)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write
(AppOutputStream.java:59)
    ... 3 more
Caused by: java.security.InvalidAlgorithmParameterException: Prime size
must be multiple of 64, and can only range from 512 to 1024 (inclusive)
    at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DashoA6275)
    at java.security.KeyPairGenerator$Delegate.initialize
(KeyPairGenerator.java:609)
    at java.security.KeyPairGenerator.initialize(KeyPairGenerator.java:351)
    at com.sun.net.ssl.internal.ssl.DHKeyExchange.generateKeyPair
(DHKeyExchange.java:123)
    ... 12 more
Rogan Dawes - 01 May 2006 21:18 GMT
> I try to establish a connection to a SSL socket server , by using ssl
> socket client (code below) and I got an exception, can you help me pls?
> The server is ok I did a connection with sslopen client.
> thanks

>             newcipher[0]="TLS_DH_anon_WITH_AES_128_CBC_SHA";

> output:
> TLS_DH_anon_WITH_AES_128_CBC_SHA
>
> javax.net.ssl.SSLException: java.lang.RuntimeException: Could not
> generate DH keypair

> Caused by: java.security.InvalidAlgorithmParameterException: Prime size
> must be multiple of 64, and can only range from 512 to 1024 (inclusive)

Looks like there is some problem with the size of the prime you are
using. Do you HAVE to use "DH_anon"? Could you not allow the SSL/TLS
suite to negotiate a shared algorithm?

You may also want to look at http://dawes.za.net/rogan/PKCS11Test.java,
which shows a whole bunch of client-side SSL-related techniques in a
simple example. Some may be of use to you.

Regards,

Rogan


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.