]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/Certificate.java
Fix html conformance for the "explained radio button" forms.
[gigi.git] / src / org / cacert / gigi / Certificate.java
index f06247cfda90c1ca7628fade6e6b3d841b716cfc..8094419ba3473f2c95f43bc0f3ac461519ca2e52 100644 (file)
@@ -8,6 +8,7 @@ import java.io.InputStream;
 import java.security.GeneralSecurityException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
+import java.sql.Date;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -18,7 +19,6 @@ import java.util.List;
 
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.util.Job;
-import org.cacert.gigi.util.Job.JobType;
 import org.cacert.gigi.util.KeyStorage;
 import org.cacert.gigi.util.Notary;
 
@@ -38,7 +38,7 @@ public class Certificate {
         }
     }
 
-    public static class SubjectAlternateName {
+    public static class SubjectAlternateName implements Comparable<SubjectAlternateName> {
 
         private SANType type;
 
@@ -57,6 +57,49 @@ public class Certificate {
             return type;
         }
 
+        @Override
+        public int compareTo(SubjectAlternateName o) {
+            int i = type.compareTo(o.type);
+            if (i != 0) {
+                return i;
+            }
+            return name.compareTo(o.name);
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((name == null) ? 0 : name.hashCode());
+            result = prime * result + ((type == null) ? 0 : type.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            SubjectAlternateName other = (SubjectAlternateName) obj;
+            if (name == null) {
+                if (other.name != null) {
+                    return false;
+                }
+            } else if ( !name.equals(other.name)) {
+                return false;
+            }
+            if (type != other.type) {
+                return false;
+            }
+            return true;
+        }
+
     }
 
     public enum CSRType {
@@ -176,7 +219,23 @@ public class Certificate {
         return CertificateStatus.REVOKED;
     }
 
-    public Job issue() throws IOException, SQLException {
+    /**
+     * @param start
+     *            the date from which on the certificate should be valid. (or
+     *            null if it should be valid instantly)
+     * @param period
+     *            the period for which the date should be valid. (a
+     *            <code>yyyy-mm-dd</code> or a "2y" (2 calendar years), "6m" (6
+     *            months)
+     * @return A job which can be used to monitor the progress of this task.
+     * @throws IOException
+     *             for problems with writing the CSR/SPKAC
+     * @throws SQLException
+     *             for problems with writing to the DB
+     * @throws GigiApiException
+     *             if the period is bogus
+     */
+    public Job issue(Date start, String period) throws IOException, SQLException, GigiApiException {
         if (getStatus() != CertificateStatus.DRAFT) {
             throw new IllegalStateException();
         }
@@ -209,7 +268,7 @@ public class Certificate {
         updater.setString(1, csrName);
         updater.setInt(2, id);
         updater.execute();
-        return Job.submit(this, JobType.SIGN);
+        return Job.sign(this, start, period);
 
     }
 
@@ -217,7 +276,7 @@ public class Certificate {
         if (getStatus() != CertificateStatus.ISSUED) {
             throw new IllegalStateException();
         }
-        return Job.submit(this, JobType.REVOKE);
+        return Job.revoke(this);
 
     }