1 13 14 package org.ejbca.core.model.ca.store; 15 16 import java.io.Serializable ; 17 import java.io.UnsupportedEncodingException ; 18 import java.math.BigInteger ; 19 import java.security.MessageDigest ; 20 import java.security.NoSuchAlgorithmException ; 21 import java.security.NoSuchProviderException ; 22 import java.util.Date ; 23 24 import org.bouncycastle.util.encoders.Hex; 25 import org.ejbca.core.model.protect.Protectable; 26 27 32 public class CertificateInfo implements Serializable , Protectable { 33 34 protected String fingerprint; 35 protected String cafingerprint; 36 protected String serno; 37 protected String issuerdn; 38 protected String subjectdn; 39 protected int status; 40 protected int type; 41 protected Date expiredate; 42 protected Date revocationdate; 43 protected int revocationreason; 44 45 public CertificateInfo(String fingerprint, String cafingerprint, String serno, 46 String issuerdn, String subjectdn, int status, int type, 47 long expiredate, long revocationdate, int revocationreason){ 48 this.fingerprint=fingerprint; 49 this.cafingerprint=cafingerprint; 50 this.serno=serno; 51 this.issuerdn=issuerdn; 52 this.subjectdn=subjectdn; 53 this.status=status; 54 this.type=type; 55 this.expiredate=new Date (expiredate); 56 this.revocationdate=new Date (revocationdate); 57 this.revocationreason=revocationreason; 58 } 59 60 public String getFingerprint() {return fingerprint;} 61 public void setFingerprint(String fp) {this.fingerprint=fp;} 62 public String getCAFingerprint() {return cafingerprint;} 63 public BigInteger getSerialNumber() {return new BigInteger (serno);} 64 public String getSubjectDN() {return subjectdn;} 65 public String getIssuerDN() {return issuerdn;} 66 public int getStatus() { return status; } 67 public void setStatus(int s) { this.status=s; } 68 public int getType() { return type; } 69 public Date getExpireDate() { return expiredate; } 70 public Date getRevocationDate() { return revocationdate; } 71 public void setRevocationDate(Date d) { this.revocationdate=d; } 72 public int getRevocationReason() { return revocationreason; } 73 74 public int getHashVersion() { 78 return 1; 79 } 80 public String getDbKeyString() { 81 return fingerprint; 82 } 83 public String getEntryType() { 84 return "CERTIFICATEDATA"; 85 } 86 public String getHash() throws NoSuchAlgorithmException , NoSuchProviderException , UnsupportedEncodingException { 87 StringBuffer buf = new StringBuffer (); 88 buf.append(fingerprint).append(issuerdn).append(subjectdn).append(status). 90 append(serno).append(expiredate).append(revocationdate).append(revocationreason); 91 MessageDigest digest = MessageDigest.getInstance("SHA-256", "BC"); 92 byte[] result = digest.digest(buf.toString().getBytes("UTF-8")); 93 return new String (Hex.encode(result)); 94 } 95 public String getHash(int version) throws NoSuchAlgorithmException , NoSuchProviderException , UnsupportedEncodingException { 96 return getHash(); 97 } 98 99 100 } 101 | Popular Tags |