Fix: some smaller findBugs issues (static access, syncing, random..)
authorBenny Baumann <BenBE@geshi.org>
Wed, 25 Feb 2015 22:25:52 +0000 (23:25 +0100)
committerFelix Dörre <felix@dogcraft.de>
Wed, 25 Feb 2015 22:25:52 +0000 (23:25 +0100)
tests/org/cacert/gigi/email/TestSendmail.java
tests/org/cacert/gigi/testUtils/ManagedTest.java
util-testing/org/cacert/gigi/util/SimpleSigner.java

index ec3f69f..83cb9aa 100644 (file)
@@ -21,6 +21,7 @@ import java.security.cert.CertificateException;
 import java.util.Base64;
 import java.util.Date;
 import java.util.Properties;
+import java.util.Random;
 
 import javax.net.ssl.SSLSocketFactory;
 
@@ -39,6 +40,8 @@ import sun.security.x509.X509CertInfo;
 
 public class TestSendmail extends ConfiguredTest {
 
+    private static final Random rng = new Random();
+
     @Test
     public void testSendmail() throws IOException, GeneralSecurityException {
         initSelfsign();
@@ -110,7 +113,7 @@ public class TestSendmail extends ConfiguredTest {
         X509CertInfo info = new X509CertInfo();
         // Add all mandatory attributes
         info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
-        info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new java.util.Random().nextInt() & 0x7fffffff));
+        info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(rng.nextInt() & 0x7fffffff));
         AlgorithmId algID = AlgorithmId.get("SHA256WithRSA");
         info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algID));
         info.set(X509CertInfo.SUBJECT, new X500Name("EMAIL=system@cacert.org"));
index d9fb31e..4ac5d91 100644 (file)
@@ -169,7 +169,7 @@ public class ManagedTest extends ConfiguredTest {
 
     public static void clearCaches() throws IOException {
         ObjectCache.clearAllCaches();
-        String type = testProps.getProperty("type");
+        // String type = testProps.getProperty("type");
         URL u = new URL("https://" + getServerName() + "/manage");
         u.openConnection().getHeaderField("Location");
     }
@@ -219,15 +219,19 @@ public class ManagedTest extends ConfiguredTest {
 
     @After
     public void clearAcceptLanguage() {
-        acceptLanguage = null;
+        ManagedTest.setAcceptLanguage(null);
     }
 
     public TestMail waitForMail() {
-        try {
-            return ter.recieve();
-        } catch (InterruptedException e) {
-            throw new Error(e);
+        TestMail mail = null;
+        while (null == mail) {
+            try {
+                mail = ter.recieve();
+            } catch (InterruptedException e) {
+                throw new Error(e);
+            }
         }
+        return mail;
     }
 
     public static TestEmailReciever getMailReciever() {
index c07067e..a9ed464 100644 (file)
@@ -274,36 +274,40 @@ public class SimpleSigner {
                     subj.put("CN", "<empty>");
                     System.out.println("WARNING: DN was empty");
                 }
-                String[] call = new String[] {
-                        "openssl", "ca",//
-                        "-in",
-                        "../../" + csrname,//
-                        "-cert",
-                        "../" + ca + ".crt",//
-                        "-keyfile",
-                        "../" + ca + ".key",//
-                        "-out",
-                        "../../" + crt.getPath(),//
-                        "-utf8",
-                        "-startdate",
-                        sdf.format(fromDate),//
-                        "-enddate",
-                        sdf.format(toDate),//
-                        "-batch",//
-                        "-md",
-                        rs.getString("md"),//
-                        "-extfile",
-                        "../" + f.getName(),//
-
-                        "-subj",
-                        Certificate.stringifyDN(subj),//
-                        "-config",
-                        "../selfsign.config"//
-
-                };
+                String[] call;
+                synchronized (sdf) {
+                    call = new String[] {
+                            "openssl", "ca",//
+                            "-in",
+                            "../../" + csrname,//
+                            "-cert",
+                            "../" + ca + ".crt",//
+                            "-keyfile",
+                            "../" + ca + ".key",//
+                            "-out",
+                            "../../" + crt.getPath(),//
+                            "-utf8",
+                            "-startdate",
+                            sdf.format(fromDate),//
+                            "-enddate",
+                            sdf.format(toDate),//
+                            "-batch",//
+                            "-md",
+                            rs.getString("md"),//
+                            "-extfile",
+                            "../" + f.getName(),//
+
+                            "-subj",
+                            Certificate.stringifyDN(subj),//
+                            "-config",
+                            "../selfsign.config"//
+                    };
+                }
+
                 if (ct == CSRType.SPKAC) {
                     call[2] = "-spkac";
                 }
+
                 Process p1 = Runtime.getRuntime().exec(call, null, new File("keys/unassured.ca"));
 
                 int waitFor = p1.waitFor();