B4J Question [BANanoServer] Trying out ABKeyStoreSSL

Mashiane

Expert
Licensed User
Longtime User
So

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

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

B4X:
If Server.PortSSL <> 0 Then
        ' make the jks file (if needed)
        MakeJKS
        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
        Else
            ' start it without https
            LogError("Failed to open or create " & JKSName & ".jks" & ". Starting server in HTTP mode...")
            Server.StartServer
        End If
        
        
        'Server.StartServerHTTP2("keystore.jks", "SSLKeyStorePassword", "SSLKeyManagerPassword")
    Else
        Server.StartServer
    End If

And added the rest of the code

B4X:
' 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
    JKS.Initialize("/var/www/html/")

    Dim domains As List
    domains.Initialize
    domains.Add("localhost")

    ' 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 = "192.168.86.150" 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
    'Else
    '    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
        JKS.ReloadJKS(Server.GetSSLConfiguration)
    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?

Thanks.

B4J logs attached
 

Attachments

  • keylog.zip
    2 KB · Views: 133
Top