KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ca > store > CertificateInfo


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.core.model.ca.store;
15
16 import java.io.Serializable JavaDoc;
17 import java.io.UnsupportedEncodingException JavaDoc;
18 import java.math.BigInteger JavaDoc;
19 import java.security.MessageDigest JavaDoc;
20 import java.security.NoSuchAlgorithmException JavaDoc;
21 import java.security.NoSuchProviderException JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import org.bouncycastle.util.encoders.Hex;
25 import org.ejbca.core.model.protect.Protectable;
26
27 /**
28  * Holds information about a certificate but not the certiifcate itself.
29  *
30  * @version $Id: CertificateInfo.java,v 1.2 2006/08/06 12:37:01 anatom Exp $
31  */

32 public class CertificateInfo implements Serializable JavaDoc, Protectable {
33
34     protected String JavaDoc fingerprint;
35     protected String JavaDoc cafingerprint;
36     protected String JavaDoc serno;
37     protected String JavaDoc issuerdn;
38     protected String JavaDoc subjectdn;
39     protected int status;
40     protected int type;
41     protected Date JavaDoc expiredate;
42     protected Date JavaDoc revocationdate;
43     protected int revocationreason;
44     
45     public CertificateInfo(String JavaDoc fingerprint, String JavaDoc cafingerprint, String JavaDoc serno,
46             String JavaDoc issuerdn, String JavaDoc 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 JavaDoc(expiredate);
56         this.revocationdate=new Date JavaDoc(revocationdate);
57         this.revocationreason=revocationreason;
58     }
59     
60     public String JavaDoc getFingerprint() {return fingerprint;}
61     public void setFingerprint(String JavaDoc fp) {this.fingerprint=fp;}
62     public String JavaDoc getCAFingerprint() {return cafingerprint;}
63     public BigInteger JavaDoc getSerialNumber() {return new BigInteger JavaDoc(serno);}
64     public String JavaDoc getSubjectDN() {return subjectdn;}
65     public String JavaDoc 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 JavaDoc getExpireDate() { return expiredate; }
70     public Date JavaDoc getRevocationDate() { return revocationdate; }
71     public void setRevocationDate(Date JavaDoc d) { this.revocationdate=d; }
72     public int getRevocationReason() { return revocationreason; }
73
74     //
75
// Protectable
76
//
77
public int getHashVersion() {
78         return 1;
79     }
80     public String JavaDoc getDbKeyString() {
81         return fingerprint;
82     }
83     public String JavaDoc getEntryType() {
84         return "CERTIFICATEDATA";
85     }
86     public String JavaDoc getHash() throws NoSuchAlgorithmException JavaDoc, NoSuchProviderException JavaDoc, UnsupportedEncodingException JavaDoc {
87         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
88         // Don't include cafingerprint and type in the hash, because it is not avaiable in all places where we need to create protection
89
buf.append(fingerprint).append(issuerdn).append(subjectdn).append(status).
90             append(serno).append(expiredate).append(revocationdate).append(revocationreason);
91         MessageDigest JavaDoc digest = MessageDigest.getInstance("SHA-256", "BC");
92         byte[] result = digest.digest(buf.toString().getBytes("UTF-8"));
93         return new String JavaDoc(Hex.encode(result));
94     }
95     public String JavaDoc getHash(int version) throws NoSuchAlgorithmException JavaDoc, NoSuchProviderException JavaDoc, UnsupportedEncodingException JavaDoc {
96         return getHash();
97     }
98     
99
100 }
101
Popular Tags