Example #1
0
bool RequestParser::doWebSocketHandshake00(const Request& req)
{
  const Request::Header *k1 = req.getHeader("Sec-WebSocket-Key1");
  const Request::Header *k2 = req.getHeader("Sec-WebSocket-Key2");
  const Request::Header *origin = req.getHeader("Origin");

  if (k1 && k2 && origin) {
    ::uint32_t n1, n2;

    if (parseCrazyWebSocketKey(k1->value, n1)
	&& parseCrazyWebSocketKey(k2->value, n2)) {
      unsigned char key3[8];
      memcpy(key3, ws00_buf_, 8);

      ::uint32_t v;

      v = htonl(n1);
      memcpy(ws00_buf_, &v, 4);

      v = htonl(n2);
      memcpy(ws00_buf_ + 4, &v, 4);

      memcpy(ws00_buf_ + 8, key3, 8);

      std::string md5 = Wt::Utils::md5(std::string(ws00_buf_, 16));
      memcpy(ws00_buf_, md5.c_str(), 16);

      return true;
    } else
      return false;
  } else
    return false;
}
Example #2
0
bool RequestParser::doWebSocketHandshake00(const Request& req)
{
  Request::HeaderMap::const_iterator k1, k2, origin;

  k1 = req.headerMap.find("Sec-WebSocket-Key1");
  k2 = req.headerMap.find("Sec-WebSocket-Key2");
  origin = req.headerMap.find("Origin");

  if (k1 != req.headerMap.end() && k2 != req.headerMap.end()
      && origin != req.headerMap.end()) {
    ::uint32_t n1, n2;

    if (parseCrazyWebSocketKey(k1->second, n1)
	&& parseCrazyWebSocketKey(k2->second, n2)) {
      unsigned char key3[8];
      memcpy(key3, buf_, 8);

      ::uint32_t v;

      v = htonl(n1);
      memcpy(buf_, &v, 4);

      v = htonl(n2);
      memcpy(buf_ + 4, &v, 4);

      memcpy(buf_ + 8, key3, 8);

      std::string md5 = Wt::Utils::md5(std::string(buf_, 16));
      memcpy(buf_, md5.c_str(), 16);

      return true;
    } else
      return false;
  } else
    return false;
}