B4J Question http to https (SSL)

Status
Not open for further replies.

M.SALIM

Member
I have written a webservice. The software is working fine when calling http but fail on https.

I'm having this error on my PC:
"javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"​
NB: I have used Openssl to create the certificate and java keytool to generate the keystore file.

Please assist.

The sample code is as follows:

SERVER CODE:
Sub Process_Globals
    Private srvr As Server
End Sub

Sub AppStart (Args() As String)
    
    srvr.Initialize("srvr")
    ConfigureSSL(443)
    srvr.LogsFileFolder = File.Combine(File.DirApp, "logs")
    srvr.AddHandler("/demo/*", "DemoHandler", False)
    srvr.Start
    Log("Server started")
    StartMessageLoop
End Sub

Private Sub ConfigureSSL (SslPort As Int)
    Dim ssl As SslConfiguration
    ssl.Initialize
    ssl.SetKeyStorePath(File.DirApp,"jetty.keystore")
    ssl.KeyStorePassword = "123456"
    srvr.SetSslConfiguration(ssl, SslPort)
End Sub
CLIENT CODE:
Private Sub Button1_Click
    Dim Result As String
    Dim url    As String ="http://127.0.0.1:56056/demo/echoparams?param1=1&param2=Test"
    Dim j      As HttpJob
    Try
        j.Initialize("",Me)
        j.PostString(url, "TEST")
        j.GetRequest.SetContentType("application/json")
        j.GetRequest.SetHeader("param1", "111")
        j.GetRequest.SetHeader("param2", "222")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        Else
            Result = j.ErrorMessage
        End If
    Catch
        Log(LastException)
    End Try
    
    Log(Result)
    j.Release
End Sub
 

Magma

Expert
Licensed User
Longtime User
Hmm.. Maybe trying this...


Don't remember if it is a home made generated ssl must use it.
 
Upvote 1

M.SALIM

Member
Hmm.. Maybe trying this...


Don't remember if it is a home made generated ssl must use it.
still not working
 
Upvote 0

M.SALIM

Member
I have written a webservice. The software is working fine when calling http but fail on https.

I'm having this error on my PC:
"javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"​
NB: I have used Openssl to create the certificate and java keytool to generate the keystore file.

Please assist.

The sample code is as follows:

SERVER CODE:
Sub Process_Globals
    Private srvr As Server
End Sub

Sub AppStart (Args() As String)
  
    srvr.Initialize("srvr")
    ConfigureSSL(443)
    srvr.LogsFileFolder = File.Combine(File.DirApp, "logs")
    srvr.AddHandler("/demo/*", "DemoHandler", False)
    srvr.Start
    Log("Server started")
    StartMessageLoop
End Sub

Private Sub ConfigureSSL (SslPort As Int)
    Dim ssl As SslConfiguration
    ssl.Initialize
    ssl.SetKeyStorePath(File.DirApp,"jetty.keystore")
    ssl.KeyStorePassword = "123456"
    srvr.SetSslConfiguration(ssl, SslPort)
End Sub
CLIENT CODE:
Private Sub Button1_Click
    Dim Result As String
    Dim url    As String ="https://127.0.0.1:56056/demo/echoparams?param1=1&param2=Test"
    Dim j      As HttpJob
    Try
        j.Initialize("",Me)
        j.PostString(url, "TEST")
        j.GetRequest.SetContentType("application/json")
        j.GetRequest.SetHeader("param1", "111")
        j.GetRequest.SetHeader("param2", "222")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        Else
            Result = j.ErrorMessage
        End If
    Catch
        Log(LastException)
    End Try
  
    Log(Result)
    j.Release
End Sub

still not working
Actually the url line should read Dim url As String ="https://127.0.0.1/demo/echoparams?param1=1&param2=Test"
 
Upvote 0

M.SALIM

Member
Actually the url line should read Dim url As String ="https://127.0.0.1/demo/echoparams?param1=1&param2=Test"
im having this error on my web page:
1712263287974.png
 
Upvote 0

M.SALIM

Member
Correct. Got it working via the default 443.
Now I have another issue when compiling the server as standalone, it does not run at all on port ConfigureSSL(443).
The screen flashes and exits.
However, it does run with a normal port (i.e. srvr.Port = ????) without ConfigureSSL(????).

Please advise.
 
Upvote 0
Status
Not open for further replies.
Top