"unable to find valid certification path to requested target" in 4.0.0-rc2

I’d like to connect to the palita.net.

But I can’t…

config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);

config.setDebuggerEnabled(true);

SSLContext sc = SSLContext.getInstance (“TLSv1.2”) ;

sc.init (null,null,null) ;

config.setCustomSSLContext(sc);

connection = new XMPPTCPConnection(config);

connection.connect();

It is doesn’t work:

Exception in thread “main” org.jivesoftware.smack.SmackException$ConnectionException

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:431)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:799)

at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:391)

at tls_connect.TLS_connect.main(TLS_connect.java:72)

Java Result: 1

Pls help, how in 4.0.0-rc2 I have to connect to the server?..

Sorry, was bug in code.

Now error is:

Exception in thread “main” javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Your SSLContext does not trust the certificate of the server.

and how it can be fixed?

By using a SSLContext that accepts the server certificate or by using a server certificate that is accepted by the SSLContext.

May you show the example please?

No, because I don’t know your constraints for accepting the certificate.

I’m pretty sure you will find all the information that you need about (X509)TrustManagers and SSLContext online. The topic is rather complex and I guess you will have to do some reading. There are some open source XMPP apps that use aSmack which you can study.

Hi Anton,

What was the bug in your code and how did you fix it? I am getting the same error while trying to just connect.

thanks!

XMPPConnection conn = new XMPPTCPConnection(“127.0.0.1”);

try {

conn.connect();

} catch (SmackException e) {

e.printstacktrace;

}

Exception in thread “main” org.jivesoftware.smack.SmackException$ConnectionException

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:431)

Hi.

You should let see us more code.

I believe you a lot of code.

In my code was the rewriting rows.

You can also configure your connection for not using security. Something like this

ConnectionConfiguration config = new ConnectionConfiguration(“palita.net”);

config.setSecurityMode(SecurityMode.disabled);

XMPPConnection connection = new XMPPTCPConnection(config);

connection.connect();

I’m not very good at english