B4J Question [BANanoServer] Trying out ABKeyStoreSSL


Licensed User
Longtime User

1. I copied all the files from ABKeyStoreSSL to my additional folders.
2. Opened up my BANanoServer project.
3. Created a reference to ABKeyStoreSSL on the libraries listing
4. Added this to Main.Process_Globals

Public JKS As ABKeystoreSSL
    Public JKSReloadTimer As Timer
    Public JKSName As String = "myjksname"
    Public JKSStorePassword As String = "myjksstorepassword"
    Public JKSManagerPassword As String = "myjksmanagerpassword"

Then updated Main.AppStart with

If Server.PortSSL <> 0 Then
        ' make the jks file (if needed)
        If File.Exists(File.DirApp, JKSName & ".jks") Then
            Log("Starting server in HTTPS mode...")
            Server.StartServerHTTP2(JKSName & ".jks", JKSStorePassword, JKSManagerPassword)
            ' set a timer for a day
            JKSReloadTimer.Initialize("JKSReloadTimer", 24*60*60*1000)
            JKSReloadTimer.Enabled = True
            ' start it without https
            LogError("Failed to open or create " & JKSName & ".jks" & ". Starting server in HTTP mode...")
        End If
        'Server.StartServerHTTP2("keystore.jks", "SSLKeyStorePassword", "SSLKeyManagerPassword")
    End If

And added the rest of the code

' creates a certificate with Let's Encrypt
Sub MakeJKS() As Boolean
    Dim Result As Boolean
    ' needs to be the 'entry point' in your webserver (NOT your B4X app). In my case it was var/www/html and not var/www/)
    ' MUST be accessible on port 80

    Dim domains As List

    ' when developing, I check here if it is my local PC. If so I do not use the production server of Let's Encrypt
    'If ABM.GetMyIP = "" Then
        Result = JKS.GenerateJKS(domains, File.DirApp, JKSName, JKSStorePassword, JKSManagerPassword, False, "C:\KeyVault", False)
        If File.Exists(File.DirApp, JKSName & ".jks") = False Then
            ' let's try to make a self signed certificate for development
            LogError("Failed to open or create " & JKSName & ".jks with Let's Encrypt. Let's try to make a self signed one...")
            Result = JKS.GenerateSelfSignedJKS(File.DirApp, JKSName, JKSStorePassword, JKSManagerPassword, "C:\KeyVault")
        End If
    '    Result = JKS.GenerateJKS(domains, File.DirApp, JKSName, JKSStorePassword, JKSManagerPassword, True, "../KeyVault", False)
    'End If

    Return Result
End Sub

Sub JKSReloadTimer_Tick
    If MakeJKS Then
        ' we created a new one, so reload it in the server
    End If
End Sub

Q0. What am I doing absolutely wrong?
Q1. Issues: I dont have a webserver to test this with, my computer is running laragin on apache 81/443, can not this be done with such an environment?
Q2. I see this line JKS.Initialize("/var/www/html/"), I guess this is for Linux deployments, for windows I guess I have to write public_html etc or something?
Q3. I am still using local apache for development, on this line, domains.Add("localhost") what is the best option to use?


B4J logs attached


  • keylog.zip
    2 KB · Views: 84