B4J Question [CLOSED] VPS or KeyStore : SocketException: Permission denied

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
I am calling to Linux experts, please. I have setup a new VPS and am facing a problem I never experienced. It is OpenVZ based, perhaps the reason for my problem ?

Each time I had started the B4J server, I have got a "permission denied" error.

I have reduced the project to its maximum minimum

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
 #CommandLineArgs:
 #MergeLibraries: True
#End Region
Sub Process_Globals
 Public srvr As Server
 Public portNonSSL As Int = 8080
 Public portSSL As Int = 443
 Public sslconf As SslConfiguration
 Public sslAvailable As Boolean
 Public keyPassword As String = myPassword
End Sub
Sub AppStart (Args() As String)
 srvr.Initialize("srvr")
 srvr.Port=portNonSSL
 sslAvailable=ConfigurerSSL
 
 srvr.AddHandler("/hello","konnektor",False)
 
 If sslAvailable Then
  'add filter to redirect all traffic from http to https (optional)
  srvr.AddFilter("/*", "HttpsFilter", False)
 End If
 srvr.Start
 StartMessageLoop
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
 Return True
End Sub
Sub ConfigurerSSL As Boolean
 If File.Exists("/home/alc/","jetty.keystore") Then
  sslconf.Initialize
  sslconf.SetKeyStorePath("/home/alc","jetty.keystore")
  sslconf.KeyManagerPassword=keyPassword
  sslconf.KeyStorePassword=keyPassword
  srvr.SetSslConfiguration(sslconf,portSSL)
  Return True
 Else
  Return False
 End If
End Sub

HttpsFilter
B4X:
'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
 If req.Secure Then
  Return True
 Else
  resp.SendRedirect(req.FullRequestURI.Replace("http:", "https:") _
       .Replace(Main.srvr.Port, Main.srvr.SslPort))
  Return False
 End If
End Sub

konnektor
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
  resp.Write(DateTime.Time(DateTime.Now))
End Sub

If I move the jetty.keystore file, the server can be accessed and doesn't generate any error. So, I guess it could be a problem with the keystore file.

Any idea ?

Many thanks


Edit: when I use another SSL port (not the usual one), the app doesn't crash anymore but the HttpsFilter doesn't work


> java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)


Edit 1 : seems to be a problem with OpenVZ because the same code (and configuration) work on KVM without a problem
I will cancel the OpenVZ VPS, that's all
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…