B4J Question SSL and SHA1 SHA2 RSA DSA

Swissmade

Well-Known Member
Licensed User
Longtime User
Hi All,
I have a IO-Box that can create a Self-signed SSL certificate.
The IO-Box uses a XPort-Pro from Lantronics to connect to the Network.
Now I like to connect to this with a TCPSocket.
To Connect I like to use socket.InitializeSSL.
How can I tell the Socket to accept a Self-signed certificate.

I have seen this https://www.b4x.com/android/forum/threads/network-v1-50-adds-support-for-ssl-sockets.55871/
But I don't see how to give a Self-signed certificate
Many thanks to helping me out here.
 
Last edited:

Swissmade

Well-Known Member
Licensed User
Longtime User
Bad don't get it working.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
I have a sslcert.pem and sslkey.pem upload to the x-port and working.
This certificates I have build with OpenSSL.
How can I use this with the Socket.InitializeSSL.

Please help.
Thanks
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Were you able to create a keystore file?
No Not yet
I have made a keystore like this.
openssl pkcs12 -export -name servercert -in sslcert.pem -inkey sslkey.pem -out myp12keystore.p12

Bad is, that I still can not connect to the Xport.


Thanks Erel for your help.
 
Last edited:
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
If I try to connect I get this error
Waiting for debugger to connect...
Program started.
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
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at anywheresoftware.b4a.objects.SocketWrapper$1.run(SocketWrapper.java:142)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
... 13 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
... 19 more
Something Wrong with connection
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Source I us to connect

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Sock As Socket
    Private AsyncSock As AsyncStreams
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    Dim in As InputStream = File.OpenInput(File.DirAssets, "Entrada-keystore.p12")
    Sock.InitializeSSL("Sock", in, "Born to be wild")
    setprotocol
'    Sock.Initialize("Sock")
    Sock.Connect("192.168.1.205", 10001, 5000)
End Sub

private Sub Sock_Connected (Successful As Boolean)
    If Successful = True Then
        Log("Whe have Connection")
    Else
        Log("Something Wrong with connection")       
    End If
   
End Sub

Private Sub setprotocol
    Dim r As Reflector
    r.Target = Sock 'socket variable
    r.Target = r.GetField("socket")
    r.RunMethod4("setEnabledProtocols", Array(Array As String("TLSv1.1", "SSLv3")), _
     Array As String("[Ljava.lang.String;"))
End Sub
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
You should convert to to a keystore. It will not work in other formats

I assume that I have done this with this command.
openssl pkcs12 -export -name servercert -in sslcert.pem -inkey sslkey.pem -out Entrada-keystore.p12
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Bad not working also with Keystore file.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Still not working,
Steps I have done.
With OpenSSL
First I create a Cert and Private key file.
Then I Create a keypair with password openssl pkcs12 -export -name servercert -in sslcert.pem -inkey sslkey.pem -out Entrada-keystore.p12
Last I create a keystore file from the p.12 file with keytool.

The certificate and Private key working in the XPort.
I don't know what's still going wrong here.
Still get a javax.net.ssl.SSLHandshakeException
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…