X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FCertificate.java;h=433e60e49b62a5bc6a97444d3ff7f1c104622c59;hb=ef11aeb0f387e935ee898b6870fcca64ec909cc5;hp=a2645c62d22ebe231b496e15fe22519602febc7d;hpb=b0a970a60d0001260594468f3ffffbf92a19bc44;p=gigi.git diff --git a/src/org/cacert/gigi/Certificate.java b/src/org/cacert/gigi/Certificate.java index a2645c62..433e60e4 100644 --- a/src/org/cacert/gigi/Certificate.java +++ b/src/org/cacert/gigi/Certificate.java @@ -38,7 +38,7 @@ public class Certificate { } } - public static class SubjectAlternateName { + public static class SubjectAlternateName implements Comparable { 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 { @@ -83,18 +126,21 @@ public class Certificate { private List sans; - public Certificate(int ownerId, String dn, String md, String csr, CSRType csrType, SubjectAlternateName... sans) { + private CertificateProfile profile; + + public Certificate(int ownerId, String dn, String md, String csr, CSRType csrType, CertificateProfile profile, SubjectAlternateName... sans) { this.ownerId = ownerId; this.dn = dn; this.md = md; this.csr = csr; this.csrType = csrType; + this.profile = profile; this.sans = Arrays.asList(sans); } private Certificate(String serial) { try { - PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id,subject, md, csr_name, crt_name,memid FROM `certs` WHERE serial=?"); + PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id,subject, md, csr_name, crt_name,memid, profile FROM `certs` WHERE serial=?"); ps.setString(1, serial); ResultSet rs = ps.executeQuery(); if ( !rs.next()) { @@ -106,6 +152,7 @@ public class Certificate { csrName = rs.getString(4); crtName = rs.getString(5); ownerId = rs.getInt(6); + profile = CertificateProfile.getById(rs.getInt(7)); this.serial = serial; PreparedStatement ps2 = DatabaseConnection.getInstance().prepare("SELECT contents, type FROM `subjectAlternativeNames` WHERE certId=?"); @@ -178,11 +225,12 @@ public class Certificate { } Notary.writeUserAgreement(ownerId, "CCA", "issue certificate", "", true, 0); - PreparedStatement inserter = DatabaseConnection.getInstance().prepare("INSERT INTO certs SET md=?, subject=?, csr_type=?, crt_name='', memid=?, profile=1"); + PreparedStatement inserter = DatabaseConnection.getInstance().prepare("INSERT INTO certs SET md=?, subject=?, csr_type=?, crt_name='', memid=?, profile=?"); inserter.setString(1, md); inserter.setString(2, dn); inserter.setString(3, csrType.toString()); inserter.setInt(4, ownerId); + inserter.setInt(5, profile.getId()); inserter.execute(); id = DatabaseConnection.lastInsertId(inserter); File csrFile = KeyStorage.locateCsr(id); @@ -264,10 +312,14 @@ public class Certificate { return ownerId; } - public List getSans() { + public List getSANs() { return Collections.unmodifiableList(sans); } + public CertificateProfile getProfile() { + return profile; + } + public static Certificate getBySerial(String serial) { // TODO caching? try {