OCSPDenier.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2002-2009 Moxie Marlinspike
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 3 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. * USA
  18. */
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "OCSPDenier.hpp"
  22. #include "../Logger.hpp"
  23. using namespace boost::asio;
  24. OCSPDenier* OCSPDenier::ocspDenier = new OCSPDenier();
  25. const char* OCSPDenier::ocspResponse = "HTTP/1.0 200 Ok\r\ncontent-type: application/ocsp-response\r\ncontent-transfer-encoding: binary\r\ncontent-length: 1\r\nconnection: close\r\n\r\n3";
  26. OCSPDenier* OCSPDenier::getInstance() {
  27. return ocspDenier;
  28. }
  29. void OCSPDenier::denyOCSPRequest(boost::shared_ptr<ip::tcp::socket> socket) {
  30. boost::shared_ptr<unsigned char> buffer((unsigned char*)malloc(1024), free);
  31. boost::shared_ptr<HttpHeaders> headers(new HttpHeaders());
  32. socket->async_read_some(boost::asio::buffer(buffer.get(), 1024),
  33. boost::bind(&OCSPDenier::readComplete, this,
  34. socket, buffer, headers,
  35. placeholders::error,
  36. placeholders::bytes_transferred));
  37. }
  38. void OCSPDenier::readComplete(boost::shared_ptr<ip::tcp::socket> socket,
  39. boost::shared_ptr<unsigned char> buffer,
  40. boost::shared_ptr<HttpHeaders> headers,
  41. const boost::system::error_code &error,
  42. size_t bytesRead)
  43. {
  44. if (error) {
  45. Logger::logError("Error reading OCSP request.");
  46. return;
  47. }
  48. if (headers->process((char*)buffer.get(), bytesRead)) {
  49. async_write(*socket, boost::asio::buffer(ocspResponse, strlen(ocspResponse)),
  50. boost::bind(&OCSPDenier::writeComplete, this, socket, placeholders::error));
  51. }
  52. }
  53. void OCSPDenier::writeComplete(boost::shared_ptr<ip::tcp::socket> socket,
  54. const boost::system::error_code &error)
  55. {
  56. Logger::logError("OCSP Denial Sent.");
  57. }