LNP242 Make §§§ fast (Logbuch:Netzpolitik)
Das Logbuch Spezial zum besonderen elektronischen Anwaltspostfach Das besondere elektronische Anwaltspostfach soll eigentlich eine elegante Lösung sein, die sichereren E-Mail-Verkehr zwischen deutschen Anwälten und deutschen Gerichten realisieren kann. Nach einer... Das Logbuch Spezial zum besond...

Hier folgen meine Gedanken zu den Problemen bei der Umsetzung des „elektronischen Anwaltpostfachs“, wie sie im „Logbuch Netzpolikt 242“ (Podcast) dargestellt werden. Ich habe sie dort auch als Kommentar veröffentlicht.

Hier nur noch kurz der Kontext: was ist das „beA“: „Das besondere elektronische Anwaltspostfach (beA) ermöglicht Rechtsanwälten die sichere elektronische Kommunikation mit der Justiz und untereinander. Jeder in Deutschland zugelassene Rechtsanwalt verfügt über ein solches elektronisches Postfach.“ Markus Drenger (CCC) hat mehrere Sicherheitslücken in der Implementierung gefunden (Talk).

Hier nun mein Kommentar.

In meiner Wahrnehmung werden mittlerweile überwiegend Webanwendungen entwickelt. Ich weiß nicht, wie es konkret bei Atos aussieht, aber das Wissen um das Bauen von nativen Anwendungen scheint mir mittlerweile nicht mehr so weit gestreut zu sein wie bei Webanwendungen. Letztere haben ja auch unbestrittene Vorteile: eine zentrale Installation auf einer bekannten Umgebung statt vieler dezentraler Installationen auf unbekannten Umgebungen. Ein Patch ist da eingespielt oder nicht eingespielt, bei nativen Anwendungen gibt es immer was dazwischen.

Beim beA ist jedoch eine lokale Installation notwendig, um auf die Smartcard zugreifen zu können. Also wird ein Server installiert, um mit der Smartcard zu kommunizieren, und auf eher abenteuerliche Weise mit einem Zertifikat ausgestattet. Wie machen denn das andere Lösungen? Die z.B. mit dem ePerso kommunizieren? Nun hat man sich dann doch eine lokale Installation ins Boot geholt und muss gleichzeitig Kopfstände machen, um damit zu kommunzieren. Ein lokaler Server … da merkt doch der Nutzer viel weniger, wenn da was schief läuft, der z.B. nicht startet. Ich stimme zu, dass hier eine lokale Anwendung passender wäre. Die Unterstützung von mindestens Windows und MacOS, mglw. auch Linux, in diversen Versionen ist jedoch sicherlich nicht einfach.

Die Sache mit den Terminalservern scheint mir ja die Vorteile der Smartcards zu nichte zu machen. Wie oft werden die eingesetzt? War das der BRAK vor Beginn des Projektes bekannt?

Die „Vertretungsregel“ begründet die Einführung des HSM, das die „Umschlüsselung“ durchführt. Damit ist die Ende-zu-Ende-Verschlüsselung kaputt. Fachlich finde ich die Anforderung nachvollziehbar. Muss denn wirklich der Rechtsanwalt persönlich adressiert werden, oder reicht es, seine Kanzlei zu adressieren? Bei den Gerichten wird man doch wohl auch nicht einzelne Personen adressieren, oder? Wenn man eine ganze Kanzlei oder Teile davon adressieren kann und die betreffenden Mitarbeiter Zugriff auf das Postfach haben, bräuchte niemand umschlüsseln. Dito bei den Absendern.

Dann könnte man auch fast schon De-Mail einsetzen. Aber halt, die Kommunikation erfolgt über OSCI. Das ist aber nur ein Transport-Protokoll. Ist die Payload weiter strukturiert? Wird z.B. ein Aktenzeichen angegeben, damit die Nachricht im Gericht gleich einer elektronischen Akte zugeordnet werden kann? Das geht dann auch in die Richtung „wir bräuchten einfach mal eine Open-Source-Komponente, die E2E-Verschlüsselung zwischen Alice und Bob ermöglicht“ – was wird genau ausgetauscht?

Das habe ich auch nicht verstanden: man kann sich als einfacher Bürger anmelden, wie kann man dann kommunizieren? Braucht man dann auch beA?

Zu guter Letzt: PDF. Ja, PDF ist nicht sicher. Ich vermisse jedoch einen Gegenvorschlag. Nur Text und JPG/PNG? Unrealistisch. Statt PDF ginge PDF/A, aber wer erklärt allen RechtsanwältInnen, dass statt PDF PDF/A zu erzeugen ist und wie man das im Programm der Wahl macht? Habe ich übrigens auch schon gehen: eingehende PDFs mittels Ghostscript in PDF/A wandeln wg. IT-Sicherheit.

