B4J Question SSL no valid keystore

Discussion in 'B4J Questions' started by Alexander Stolte, Jan 30, 2018.

Tags:
  1. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Hello,

    i follow these steps. Erel was linking to a page to create a keystore file, i follow these steps and have create an keystore.

    Now if i call this function:

    Code:
    Private Sub ConfigureSSL (SslPort As Int)
        
    'example of SSL connector configuration
        Dim ssl As SslConfiguration
        ssl.Initialize
        ssl.SetKeyStorePath(
    File.DirApp, "selfsigned.keystore"'path to keystore file
        ssl.KeyStorePassword = "mystorepw"
        ssl.KeyManagerPassword = 
    "mymanagerpw"
        srvr.SetSslConfiguration(ssl, SslPort)
        
    'add filter to redirect all traffic from http to https (optional)
        'srvr.AddFilter("/*", "HttpsFilter", False)
    End Sub
    comes this error:

    Code:
    Error occurred on line: 31
    java.lang.IllegalStateException: no valid keystore
        at org.eclipse.jetty.util.security.CertificateUtils.getKeyStore(CertificateUtils.java:
    48)
        at org.eclipse.jetty.util.ssl.SslContextFactory.loadKeyStore(SslContextFactory.java:
    1020)
        at org.eclipse.jetty.util.ssl.SslContextFactory.doStart(SslContextFactory.java:
    336)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:
    132)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:
    114)
        at org.eclipse.jetty.server.SslConnectionFactory.doStart(SslConnectionFactory.java:
    64)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:
    132)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:
    114)
        at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:
    260)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:
    81)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:
    244)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.server.Server.doStart(
    Server.java:384)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:
    212)
        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.shell.Shell.runVoidMethod(
    Shell.java:656)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:232)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:159)
        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:
    79)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    92)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    70)
        at b4j.example.main.main(main.java:
    29)
    The password is right, the way to create this file was right.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    If everything was right then it would have worked.

    Why are there two different passwords?
     
  3. LucaMs

    LucaMs Expert Licensed User

    The tool to generate the key requires two passwords, and your code too:
    Now I don't remember but the name used by that tool for PWs are different from yours.
    One is the Keystore file pw, the other, here named KeyManagerPassword I think is the second one the tool requires (although its name is different).
     
  4. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Thats right, the first is the "Keystore-Password" and the second is the "KeyPassword".
     
    Cableguy likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    Create a new keystore and use the same password.
     
  6. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    I've already tried everything, always the same mistake. With the same password, with a other method, nothing works.

    I have even created a keystore on the server to rule out version differences, with the same result.

    i create the key as described:

    Code:
    keytool -keystore keystore -alias jetty -genkey -keyalg RSA
    fill all out and finish. Then i have a basic keystore for using.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Which error do you get if you set the path to a non-existent file?
     
  8. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    The same... and if i switch to File.DirAssets to the right file, comes the same error too.

    Code:
    Error occurred on line: 31
    java.lang.IllegalStateException: no valid keystore
        at org.eclipse.jetty.util.security.CertificateUtils.getKeyStore(CertificateUtils.java:
    48)
        at org.eclipse.jetty.util.ssl.SslContextFactory.loadKeyStore(SslContextFactory.java:
    1020)
        at org.eclipse.jetty.util.ssl.SslContextFactory.doStart(SslContextFactory.java:
    336)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:
    132)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:
    114)
        at org.eclipse.jetty.server.SslConnectionFactory.doStart(SslConnectionFactory.java:
    64)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:
    132)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:
    114)
        at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:
    260)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:
    81)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:
    244)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.server.Server.doStart(
    Server.java:384)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:
    212)
        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.shell.Shell.runVoidMethod(
    Shell.java:656)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:232)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:159)
        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:
    79)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    92)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    70)
        at b4j.example.main.main(main.java:
    29)


    Code:
    Error occurred on line: 31
    java.lang.IllegalStateException: no valid keystore
        at org.eclipse.jetty.util.security.CertificateUtils.getKeyStore(CertificateUtils.java:
    48)
        at org.eclipse.jetty.util.ssl.SslContextFactory.loadKeyStore(SslContextFactory.java:
    1020)
        at org.eclipse.jetty.util.ssl.SslContextFactory.doStart(SslContextFactory.java:
    336)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:
    132)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:
    114)
        at org.eclipse.jetty.server.SslConnectionFactory.doStart(SslConnectionFactory.java:
    64)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:
    132)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:
    114)
        at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:
    260)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:
    81)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:
    244)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at org.eclipse.jetty.server.Server.doStart(
    Server.java:384)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
    68)
        at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:
    212)
        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.shell.Shell.runVoidMethod(
    Shell.java:656)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:232)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:159)
        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:
    79)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    92)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    70)
        at b4j.example.main.main(main.java:
    29)
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    File.DirAssets is not relevant here.

    I'm probably haven't copied the store file to the correct path.

    Check the path with Log(File.DirApp).
     
  10. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Oh man, the path for the DirApp folder was wrong... but if i add this file with DirAssets then it was wrong, strange world. :eek: Thanks.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    There is no relation between DirAssets and DirApp.
     
    Alexander Stolte likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice