customer SSL for smtp

hello

I have a code it does not work and which enables to send an email via the server smtp.my problem it is that in my code I do not know how to negotiate the keys and the certificates of my server.

String trustStorefile ="java.home"/lib/security/cacerts";

String pwd ="changeit";

String protocol ="smtp";

String socketFactory ="javax.net.ssl.SSLSocketFactory";

String smtpAuth ="true";

String strport ="25";

String username ="toto";

String Password ="xxxxx";

String serveur ="smtp.xxx.xx.xx";

Properties props = System.getProperties();

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

System.setProperty("javax.net.ssl.trustStore", trustStorefile);

System.setProperty("javax.net.ssl.keyStorePassword", pwd);

Security.setProperty("ssl.SocketFactory.provider","DummySSLSocketFactory");

props.setProperty("mail.transport.protocol",protocol);

props.setProperty("mail.smtp.port",strport);

props.setProperty("mail.smtp.starttls.enable","true");

props.setProperty("mail.smtp.auth", smtpAuth);

props.setProperty("mail.smtp.socketFactory.class", socketFactory);

props.setProperty("mail.smtp.socketFactory.fallback","false");

props.setProperty("mail.smtp.socketFactory.port",strport);

session = Session.getInstance( props);

URLName url =new URLName(protocol, serveur, Integer.parseInt(strport),"", username, Password);

com.sun.mail.smtp.SMTPSSLTransport transport =new com.sun.mail.smtp.SMTPSSLTransport(session, url);

transport.setStartTLS(true);

session.setDebug(true);

.....

thank you to help me.

[2616 byte] By [salim1981a] at [2007-11-27 5:22:31]
# 1

> my problem it is

> that in my code I do not know how to negotiate the

> keys and the certificates of my server.

SSL does that. You don't have to do anything about it as long as your truststore trusts the server certificate as described in http://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html.

> Properties props = System.getProperties();

> Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());

> System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");

The above two lines haven't been necessary since JDK 1.4.

> Security.setProperty(

> "ssl.SocketFactory.provider","DummySSLSocketFactory");

What on earth is that for? Delete it. Delete it now. Do not pass GO. Do not collect $200.

ejpa at 2007-7-12 11:47:56 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2

thank you for your help.but i want to know that:

- if I want to integrate in my code what in SSLSocketClientWithClientAuth for sample code. does the value have to give for passphrase it is changeit and directory of cacerts for testkeys?

- not need to create a certificate for customer.

salim1981a at 2007-7-12 11:47:56 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3

I created a certificate customer with keytool:keytool -genkey -keyalg rsa -alias jaworski

and Iexported it :keytool -export -alias jaworski -file jj.cer.

but I can't imported it (keytool -import -alias jaworski -file jj.cer) and i have exception:keytool error: java.lang.Exception: Certificate reply and certificate in keystore are identical.

I think that it will be necessary to convert the certificate into signed certificate.could give me the steps has to follow to sign my certificate?

thinks.

Message was edited by:

salim1981

salim1981a at 2007-7-12 11:47:56 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...