]> WPIA git - gigi.git/commitdiff
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 ec3f69f2d581f09458a3c30757eba65b10d5058c..83cb9aaaf51b581da36edc6b46a4742fdb0e1248 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.Base64;
 import java.util.Date;
 import java.util.Properties;
+import java.util.Random;
 
 import javax.net.ssl.SSLSocketFactory;
 
 
 import javax.net.ssl.SSLSocketFactory;
 
@@ -39,6 +40,8 @@ import sun.security.x509.X509CertInfo;
 
 public class TestSendmail extends ConfiguredTest {
 
 
 public class TestSendmail extends ConfiguredTest {
 
+    private static final Random rng = new Random();
+
     @Test
     public void testSendmail() throws IOException, GeneralSecurityException {
         initSelfsign();
     @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));
         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"));
         AlgorithmId algID = AlgorithmId.get("SHA256WithRSA");
         info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algID));
         info.set(X509CertInfo.SUBJECT, new X500Name("EMAIL=system@cacert.org"));
index d9fb31e77fa2168dbc0e82cb642998f61aeff4d5..4ac5d910f3d9ba78f3a2f1f65a33c0ff35b784de 100644 (file)
@@ -169,7 +169,7 @@ public class ManagedTest extends ConfiguredTest {
 
     public static void clearCaches() throws IOException {
         ObjectCache.clearAllCaches();
 
     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");
     }
         URL u = new URL("https://" + getServerName() + "/manage");
         u.openConnection().getHeaderField("Location");
     }
@@ -219,15 +219,19 @@ public class ManagedTest extends ConfiguredTest {
 
     @After
     public void clearAcceptLanguage() {
 
     @After
     public void clearAcceptLanguage() {
-        acceptLanguage = null;
+        ManagedTest.setAcceptLanguage(null);
     }
 
     public TestMail waitForMail() {
     }
 
     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() {
     }
 
     public static TestEmailReciever getMailReciever() {
index c07067e5fc1be9c9f06ea15f7bc8440b1a8d9edb..a9ed46456a20680b0621d994183190c420b5be3e 100644 (file)
@@ -274,36 +274,40 @@ public class SimpleSigner {
                     subj.put("CN", "<empty>");
                     System.out.println("WARNING: DN was empty");
                 }
                     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";
                 }
                 if (ct == CSRType.SPKAC) {
                     call[2] = "-spkac";
                 }
+
                 Process p1 = Runtime.getRuntime().exec(call, null, new File("keys/unassured.ca"));
 
                 int waitFor = p1.waitFor();
                 Process p1 = Runtime.getRuntime().exec(call, null, new File("keys/unassured.ca"));
 
                 int waitFor = p1.waitFor();