001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.core.model.ca.store;
013:
014: import java.io.Serializable;
015: import java.io.UnsupportedEncodingException;
016: import java.math.BigInteger;
017: import java.security.MessageDigest;
018: import java.security.NoSuchAlgorithmException;
019: import java.security.NoSuchProviderException;
020: import java.util.Date;
021:
022: import org.bouncycastle.util.encoders.Hex;
023: import org.ejbca.core.model.protect.Protectable;
024:
025: /**
026: * Holds information about a certificate but not the certiifcate itself.
027: *
028: * @version $Id: CertificateInfo.java,v 1.2 2006/08/06 12:37:01 anatom Exp $
029: */
030: public class CertificateInfo implements Serializable, Protectable {
031:
032: protected String fingerprint;
033: protected String cafingerprint;
034: protected String serno;
035: protected String issuerdn;
036: protected String subjectdn;
037: protected int status;
038: protected int type;
039: protected Date expiredate;
040: protected Date revocationdate;
041: protected int revocationreason;
042:
043: public CertificateInfo(String fingerprint, String cafingerprint,
044: String serno, String issuerdn, String subjectdn,
045: int status, int type, long expiredate, long revocationdate,
046: int revocationreason) {
047: this .fingerprint = fingerprint;
048: this .cafingerprint = cafingerprint;
049: this .serno = serno;
050: this .issuerdn = issuerdn;
051: this .subjectdn = subjectdn;
052: this .status = status;
053: this .type = type;
054: this .expiredate = new Date(expiredate);
055: this .revocationdate = new Date(revocationdate);
056: this .revocationreason = revocationreason;
057: }
058:
059: public String getFingerprint() {
060: return fingerprint;
061: }
062:
063: public void setFingerprint(String fp) {
064: this .fingerprint = fp;
065: }
066:
067: public String getCAFingerprint() {
068: return cafingerprint;
069: }
070:
071: public BigInteger getSerialNumber() {
072: return new BigInteger(serno);
073: }
074:
075: public String getSubjectDN() {
076: return subjectdn;
077: }
078:
079: public String getIssuerDN() {
080: return issuerdn;
081: }
082:
083: public int getStatus() {
084: return status;
085: }
086:
087: public void setStatus(int s) {
088: this .status = s;
089: }
090:
091: public int getType() {
092: return type;
093: }
094:
095: public Date getExpireDate() {
096: return expiredate;
097: }
098:
099: public Date getRevocationDate() {
100: return revocationdate;
101: }
102:
103: public void setRevocationDate(Date d) {
104: this .revocationdate = d;
105: }
106:
107: public int getRevocationReason() {
108: return revocationreason;
109: }
110:
111: //
112: // Protectable
113: //
114: public int getHashVersion() {
115: return 1;
116: }
117:
118: public String getDbKeyString() {
119: return fingerprint;
120: }
121:
122: public String getEntryType() {
123: return "CERTIFICATEDATA";
124: }
125:
126: public String getHash() throws NoSuchAlgorithmException,
127: NoSuchProviderException, UnsupportedEncodingException {
128: StringBuffer buf = new StringBuffer();
129: // Don't include cafingerprint and type in the hash, because it is not avaiable in all places where we need to create protection
130: buf.append(fingerprint).append(issuerdn).append(subjectdn)
131: .append(status).append(serno).append(expiredate)
132: .append(revocationdate).append(revocationreason);
133: MessageDigest digest = MessageDigest.getInstance("SHA-256",
134: "BC");
135: byte[] result = digest.digest(buf.toString().getBytes("UTF-8"));
136: return new String(Hex.encode(result));
137: }
138:
139: public String getHash(int version) throws NoSuchAlgorithmException,
140: NoSuchProviderException, UnsupportedEncodingException {
141: return getHash();
142: }
143:
144: }
|