]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/Certificate.java
Adding "Error" as Certificate status.
[gigi.git] / src / org / cacert / gigi / Certificate.java
index c5aaf3fdd3f650f1f89f37aaaf9973bce36f09e1..c6924132cdc8c0445e3bcbee2e88d34112251b31 100644 (file)
@@ -16,29 +16,62 @@ import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.util.KeyStorage;
 
 public class Certificate {
-       int id;
-       int serial;
-       String dn;
-       String md;
-       String csrName;
-       String crtName;
-       String csr = null;
+       private int id;
+       private int serial;
+       private String dn;
+       private String md;
+       private String csrName;
+       private String crtName;
+       private String csr = null;
        public Certificate(String dn, String md, String csr) {
                this.dn = dn;
                this.md = md;
                this.csr = csr;
        }
 
-       // created, modified, revoked, expire
        public enum CertificateStatus {
-               DRAFT(false), BEEING_ISSUED(true), ISSUED(false), BEEING_REVOKED(true), REVOKED(
-                               false);
+               /**
+                * This certificate is not in the database, has no id and only exists as
+                * this java object.
+                */
+               DRAFT(false),
+               /**
+                * The certificate has been written to the database and is waiting for
+                * the signer to sign it.
+                */
+               SIGNING(true),
+               /**
+                * The certificate has been signed. It is stored in the database.
+                * {@link Certificate#cert()} is valid.
+                */
+               ISSUED(false),
+               /**
+                * The cetrificate is about to be revoked by the signer bot.
+                */
+               BEING_REVOKED(true),
 
-               boolean unstable;
+               /**
+                * The certificate has been revoked.
+                */
+               REVOKED(false),
+
+               /**
+                * If this certificate cannot be updated because an error happened in
+                * the signer.
+                */
+               ERROR(false);
+
+               private boolean unstable;
 
                private CertificateStatus(boolean unstable) {
                        this.unstable = unstable;
                }
+               /**
+                * Checks, iff this certificate stage will be left by signer actions.
+                * 
+                * @return True, iff this certificate stage will be left by signer
+                *         actions.
+                */
                public boolean isUnstable() {
                        return unstable;
                }
@@ -48,15 +81,21 @@ public class Certificate {
                if (id == 0) {
                        return CertificateStatus.DRAFT;
                }
-               PreparedStatement searcher = DatabaseConnection.getInstance().prepare(
-                               "SELECT crt_name, created, revoked FROM emailcerts WHERE id=?");
+               PreparedStatement searcher = DatabaseConnection
+                               .getInstance()
+                               .prepare(
+                                               "SELECT crt_name, created, revoked, warning FROM emailcerts WHERE id=?");
                searcher.setInt(1, id);
                ResultSet rs = searcher.executeQuery();
                if (!rs.next()) {
                        throw new IllegalStateException("Certificate not in Database");
                }
+               if (rs.getInt(4) >= 3) {
+                       return CertificateStatus.ERROR;
+               }
+
                if (rs.getString(2) == null) {
-                       return CertificateStatus.BEEING_ISSUED;
+                       return CertificateStatus.SIGNING;
                }
                crtName = rs.getString(1);
                System.out.println(crtName);
@@ -65,7 +104,7 @@ public class Certificate {
                }
                if (rs.getTime(2) != null
                                && rs.getString(3).equals("1970-01-01 00:00:00.0")) {
-                       return CertificateStatus.BEEING_REVOKED;
+                       return CertificateStatus.BEING_REVOKED;
                }
                return CertificateStatus.REVOKED;
        }
@@ -148,5 +187,17 @@ public class Certificate {
        public Certificate renew() {
                return null;
        }
+       public int getId() {
+               return id;
+       }
+       public int getSerial() {
+               return serial;
+       }
+       public String getDistinguishedName() {
+               return dn;
+       }
+       public String getMessageDigest() {
+               return md;
+       }
 
 }