public override void handlePOSTRequest(HttpProcessor p, MemoryStream ms) { try { byte[] ocspdata = ms.ToArray(); OcspReq req = new OcspReq(ocspdata); GeneralName name = req.RequestorName; if (validator != null) { string stat = "GOOD"; foreach (CertificateID id in req.GetIDs()) { Stopwatch st = new Stopwatch(); st.Start(); OCSPCache cac = GetCache(id.SerialNumber.LongValue); if (cac != null) { Console.Write("[CACHED] "); string header = GetRFC822Date(cac.CacheTime); byte[] responseBytes = cac.data; p.outputStream.WriteLine("HTTP/1.1 200 OK"); p.outputStream.WriteLine("content-transfer-encoding: binary"); p.outputStream.WriteLine("Last-Modified: " + header); p.outputStream.WriteLine("Content-Type: application/ocsp-response"); p.outputStream.WriteLine("Connection: keep-alive"); p.outputStream.WriteLine("Accept-Ranges: bytes"); p.outputStream.WriteLine("Server: AS-OCSP-1.0"); p.outputStream.WriteLine("Content-Length: " + responseBytes.Length.ToString()); p.outputStream.WriteLine(""); p.outputStream.WriteContent(responseBytes); } else { // validate OCSPRespGenerator gen = new OCSPRespGenerator(); BasicOcspRespGenerator resp = new BasicOcspRespGenerator(validator.CACert.GetPublicKey()); DerGeneralizedTime dt = new DerGeneralizedTime(DateTime.Parse("03/09/2014 14:00:00")); CrlReason reason = new CrlReason(CrlReason.CACompromise); if (validator.IsRevoked(id, ref dt, ref reason)) { RevokedInfo rinfo = new RevokedInfo(dt, reason); RevokedStatus rstatus = new RevokedStatus(rinfo); resp.AddResponse(id, rstatus); stat = "REVOKED"; } else { resp.AddResponse(id, CertificateStatus.Good); } BasicOcspResp response = resp.Generate("SHA1withRSA", validator.CAKey, new X509Certificate[] { validator.CACert }, DateTime.Now); OcspResp or = gen.Generate(OCSPRespGenerator.Successful, response); string header = GetRFC822Date(DateTime.Now); byte[] responseBytes = or.GetEncoded(); AddCache(responseBytes, id.SerialNumber.LongValue); p.outputStream.WriteLine("HTTP/1.1 200 OK"); p.outputStream.WriteLine("content-transfer-encoding: binary"); p.outputStream.WriteLine("Last-Modified: " + header); p.outputStream.WriteLine("Content-Type: application/ocsp-response"); p.outputStream.WriteLine("Connection: keep-alive"); p.outputStream.WriteLine("Accept-Ranges: bytes"); p.outputStream.WriteLine("Server: AS-OCSP-1.0"); p.outputStream.WriteLine("Content-Length: " + responseBytes.Length.ToString()); p.outputStream.WriteLine(""); p.outputStream.WriteContent(responseBytes); } Console.Write(id.SerialNumber + " PROCESSED IN " + st.Elapsed + " STATUS " + stat); Console.WriteLine(""); } } else { p.writeFailure(); } } catch (Exception ex) { Console.WriteLine("OCSP Server Error : " + ex.Message); } }