]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Certificate.java
Fix: Stacktrace on certificate generation timeout.
[gigi.git] / src / org / cacert / gigi / dbObjects / Certificate.java
index ced044cd8d34a102fa68875e0b9d6604d7fbfdea..6882b8113018c4c41af40bf54f5844f176a9878b 100644 (file)
@@ -206,7 +206,7 @@ public class Certificate {
 
     }
 
-    public CertificateStatus getStatus() {
+    public synchronized CertificateStatus getStatus() {
         if (id == 0) {
             return CertificateStatus.DRAFT;
         }
@@ -273,9 +273,9 @@ public class Certificate {
         }
         File csrFile = KeyStorage.locateCsr(id);
         csrName = csrFile.getPath();
-        FileOutputStream fos = new FileOutputStream(csrFile);
-        fos.write(csr.getBytes());
-        fos.close();
+        try (FileOutputStream fos = new FileOutputStream(csrFile)) {
+            fos.write(csr.getBytes("UTF-8"));
+        }
 
         GigiPreparedStatement updater = DatabaseConnection.getInstance().prepare("UPDATE certs SET csr_name=? WHERE id=?");
         updater.setString(1, csrName);
@@ -347,6 +347,9 @@ public class Certificate {
     }
 
     public static Certificate getBySerial(String serial) {
+        if (serial == null || "".equals(serial)) {
+            return null;
+        }
         // TODO caching?
         try {
             return new Certificate(serial);