1 13 14 package org.ejbca.core.protocol.ocsp; 15 16 import org.bouncycastle.ocsp.BasicOCSPResp; 17 import org.bouncycastle.ocsp.OCSPException; 18 import org.bouncycastle.ocsp.OCSPResp; 19 import org.bouncycastle.ocsp.RevokedStatus; 20 import org.bouncycastle.ocsp.SingleResp; 21 import org.bouncycastle.ocsp.UnknownStatus; 22 23 29 public class OCSPUnidResponse { 30 31 35 public static final int OCSP_GOOD = 1; 36 public static final int OCSP_REVOKED = 2; 37 public static final int OCSP_UNKNOWN = 3; 38 39 45 public static final int ERROR_NO_ERROR = 0; 46 49 public static final int ERROR_UNKNOWN = 1; 50 53 public static final int ERROR_UNAUTHORIZED = 2; 54 57 public static final int ERROR_NO_RESPONSE = 3; 58 64 public static final int ERROR_INVALID_SIGNATURE = 4; 65 70 public static final int ERROR_INVALID_SIGNERID = 5; 71 75 public static final int ERROR_INVALID_SIGNERCERT = 6; 76 79 public static final int ERROR_NO_OCSP_URI = 5; 80 81 84 private OCSPResp resp = null; 85 private String fnr = null; 86 private int httpReturnCode = 200; 87 private int errCode = OCSPUnidResponse.ERROR_NO_ERROR; 88 89 public OCSPUnidResponse() { 90 } 91 public OCSPUnidResponse(OCSPResp ocspresp) { 92 this.resp = ocspresp; 93 } 94 public int getHttpReturnCode() { 95 return httpReturnCode; 96 } 97 public void setHttpReturnCode(int code) { 98 httpReturnCode = code; 99 } 100 public int getErrorCode() { 101 return errCode; 102 } 103 public void setErrorCode(int code) { 104 errCode = code; 105 } 106 public String getFnr() { 107 return fnr; 108 } 109 public void setFnr(String fnr) { 110 this.fnr = fnr; 111 } 112 public OCSPResp getResp() { 113 return resp; 114 } 115 public void setResp(OCSPResp resp) { 116 this.resp = resp; 117 } 118 public int getStatus() { 119 if (resp == null) { 120 return OCSPUnidResponse.OCSP_UNKNOWN; 121 } 122 try { 123 BasicOCSPResp brep; 124 brep = (BasicOCSPResp) resp.getResponseObject(); 125 SingleResp[] singleResps = brep.getResponses(); 126 SingleResp singleResp = singleResps[0]; 127 Object status = singleResp.getCertStatus(); 128 if (status == null) { 129 return OCSPUnidResponse.OCSP_GOOD; 130 } 131 if (status instanceof RevokedStatus) { 132 return OCSPUnidResponse.OCSP_REVOKED; 133 } 134 if (status instanceof UnknownStatus) { 135 return OCSPUnidResponse.OCSP_UNKNOWN; 136 } 137 } catch (OCSPException e) { 138 } 140 return OCSPUnidResponse.OCSP_UNKNOWN; 141 142 } 143 144 145 } 146 | Popular Tags |