3

I am newbie to server side and would like to how to configure AJP connector in eclipse's tomcat in linux environment to enable SSL.

I want to enable SSL in tomcat without using keystore. I created key.pem, cert.pem and cert.crt. And dont no what to do next. Can any body help? Used the following commands:

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 999

openssl x509 -outform der -in cert.pem -out cert.crt

Server.xml

<Connector 
          port="8443" maxThreads="200"
          scheme="https" secure="true" SSLEnabled="true"
          SSLCertificateFile="/root/keyTest/cert.pem" 
          SSLCertificateKeyFile="/root/keyTest/key.pem"
          clientAuth="optional" SSLProtocol="TLSv1"/>

But got an error

SEVERE: Failed to load keystore type JKS with path /root/.keystore due to /root/.keystore (No such file or directory)
    java.io.FileNotFoundException: /root/.keystore (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getStore(JSSESocketFactory.java:413)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeystore(JSSESocketFactory.java:319)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:577)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:517)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.init(JSSESocketFactory.java:462)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.createSocket(JSSESocketFactory.java:209)
        at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:398)
        at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:646)
        at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
        at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
        at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:821)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)

    May 12, 2015 3:58:56 PM org.apache.coyote.AbstractProtocol init
    SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-8443"]
    java.io.FileNotFoundException: /root/.keystore (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getStore(JSSESocketFactory.java:413)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeystore(JSSESocketFactory.java:319)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:577)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:517)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.init(JSSESocketFactory.java:462)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.createSocket(JSSESocketFactory.java:209)
        at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:398)
        at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:646)
        at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
        at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
        at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:821)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)

    May 12, 2015 3:58:56 PM org.apache.catalina.core.StandardService initInternal
    SEVERE: Failed to initialize connector [Connector[HTTP/1.1-8443]]
    org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-8443]]
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
        at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:821)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)
    Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
        at org.apache.catalina.connector.Connector.initInternal(Connector.java:980)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        ... 12 more
    Caused by: java.io.FileNotFoundException: /root/.keystore (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getStore(JSSESocketFactory.java:413)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeystore(JSSESocketFactory.java:319)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:577)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:517)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.init(JSSESocketFactory.java:462)
        at org.apache.tomcat.util.net.jsse.JSSESocketFactory.createSocket(JSSESocketFactory.java:209)
        at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:398)
        at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:646)
        at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
        at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
        at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
        ... 13 more

1 Answer 1

0

Was able to implement the same.

Refer :- http://eves4code.blogspot.in/2015/05/configure-ssl-in-tomcat-localhost-using.html?q=ssl

See below steps.

  1. openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 999 openssl x509 -outform der -in cert.pem -out your-cert.crt

copy the above 3 files to /opt/apache-tomcat-7.0.57/conf/

In server.xml

  1. You can not use a keystore if you are using the APR connector. https://stackoverflow.com/questions/6306314/tomcat-7-ssl-failed

You'll just have to use a keystore (or equivalent), since you'll need a certificate to be able to use HTTPS with a browser. You can use a PKCS#12 file generated by OpenSSL as a keystore of PKCS12 type. Alternatively, you can use the APR connector and use the key and cert in PEM format directly. https://stackoverflow.com/questions/30190681/enable-ssl-in-tmcat-without-using-keystore Download Tomcat Native source from https://tomcat.apache.org/download-native.cgi Download APR Native http://apr.apache.org/download.cgi Install Apr/Native : http://www.sheroz.com/installing-apache-tomcat-native-linux-ubuntu-1204

cd tomcat-native-1.1.27-src/jni/native ./configure --with-apr=/usr/local/apr --with-java-home=/home/foo/jdk1.7.0_25 --with-ssl=yes make sudo make install Refer : https://stackoverflow.com/questions/18776378/tomcat-apr-native-library-not-loaded-even-when-present-and-configured https://stackoverflow.com/questions/8716259/what-does-the-apr-based-apache-tomcat-native-library-was-not-found-mean

From /usr/local/apr/lib/, copy the tcnative-1.dll (or libtcnative.so for Linux) and put it in the tomcat's bin folder, and add a system property to the launch configuration of the tomcat server in eclipse. -Djava.library.path=c:\dev\tomcat\bin

To find catalina home $ /opt/apache-tomcat-7.0.57/bin/catalina.sh version Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.29 Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.29 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.29/temp Using JRE_HOME: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home Using CLASSPATH: /usr/local/apache-tomcat-7.0.29/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.29/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.29 Server built: Jul 3 2012 11:31:52 Server number: 7.0.29.0 OS Name: Mac OS X OS Version: 10.7.4 Architecture: x86_64 JVM Version: 1.6.0_33-b03-424-11M3720 JVM Vendor: Apple Inc. Refer : https://stackoverflow.com/questions/11496280/how-do-i-find-the-value-of-catalina-home

Create /opt/apache-tomcat-7.0.64/bin/setenv.sh

JRE_HOME=/usr/java/latest CATALINA_PID="$CATALINA_BASE/tomcat.pid export LD_LIBRARY_PATH='$LD_LIBRARY_PATH:/usr/local/apr/lib'

Refer : http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt https://stackoverflow.com/questions/9480210/tomcat-7-setenv-sh-is-not-found

catalin_pid - The PID file is located wherever you tell the catalina script to put it. CATALINA_PID is an input variable, not an output. You supply the path/file and tomcat writes its PID number a single line of text to that file. Refer : http://www.coderanch.com/t/503086/Tomcat/Expression-Tomcat-pid

JRE_HOME http://www.unix.com/shell-programming-and-scripting/43918-how-find-jre-installed-linux-machine.html

http://snipplr.com/view/50950/

Add environment variable to tomcat configuration https://stackoverflow.com/questions/6926382/eclipse-tomcat-apr

  1. Go to localhost:8080
  2. Go to https://localhost:8443

  3. Paste to project's web.xml securedapp / CONFIDENTIAL Refer: http://java.dzone.com/articles/setting-ssl-tomcat-5-minutes No need for this step / 7. Next time after removing tomcat from Eclipse, we need to congiure the tomcat-native again. Servers -> Click on you tomcat -> Overview -> Click on 'Open launch configuration' -> Tab 'Enviroment -> New...

LD_LIBRARY_PATH - /usr/local/apr environment variable

See : https://stackoverflow.com/questions/6926382/eclipse-tomcat-apr

The shared library must be found by the tomcat process. On Linux, you can use the LD_LIBRARY_PATH environment variable for this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .