Recent EntriesOCSP Java Bug (Part II)
Saturday, May 18 2013 Debian 7.0 released! Sunday, May 5 2013 Glassfish HA using EJB Sunday, April 7 2013 BUG in Java OCSP Implementation (PKIX)? Friday, March 15 2013 SPNEGO/Kerberos in JavaEE (spnego.java.net) Sunday, March 3 2013 Testing WebRTC Saturday, February 16 2013 SPNEGO/Kerberos in JavaEE (PAC) Saturday, February 2 2013 SPNEGO/Kerberos in JavaEE Friday, January 18 2013 Samba 4.0.0 Thursday, December 27 2012 Limbo Sunday, December 2 2012 QuicksearchSyndicate This BlogAuthorBlog Administration |
Saturday, May 18. 2013OCSP Java Bug (Part II)As you have already seen in the previous entry, Debian 7.0 is now public and therefore I am using Jessie in testing. Openjdk 7 package is now update 21 (icedtea 2.3.9) and, as I promised, I finally upgraded from openjdk-6 to 7. Taking advantage of the situation I tested the previous OCSP issue I commented in this blog but with the new version. In 7u21 the issue is exactly the same but presenting different error messages. In the error cases the message presented is the following Signature length not correct: got 256 but was expecting 128. Much more cryptic I have to say than the previous messages (Error verifying OCSP Responder's signature or Responder's certificate not valid for signing OCSP responses). Checking again the code the problem is still the same. Just the issuer certificate or the configured certificate is passed to the OCSPResponse, so the cases 1 and 3 cannot be mixed with the case 2. But there is a good new, since the following commit the OCSP and OCSPResponse classes accept a list of responder certificates (previously it was only one) and therefore now the fix is even easier. It just consists in adding both certs (issuer cert and configured responder if it is the case) to the list. so now the fix is a simpler patch that only changes the OCSPChecker class. Talking about the bug I received an answer from Oracle telling me that the BUG has been accepted (it was around two months ago) but I have no more news since then. There is not a public link in the java database either. I am going to try to contact with icedtea guys to see what they think about that. Keep on trying! Sunday, April 7. 2013Glassfish HA using EJBI have received some comments about the old entry that installed a full glassfish HA solution using debian, people complain that the post did not deal with Stateful EJBs. A Stateful EJB is a enterprise bean that acts as a server-side extension of the client maintaining its state during calls (the bean object maintains its properties). Obviously this type of EJB has to also be replicated between the application server instances in case of an HA architecture. The reason for that oversight is clear, I am not a fan of remote EJBs, I always recommend to use local ones (which are deployed and called inside the same JVM and their performance is much better) or Web Services. Stateful EJBs should work smoothly in glassfish and today I am going to present a little example (and, as you will see later, I faced a very nasty issue). The first thing I did was installing the solution with glassfish 3.1.2.2, I repeated the same steps explained in the previous entry one by one. When the (in)famous clusterjsp was running I started to develop and deploy a simple stateful EJB following Markus Eisele's blog entry.
Today's entry complements a previous one of the blog (simple but full glassfish HA using debian), that entry tested only the web part but some people have commented to me what happened with a Stateful EJB. Usually that type of EJB should work in the HA scenario smoothly but a weird problem happened to me, using localhost instead of the real hostname for node creation complicated my solution. Once that issue was fixed the solution worked smoothly and EJB HA was assured by the glassfish cluster. Here I upload the clusterejb project I used in the entry. The moral is glassfish replication also works with stateful EJBs. Replicated regards! Friday, March 15. 2013BUG in Java OCSP Implementation (PKIX)?Today's entry is going to explain an issue I had some weeks ago with an OCSP (Online Certificate Status Protocol) responder. I had to use a specific responder which worked in such a way that I was not able to make Java work against it. I did not understand what was happening and I decided to test the problem more deeply in this entry. Let's start explaining how an OCSP responder works: the server receives requests from clients which want to check if a specific certificate is revoked; the responder checks the status of the certificate and answers if it is good, revoked or unknown; cos the protocol is affected by man in the middle attacks the response is signed; usually the response is signed by the same CA that issued the certificate being checked. And here my issue appears, my specific OCSP server checked certificates issued by different CAs, and to do that it followed two rules:
I could not configure Java to work against that OCSP responder. So I decided to read what RFC2560 (the standard that defines OCSP protocol) says, and this is the important part: All definitive response messages SHALL be digitally signed. The key used to sign the response MUST belong to one of the following: There are three possibilities or cases, which I will try to explain a bit more:
If you recheck what my responder was doing, it was using case 1 for its own certificates (common case) and case 2 for foreign certificates (the one in which the client should know the certificate used in order to trust in the responses). Therefore I understand that the OCSP responder was working well, its behavior is covered by the standard. OCSP in Java is part of its Public-Key Infrastructure (PKIX) implementation. It has several properties defined in the Security configuration for controlling the checking process. Let's summarize the most important:
At this point I decided to create an openssl ocsp environment which tested the three possibilities, for that I need a client certificate and three certificates for the OCSP responder (I followed similar commands to the ones I used in this previous entry):
This zip file contains the demoCA directory with all the openssl configuration to launch the ocsp responder. I developed a simple Java to test PKIX validation in the three scenarios. The program sets to true ocsp.enable and uses the fourth and fifth argument to set the ocsp.responderURL and the ocsp.responderCertSubjectName (this argument is optional). Previous arguments are the client certificate to check, the cacerts keystore to use and the password of the keystore. I tested the three possible scenarios:
I know, now you are saying but what the hell, Java supports all the possibilities. Where is the problem? A different configuration is needed to accomplish the three cases. Case 2 only works if the property ocsp.responderCertSubjectName is set (or any other option that fixes the certificate used for signing responses) but case 1 and 3 only works with that property not set. There is no way to configure the Java Security in a way that handles the three scenarios at the same time. What happens if there is an OCSP server whose responses use mixed cases? You are in a big problem if case 2 is involved. If you remember the responder I commented in the introduction, it works using cases 1 and 2, I would have never got it working no matter the time I had spent. It was absolutely impossible. First question, does the standard support that an OCSP responder uses all the scenarios at the same time? Or does it force the responder to not mix case 2 with the other two? I have not read anything against the first sentence and Java supports cases 1 and 3 at the same time, so why not case 2. Second question, is mixing case 2 with any of the other cases useful for a responder? I think it is, it is quite reasonable that the responder uses case 1 (the common method) for their own certificates and case 2 for certificates issued by other authorities (case 3 is also valid but you need the partner authority to sign a certificate for you). Remember that case 1 does not need client configuration and case 2 does need it, so it is logical to minimize the use of case 2. I think this is a BUG in the Java implementation and I will try to report it. If any of you is an expert in OCSP please let me know your thoughts. As you know I try to be a good neighbor and I checked why Java worked that way. Looking the code for openjdk6 b27 (last bundle released for version 6 at the moment) I checked that class sun.security.provider.certpath.OCSPChecker chooses the responder certificate from the properties defined in the Security configuration or from the issuer of the certificate that is going to be validated. It is one or the other. Then the class sun.security.provider.certpath.OCSPResponse receives that certificate as a parameter and validates the sign. OCSPResponse covers cases 1 and 3, the certificate used for signing can be the one passed as an argument or another certificate which has the OCSPSigning extension and was issued by the argument cert. That is the reason Java/PKIX isolates case 2 from the other two scenarios. Because I spent so much time guessing all of this I decided to make a patch. The fix involves the two classes commented in the previous paragraph and another one which is an intermediary class between them (OCSP class in the same package). In my solution OCSPResponse class receives two arguments: the issuer cert (the certificate which issues the client certificate to be checked) and the responder cert (the certificate defined in the Security properties, it can be null). With both certs the class can check the three cases at the same OCSP response, including the reviled scenario 2. Here it is my patch. With the new classes no matter how the openssl ocsp responder is started (any case) the same configuration for the Java program works: $ java -Xbootclasspath/p:/home/ricky/Desktop/jdk-patch/src/share/classes/ \ -Djava.security.debug=certpath -cp . CertificateChecker client1.pem cacerts.demo \ changeme http://localhost:3456 "CN=OCSP-TRUSTED, O=demo.kvm, ST=demo, C=ES" The previous command works for the three certificates (demoCA case 1, ocsp-trusted case 2 and ocsp-signing case 3) cos I am prepending my modified classes to the boot classpath. The same arguments, the same configuration works no matter which case the responder uses. Cos explanation for this issue is so long and complex I posted the entry before reporting the BUG (I will link this entry from the BUG explanation). I opened another BUG before but I had not understood the problem completely and people at Java team did not say anything to me (I was half wrong so it is fair). Let's see what happens now!
(Page 1 of 11, totaling 33 entries)
» next page
|

Comments
Thu, 04.04.2013 10:13
Hi Rulet, Usually this is a bug in the distribution packages, I suppose you're using ubuntu [...]
Wed, 03.04.2013 18:05
Whem trying to install libasound2:i386 it gives an error that /usr/share/alsa/alsa.conf cannot [...]
Sat, 16.02.2013 14:07
I have a set of events saved in my database (a very special database, so I can't use some popu [...]
Sat, 22.12.2012 15:26
Thanks Ricky, You are the guy! This is the way.. I can see it now! Thanks again!!!
Sat, 22.12.2012 15:17
No Bruno, a login is never done using a Java applet. The web server is configured to request u [...]
Thu, 20.12.2012 21:29
Thanks for the answer Ricky! Please, look the link above: https://cav.receita.fazenda.gov. [...]
Thu, 20.12.2012 14:43
Hi Semko, That error means the apt-get doesn't find the libasound2:i386 package. Are you u [...]
Thu, 20.12.2012 14:31
Hi Bruno, In order to authenticate a user using a certificate you need to read another of [...]