A .NET facility to create an OCSP Responder
OCSPResponder is a library written in C# that enables you to easily create an OCSP Responder in .NET. All you need is to implement an interface for the CA/Authorized Responder. It follows the OCSP protocol defined in RFC 6960.
- Install OCSPResponder.AspNetCore via NuGet. This package contains OCSPResponder.Core as dependency.
- Implement the IOcspResponderRepository interface for your CA.
- Configure in your Dependency Injector to use the class OcspResponder for the interface IOcspResponder.
- Configure in your Dependency Injector to use the class that you implemented for the interface IOcspResponderRepository.
- Create a WebAPI Controller and call OcspResponder.Respond() passing the HttpRequest.ToOcspRequest().
- Done! You've been configured your OCSP Responder.
/Controllers/OcspController.cs
[Route("api/ocsp")]
public class OcspController : Controller
{
[HttpGet]
public async Task<IActionResult> Get(string encoded)
{
var ocspHttpRequest = await Request.ToOcspHttpRequest();
var ocspHttpResponse = await OcspResponder.Respond(ocspHttpRequest);
return new OcspActionResult(ocspHttpResponse);
}
[HttpPost]
public async Task<IActionResult> Post()
{
var ocspHttpRequest = await Request.ToOcspHttpRequest();
var ocspHttpResponse = await OcspResponder.Respond(ocspHttpRequest);
return new OcspActionResult(ocspHttpResponse);
}
private IOcspResponder OcspResponder { get; }
public OcspController(IOcspResponder ocspResponder)
{
OcspResponder = ocspResponder;
}
}
- Install OCSPResponder.Core via NuGet.
- Implement the IOcspResponderRepository interface for your CA.
- Configure in your Dependency Injector to use the class OcspResponder for the interface IOcspResponder.
- Configure in your Dependency Injector to use the class that you implemented for the interface IOcspResponderRepository.
- Create a WebAPI Controller and call OcspResponder.Respond() passing the HttpRequestMessage.ToOcspHttpRequest().
- Done! You've been configured your OCSP Responder.
/Controllers/OcspController.cs
[RoutePrefix("api/ocsp")]
public class OcspController : Controller
{
[Route("{encoded}"]
public Task<HttpResponseMessage> Get(string encoded)
{
var ocspHttpResponse = await OcspResponder.Respond(Request.ToOcspHttpRequest());
return ocspHttpResponse.toHttpResponseMessage();
}
[Route("")]
public Task<HttpResponseMessage> Post()
{
var ocspHttpResponse = await OcspResponder.Respond(Request.ToOcspHttpRequest());
return ocspHttpResponse.toHttpResponseMessage();
}
private IOcspResponder OcspResponder { get; }
public OcspController(IOcspResponder ocspResponder)
{
OcspResponder = ocspResponder;
}
}
Code by Gabriel Calegari. Copyright 2018 Gabriel Calegari.
This library is intended to be used in both open-source and commercial environments. It is under Apache 2.0 license.
Refer to the LICENSE for detailed information.
If you have a feature request or bug report, leave an issue on the issues page or send a pull request. For general questions and comments, use the StackOverflow forum.