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.
java -jar server.jar
2018-01-14 13:11:58.535:INFO::main: Logging initialized @432ms to org.eclipse.jetty.util.log.StdErrLog
2018-01-14 13:11:58.968:INFO:eek:ejs.Server:main: jetty-9.4.z-SNAPSHOT
2018-01-14 13:11:59.143:INFO:eek:ejs.session:main: DefaultSessionIdManager workerName=node0
2018-01-14 13:11:59.144:INFO:eek:ejs.session:main: No SessionScavenger set, using defaults
2018-01-14 13:11:59.150:INFO:eek:ejs.session:main: Scavenging every 600000ms
2018-01-14 13:11:59.163:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@5a61f5df{/,file:///home/alc/www/,AVAILABLE}
2018-01-14 13:11:59.179:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened /home/alc/logs/b4j-2018_01_14.request.log
2018-01-14 13:11:59.235:INFO:eek:ejs.AbstractConnector:main: Started ServerConnector@174d20a{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
main._appstart (java line: 67)
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:298)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:431)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:211)
at fr.srvr.server.test.main._appstart(main.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at fr.srvr.server.test.main.main(main.java:29)
main.main (java line: 29)
java.lang.RuntimeException: java.net.SocketException: Permission denied
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at fr.srvr.server.test.main.main(main.java:29)
Caused by: java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:298)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:431)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:211)
at fr.srvr.server.test.main._appstart(main.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
... 2 more

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

2018-01-14 15:07:37.118:INFO:eek:ejs.AbstractConnector:main: Started ServerConnecto r@36f6e879{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2018-01-14 15:07:37.121:INFO:eek:ejs.Server:main: Started @1202ms
2018-01-14 15:08:14.010:WARN:eek:ejh.HttpParser:qtp189568618-15: Illegal character 0x16 in state=START for buffer HeapByteBuffer@69ccff2a[p=1,l=206,c=8192,r=205]={ \x16<<<\x03\x03\x00\xC9\x01\x00\x00\xC5\x03\x03Z[\xB8\xAdaNo...\x00\x18\x00\x06\ x00\n\x03\x02\x01\x00\xFf\x01\x00\x01\x00>>>\n\r\n6299\r\nHost: nf...\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
2018-01-14 15:08:14.454:WARN:eek:ejh.HttpParser:qtp189568618-10: Illegal character 0x16 in state=START for buffer HeapByteBuffer@69ccff2a[p=1,l=140,c=8192,r=139]={ \x16<<<\x03\x01\x00\x87\x01\x00\x00\x83\x03\x01Z[\xB8\xAe\x00\x1c\x03...\x00\x18 \x00\x06\x00\n\x03\x02\x01\x00\xFf\x01\x00\x01\x00>>>\x00\x00\r\x00\x14\x00\x12\ x04\x01\x05\x01\x02\x01\x04\x03\x05\x03...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00}

> 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:
Top