Home | History | Annotate | Download | only in ocsp
      1 package org.bouncycastle.cert.ocsp;
      2 
      3 import java.io.IOException;
      4 
      5 import org.bouncycastle.asn1.ASN1OctetString;
      6 import org.bouncycastle.asn1.DEROctetString;
      7 import org.bouncycastle.asn1.ocsp.OCSPObjectIdentifiers;
      8 import org.bouncycastle.asn1.ocsp.OCSPResponse;
      9 import org.bouncycastle.asn1.ocsp.OCSPResponseStatus;
     10 import org.bouncycastle.asn1.ocsp.ResponseBytes;
     11 
     12 /**
     13  * base generator for an OCSP response - at the moment this only supports the
     14  * generation of responses containing BasicOCSP responses.
     15  */
     16 public class OCSPRespBuilder
     17 {
     18     public static final int SUCCESSFUL = 0;  // Response has valid confirmations
     19     public static final int MALFORMED_REQUEST = 1;  // Illegal confirmation request
     20     public static final int INTERNAL_ERROR = 2;  // Internal error in issuer
     21     public static final int TRY_LATER = 3;  // Try again later
     22     // (4) is not used
     23     public static final int SIG_REQUIRED = 5;  // Must sign the request
     24     public static final int UNAUTHORIZED = 6;  // Request unauthorized
     25 
     26     public OCSPResp build(
     27         int status,
     28         Object response)
     29         throws OCSPException
     30     {
     31         if (response == null)
     32         {
     33             return new OCSPResp(new OCSPResponse(new OCSPResponseStatus(status), null));
     34         }
     35 
     36         if (response instanceof BasicOCSPResp)
     37         {
     38             BasicOCSPResp r = (BasicOCSPResp)response;
     39             ASN1OctetString octs;
     40 
     41             try
     42             {
     43                 octs = new DEROctetString(r.getEncoded());
     44             }
     45             catch (IOException e)
     46             {
     47                 throw new OCSPException("can't encode object.", e);
     48             }
     49 
     50             ResponseBytes rb = new ResponseBytes(
     51                 OCSPObjectIdentifiers.id_pkix_ocsp_basic, octs);
     52 
     53             return new OCSPResp(new OCSPResponse(
     54                 new OCSPResponseStatus(status), rb));
     55         }
     56 
     57         throw new OCSPException("unknown response object");
     58     }
     59 }
     60