OCSPRespGenerator.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ocsp;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Ocsp
  7. {
  8. /**
  9. * base generator for an OCSP response - at the moment this only supports the
  10. * generation of responses containing BasicOCSP responses.
  11. */
  12. public class OCSPRespGenerator
  13. {
  14. public const int Successful = 0; // Response has valid confirmations
  15. public const int MalformedRequest = 1; // Illegal confirmation request
  16. public const int InternalError = 2; // Internal error in issuer
  17. public const int TryLater = 3; // Try again later
  18. // (4) is not used
  19. public const int SigRequired = 5; // Must sign the request
  20. public const int Unauthorized = 6; // Request unauthorized
  21. public OcspResp Generate(
  22. int status,
  23. object response)
  24. {
  25. if (response == null)
  26. {
  27. return new OcspResp(new OcspResponse(new OcspResponseStatus(status),null));
  28. }
  29. if (response is BasicOcspResp)
  30. {
  31. BasicOcspResp r = (BasicOcspResp)response;
  32. Asn1OctetString octs;
  33. try
  34. {
  35. octs = new DerOctetString(r.GetEncoded());
  36. }
  37. catch (Exception e)
  38. {
  39. throw new OcspException("can't encode object.", e);
  40. }
  41. ResponseBytes rb = new ResponseBytes(
  42. OcspObjectIdentifiers.PkixOcspBasic, octs);
  43. return new OcspResp(new OcspResponse(
  44. new OcspResponseStatus(status), rb));
  45. }
  46. throw new OcspException("unknown response object");
  47. }
  48. }
  49. }
  50. #pragma warning restore
  51. #endif