Wednesday, March 28, 2012

Client authentication with SSL certificates in Jetty in maven

Here is an example pom.xml fragment:

                    <!--connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                    <connector implementation="">
                        <wantClientAuth>true</wantClientAuth><!-- deprecated! -->
                        <needClientAuth>false</needClientAuth><!-- deprecated! -->
                        <!-- -->

Client authentication with SSL certificates in Tomcat

Place something like this in server.xml file:

      <Connector port="8443" 



Attention: clientAuth parameter, in Tomcat 6.0 can get value "want", so it accepts connections with and wothout certificates. The application could decide what to do with the two types of clients internally. Take attention Tomcat 6.0 COULD NOT understand option clientAuth="optional". I suppose it was valid sometime, but now it is not.

Tuesday, March 27, 2012

Checking certificate validity via CRL with openssl

openssl verify -crl_check -CAfile miteff-root-ca-c.crt -untrusted signer-ca-c3-chain.crt

Thursday, March 22, 2012

maven webapp archetype

mvn archetype:generate -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp

Wednesday, March 21, 2012

Test your bugfix skills

Here is a bug. Find it:

        BufferedReader reader = request.getReader();
        StringBuilder requestSB = new StringBuilder();
        String requestStr;
        String line;
        while ((line = reader.readLine()) != null) {
          requestSB.append( line );
          requestSB.append( '\n' );
        requestStr = requestSB.toString();

In which situations this bug appears?

Getting HTTPS SSL certificates from HttpRequest in Java

Such an easy solution: cert[] =
([]) httpServletRequest.getAttribute

The result is the whole certificate chain.

The client could or could not send its certificate. A client certificate can be send in SSL version 3 and in TLS. You have to set an option to the web application server to want ant to accept client certificates. In jetty, the option is named wantClientAuth. Later I will extend the article with the name for Tomcat.

Monday, March 19, 2012

Adding external jar libraries to maven project

You have to add something like this in your pom.xml:

Tuesday, March 13, 2012

Starting a java application with debug logs for SUN packages

First check which is the define for enabling debug for package you want to get logs from. This is an example for (and some related packages to it):

java ApplicationFromMiteffDotCom

Monday, March 12, 2012

Making jar with dependency jars incorporated with maven

I want to start my program from the clear console. Here is the code, which has to be placed in pom.xml:

Redirecting output in MS DOS

I need to redirect the error output to file also. This can be done with

command > certpath.txt 2>&1

For example:

java -jar target\xxx-2.0-SNAPSHOT-jar-with-dependencies.jar > certpath.txt 2>&1

Friday, March 9, 2012

Checking certificate validity via OCSP with OpenSSL

The certificate have to had a OCSP definition.

OpenSSL> ocsp -issuer G:\temp\1\XXXRootCA.pem -cert G:\temp\1\XXXRootCA.pem -CAfile G:\temp\1\XXXRootCA.pem -url -text

Note: add full path to the files

Debugging classes without sources

I have to debug some classes, which are not provided with source code in NetBeans.

I have to choose from these options:
1. Switch to Eclipse and use JD-Eclipse. Many people indicates that they use it without problems.
2. Decompile the sources and add them to IDE. In this case we have to an another problem - line numbers. From Java bytecode, IDE knows the lines, where the operations are placed in source code. If lines mismatch, the debugger jumps to wrong numbers - fail.

Sunday, March 4, 2012

Multiple vhosts with apache httpd

There are two major questions about that:
1. May an apache site has multiple https virtual hosts?
2. May an apache site has different certificates for different virtual hosts.