B4J Question [Solved] [ABMaterial] - using https (secure)

Harris

Expert
Licensed User
myApp.StartServerHTTP2(srvr, "srvr", port, 443,"keystore","b12xxxxx","b12xxxxx" ) ' port = 51046
Is this correct?


I purchased SSL cert from SSLs.com (namecheap)...

I had my VPS provider setup the certs on my VPS.
I created a keystore (named keystore) according to this command - and answering questions...

keytool -keystore keystore -alias jetty -genkey -keyalg RSA

Updated server with new jar and rebooted. The jar did start on the server, however
now I can't run the app in my browser.
 

Harris

Expert
Licensed User
B4X:
2019-04-12 22:23:28.362:INFO::main: Logging initialized @6182ms to org.eclipse.jetty.util.log.StdErrLog
abmapplication._startserverhttp2 (java line: 387)
java.lang.IllegalStateException: No Server ALPNProcessors!
    at org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory.<init>(ALPNServerConnectionFactory.java:53)
    at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:142)
    at com.ab.ccwatch.abmapplication._startserverhttp2(abmapplication.java:387)
    at com.ab.ccwatch.main._appstart(main.java:123)
    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:91)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
That is what I get on my dev... which has no ssl certs...
Copied jar to server, nothing shows up in the logs...
 

Harris

Expert
Licensed User
You do have your keystore.jks file next to the jar? And ae running java 9+?
No keystore.jks in File.DirApp...
Just "keystore" file.

Java

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
root@hwsrv-206966:~#


This process seems confusing - and of course it would - cause I ultimate dummie...

Thanks AB
 

Harris

Expert
Licensed User
So I need to update as you suggest...

To what version? I have read many posts with updating to 11 (10, and others) and hearing many issues (real or not).

My VPS is Ubuntu, 18.04 LTS.

Not great with command line updates. Takes much google searching to find a suitable method to patch.
Thanks God no matter how much I screw up, Linux always recovers, and I carry on - no harm - no foul.
With MS, I would have to format Drive C:


Thanks
 

Harris

Expert
Licensed User
When I contacted my VPS provider who installed the cert, they had NO idea what I was referring to when I mentioned the "keystore" file to make my app work.... WTF?
 

Harris

Expert
Licensed User
I will try java 9 update in the morning. it is 1 am here...
Thanks
 

DonManfred

Expert
Licensed User
I´m really not a pro in this but i want to share my 2cent:
I do have a cheap VPS to play around with it.

I am using letsencrypt certs to secure my webserver on the VPS.
The plus on this certs is that they are Trusted ones.

I did installed the certbot using ssh and their Documentations.

https://certbot.eff.org/

For you i guess it is
https://certbot.eff.org/lets-encrypt/ubuntubionic-apache.html

List of all Instructions
https://certbot.eff.org/all-instructions


Another Tutorial
https://www.digitalocean.com/commun...ure-apache-with-let-s-encrypt-on-ubuntu-18-04

Hope it helps!?
 
Last edited:

Harris

Expert
Licensed User
B4X:
 pre end myapp - output to ccwlogs.txt
2019-04-13 11:26:21.633:WARN:oejh.HttpParser:qtp335359181-24: Illegal character 0x16 in state=START for buffer HeapByteBuffer@53a4cb8a[p=1,l=517,c=8192,r=516]={\x16<<<\x03\x01\x02\x00\x01\x00\x01\xFc\x03\x03\xD6 \xE2R&\xCbx...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
2019-04-13 11:26:21.860:WARN:oejh.HttpParser:qtp335359181-23: Illegal character 0x16 in state=START for buffer HeapByteBuffer@53a4cb8a[p=1,l=208,c=8192,r=207]={\x16<<<\x03\x01\x00\xCb\x01\x00\x00\xC7\x03\x03\xEc\x04\xF8\x17=`\x98...\x12\x00\x00\x00\x1b\x00\x03\x02\x00\x02\xAa\xAa\x00\x01\x00>>>\x00\x14\x00\x12\x04\x03\x08\x04\x04\x01\x05\x03\x08\x05\x05\x01\x08...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
/
Forbidden
 initing abmapplication
Connected
Waiting for value (105 ms)
Waiting for value (100 ms)
Waiting for value (101 ms)
Disconnected
Home Page Connected
Waiting for value (101 ms)
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:188)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
    at anywheresoftware.b4a.objects.collections.Map.ContainsKey(Map.java:122)
    at com.ab.abmaterial.ABMaterial.UpdateFromCache(Unknown Source)
    at com.ab.ccwatch.homepage._websocket_connected(homepage.java:323)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    ... 7 more
Disconnected
Updated server to open-jdk 11
Same issue... arrggg.
 
Last edited:

OliverA

Expert
Licensed User

OliverA

Expert
Licensed User
Are you using a port # to access your ABM application?
 

Harris

Expert
Licensed User

Harris

Expert
Licensed User
I don't have a redirect filter - as per erels SSL tutorial - SHould I Have?
 

OliverA

Expert
Licensed User
myApp.StartServerHTTP2(srvr, "srvr", port, 443,"keystore","b12xxxxx","b12xxxxx" ) ' port = 51046
Make sure the 443 is not 443, but the port you are using (51046)
 

Harris

Expert
Licensed User
myApp.StartServerHTTP2(srvr, "srvr", port, 443,"ccw.keystore", "b12bxxxx","b12bxxxx" )
 

Harris

Expert
Licensed User

Harris

Expert
Licensed User
myApp.StartServerHTTP2(srvr, "srvr", port, port,"ccw.keystore", "b12bxxxx","b12bxxxx" )

port is 51046

Added HttpsFilter -
This site can’t provide a secure connection

Without filter: No connection now...

B4X:
public Sub StartServerHTTP2(srvr As Server, srvrName As String, srvrPort As Int, SSLsvrPort As Int,  SSLKeyStoreFileName As String, SSLKeyStorePassword As String, SSLKeyManagerPassword As String)

Try
    
    Log("trying to startup")
    ABM.WriteAppLauchPageToDisk(AppPage, File.DirApp & "/www/" & ABMShared.AppName, "index.html", ABMShared.NeedsAuthorization)

    Dim ssl As SslConfiguration
    ssl.Initialize
    ssl.SetKeyStorePath(File.DirApp, SSLKeyStoreFileName) 'path to keystore file
    ssl.KeyStorePassword = SSLKeyStorePassword
    ssl.KeyManagerPassword = SSLKeyManagerPassword
    srvr.SetSslConfiguration(ssl, SSLsvrPort)
    srvr.AddFilter("/*", "HttpsFilter", False)
    ' start the server
    srvr.Initialize(srvrName)
        Log("trying to startup... :  "&srvrName)

    ' uncomment this if you want to directly access the app in the url without having to add the app name
    ' e.g. 192.168.1.105:51042 or 192.168.1.105 if you are using port 80
    'srvr.AddFilter( "/", "ABMRootFilter", False )
    
    ' NEW V3 Cache Control
    srvr.AddFilter("/*", "ABMCacheControl", False)
    ' NEW 4.00  custom error pages (optional) Needs the ABMErrorHandler class
    srvr.SetCustomErrorPages(CreateMap("org.eclipse.jetty.server.error_page.global": "/" & ABMShared.AppName & "/error")) ' OPTIONAL
    srvr.AddHandler("/" & ABMShared.AppName & "/error", "ABMErrorHandler", False) ' OPTIONAL
    
    srvr.AddWebSocket("/ws/" & ABMShared.AppName, "ABMApplication")
    For i =0 To Pages.Size - 1
        srvr.AddWebSocket("/ws/" & ABMShared.AppName & "/" & Pages.Get(i) , Pages.Get(i))
        If PageNeedsUpload.Get(i) Then
            srvr.AddHandler("/" & ABMShared.AppName & "/" & Pages.Get(i) & "/abmuploadhandler", "ABMUploadHandler", False)
        End If
    Next
    srvr.AddBackgroundWorker("ABMCacheScavenger")
    srvr.Port = srvrPort
    srvr.Http2Enabled = True
    
    #If RELEASE       
    srvr.SetStaticFilesOptions(CreateMap("gzip":True,"dirAllowed":False))
    #Else       
        srvr.SetStaticFilesOptions(CreateMap("gzip":False,"dirAllowed":False))
    #End If
        
    srvr.Start
    
    Dim joServer As JavaObject = srvr
    joServer.GetFieldJO("server").RunMethod("stop", Null)
    joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setMaxAge", Array(31536000)) ' 1 year
    
    ' NEW FEATURE! Each App has its own Session Cookie
    joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setName", Array(ABMShared.AppName.ToUpperCase))
    joServer.GetFieldJO("server").RunMethod("start", Null)
    
    Dim secs As Long = ABMShared.CacheScavengePeriodSeconds ' must be defined as a long, else you get a 'java.lang.RuntimeException: Method: setIntervalSec not matched.' error
    joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionIdManager", Null).RunMethodJO("getSessionHouseKeeper", Null).RunMethod("setIntervalSec", Array As Object(secs))
    
    Dim jo As JavaObject = srvr
    Dim connectors() As Object = jo.GetFieldJO("server").RunMethod("getConnectors", Null)
    Dim timeout As Long = ABMShared.SessionMaxInactiveIntervalSeconds*1000
    For Each c As JavaObject In connectors
        c.RunMethod("setIdleTimeout", Array(timeout))
    Next

    ABMShared.CachedPages = srvr.CreateThreadSafeMap
    
Catch
    Log(" start except: "&LastException.Message)
End Try       
End Sub
'----------------------END MODIFICATION 4.00-------------------------------
 

OliverA

Expert
Licensed User
make first port # 51046, this is for http:// access. Make the second port 51047. That will be for https:// access
 

Harris

Expert
Licensed User
Top