Über das beA ließe sich also mindestens nochmal 2 Stunden diskutieren.

I recently felt the need for accessing the metrics / statistics of a JDBC Data Source from within an application that is deployed on a Oracle Weblogic Server. I did not succeed right away, so I document it here.

Basically we just need some calls to JMX. Using the Weblogic RuntimeServiceMBean we navigate from ServerRuntime and JDBCServiceRuntime to JDBCDataSourceRuntimeMBeans. From there we get ObjectNames for each JDBC Data Source that we can access from our application. Using these object names we can retreive the metrics.

First we get the MBeanServer via JNDI:

  1. MBeanServer getMBeanServer() throws NamingException {
  2.   InitialContext ctx = new InitialContext();
  3.   MBeanServer server = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
  4.   return server;
  5. }

Then we navigate as described before:

  1. ObjectName[] getJdbcDataSourceRuntimeMBeans(MBeanServer server)
  2.       throws MalformedObjectNameException, AttributeNotFoundException, MBeanException,
  3.       InstanceNotFoundException, ReflectionException {
  4.     ObjectName service = new ObjectName(
  5. "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
  6.     ObjectName serverRT = (ObjectName) server.getAttribute(service, "ServerRuntime");
  7.     ObjectName jdbcRT = (ObjectName) server.getAttribute(serverRT, "JDBCServiceRuntime");
  8.     ObjectName[] dsRTs = (ObjectName[]) server.getAttribute(jdbcRT, "JDBCDataSourceRuntimeMBeans");
  9.     return dsRTs;
  10.   }

To get the current number of active connections and the current capacity of the connection pool, we access the attributes ActiveConnectionsCurrentCount and CurrCapacity:

  1. MBeanServer server = getMBeanServer();
  2.       ObjectName[] dsRTs = getJdbcDataSourceRuntimeMBeans(server);
  3.       for (ObjectName dsRT : dsRTs) {
  4.         String name = (String) server.getAttribute(dsRT, "Name");
  5.         Integer activeConnectionsCurrentCount =
  6.             (Integer) server.getAttribute(dsRT, "ActiveConnectionsCurrentCount");
  7.         Integer currCapacity =
  8.             (Integer) server.getAttribute(dsRT, "CurrCapacity");
  9.     // do something with these metrics
  10.       }

There are a bunch of metrics. Here is a list. You can enumerate them using MBeanAttrbuteInfo:

  1. /**
  2.    * Returns MBean-Attribute Infos such as Name, Type and Description
  3.    */
  4.   public MBeanAttributeInfo[] getMetricsAttributeInfos() {
  5.     try {
  6.       MBeanServer server = getMBeanServer();
  7.       ObjectName[] dsRTs = getJdbcDataSourceRuntimeMBeans(server);
  8.       if (dsRTs.length>0) {
  9.         return server.getMBeanInfo(dsRTs[0]).getAttributes();
  10.       }
  11.     } catch (Exception e) {
  12.       // your favourite error logging mechanism here...
  13.     }
  14.     return new MBeanAttributeInfo[]{};
  15.    
  16.   }

every MBeanAttributeInfo contains name, type and description of the attribute.

Note: I am using Weblogic Server 11g here. I have not tried this on WLS 12c.

At work our application reads email from a number of POP3 servers using JavaMail. If you trigger the POP3 server’s timeout the session is closed silently und JavaMail does not complain on session.close. In the result, the message is not deleted and will be processed again on the next turn of the background processing task. To fix this, you need to check the state of the POP3 folder after processing each message. Read on for more details on this issue.

Problem

Some of the mails our application is getting are not only „messages“ meant to be read by humans but contain structured information that is processed. This means DB operations. Processing takes not more than a few seconds – unless the Oracle DB optimizer chooses to take a bad SQL execution plan. At least this is what happened to us last week: the processing of a structured message took like 20 minutes.

The symptom then was that after the application was finished processing the email, it did not deleted the message from the server. It then started processing the mail in the next turn. As we found out the POP3 server (qpopper) has configured a timeout of five minutes. After that it answers with an „-ERR“ status code to the next client command. The code we used to process the mail was roughly this:

  1. try {
  2.   mail = pop3Folder.getMessage(mailIndex + 1);
  3.   // ... do something with mail ...
  4. } finally {
  5.   mail.setFlag(Flags.Flag.DELETED, true);
  6. }
  7. folder.close();

When setting the delete flag, JavaMail sends the DELE command. That was answered with „-ERR“ (from POP3 protocol exchange):

C: STAT
S: +OK 1 1866
C: RETR 1
S: ...
C: DELE 1
S: -ERR POP timeout from some.host
C: QUIT
S: +OK Pop server at some.host signing off.

and the session is gone. Using session.close did not complain. So no exception occured. In fact, if an exception had occured we already had an compensation mechanism that would have prevented processing the same mail again. Also it would have pointed us to the problem more directly.

Solution

The solution is to check the protocol state using folder.isOpen after processing a mail.

If that folder is not open, the mails you have so far processed have not been deleted because in POP3, mails are deleted when closing a folder. So open the folder again and delete all messages (messageRead) that you have processed before. Then carry on, i.e. close the folder.

  1. boolean isOpen = folder.isOpen();
  2. if (!isOpen) {
  3.   folder.open(Folder.READ_WRITE);
  4.   final int mailCount = folder.getMessageCount();
  5.   for(int i = 1; i <= Math.min(messageRead, mailCount); i++) {
  6.     Message mail = folder.getMessage(i);
  7.     mail.setFlag(Flags.Flag.DELETED, true);
  8.   }
  9. }
  10. // folder.close in "normal" code flow

The folder.isOpen sends a NOOP command and evaluates the response, so the „-ERR“ server code is not gone unnoticed.

Doing it right

POP3 was designed to download mails rather quickly. A better solution is to fetch emails from POP3, store it somewhere and only then process them („offline“).

You often find the answer to „How do I set default timeouts for (outgoing) network connectins in Java“ is

  1. System.setProperty("sun.net.client.defaultReadTimeout", "30000");
  2. System.setProperty("sun.net.client.defaultConnectTimeout", "30000");

But this may or may not work. Because, as stated by Sun in 2005:

Yes, it [the default timeout] is cached, or more precisely it is looked up only at startup time. This is by design.

Playing around with the code in the bug database entry linked to above and netcat, I found that it is also true for Java 6. Chances are high that it is true for Java 7, too.

What is meant by „startup time“ is using some network connection, e.g. HttpURLConnection. That means if there has some network connection been used before the properties are programmatically set, no network connections will use these timeout values!! If you set these properties in the JEE ContextListener or some startup-servlet they may have no impact anymore because your web container may already have used a network connection. Better use the commandline to pass these parameters.

Die „Berlin Expert Days 2012“ war eine zweitägige Softwareentwicklungs-Konferenz in Berlin. Ich war das erste Mal dabei und es hat mir gut gefallen. Die Konferenz findet im Fachbereich Informatik an der FU-Berlin statt. Sie ist nicht sehr groß (Räumlichkeiten: 1 Hörsaal, 2 Seminarräume), wobei dieses Jahr wohl nicht alle Anmeldungen auch ein Ticket bekommen haben. Den Preis von unter 100 EUR finde ich sehr moderat.

Die meisten Talks, die ich gehört habe, waren interessant und gut präsentiert. Ausnahmen bestätigten die Regel. Ich schreibe mal einzelne Posts zu den Talks.

Ich habe sogar einen Ex-Kommolitonen wieder getroffen.

Problem

While using Oracle Enterprise Pack for Eclipse (Version 11.1.1.7.1) with Weblogic 11gR1 (that is 10.3.4.0) for some weeks
I suddenly was not able to stop the Weblogic server. Whatever method I used to stop the server, it didn’t work. When I restarted Eclipse
the Weblogic server started automatically again. Also, there were no more console output neither from the server nor from my application.

Solution

I manually started the „bin\stopWeblogic.cmd“ skript in the domain home directory using the Windows console. You can go to the
domain home by right-clicking the server in the „Servers“ view and choosing „Go To > Domain Home“. When I started the server
again from within Eclipse, the console output was there again and stopping the server worked well again. All is well 🙂

Gespräch mit Kollege:
Gegeben Klasse A und Klasse B extends A und ich rufe im Konstruktor von A eine Methode auf, die in B überschrieben wird und die dort auf eine in B definierte Variable zugreift, dann ist diese Variable zum Zeitpunkt des Aufrufs nicht initialisiert. Das stimmt.

Wozu brauchst Du das?
Klasse Gruppenbaum, im Konstruktor lese ich Baum aus DB.
Na das ist ja nicht so gut. Konstruktoren sollten ihr Objekt in einen definierten Zustand bringen, mehr aber auch nicht. Wurde schon vor langer Zeit beschrieben.