pike.git / lib / modules / SSL.pmod / Connection.pike

version» Context lines:

pike.git/lib/modules/SSL.pmod/Connection.pike:81:      Alert alert(int(1..2) level, int(8bit) description,    string|void message)   {    return context->alert_factory(this, level, description, version,    message);   }      string(8bit) get_signature_algorithms()   { -  ADT.struct sign_algs = ADT.struct(); +  Stdio.Buffer sign_algs = Stdio.Buffer();    foreach(context->get_signature_algorithms(), [int hash, int sign])    { -  sign_algs->put_uint(hash, 1); -  sign_algs->put_uint(sign, 1); +  sign_algs->add_int(hash, 1); +  sign_algs->add_int(sign, 1);    } -  return sign_algs->pop_data(); +  return (string(8bit))sign_algs;   }      #ifdef SSL3_PROFILING   System.Timer timer = System.Timer();   void addRecord(int t,int s) {    Stdio.stdout.write("time: %.6f sender: %d type: %s\n", timer->get(), s,    fmt_constant(t, "HANDSHAKE"));   }   #endif   
pike.git/lib/modules/SSL.pmod/Connection.pike:182:    // by crafting a heartbeat packet with insufficient (0) padding.    //    // If we get a response, the peer doesn't validate the message sizes    // properly, and probably suffers from the Heartbleed vulnerability.    //    // Note that we don't use negative padding (as per the actual attack),    // to avoid actually stealing information from the peer.    //    // Note that we detect the packet on return by it having all zeros    // in the second field. -  ADT.struct hb_msg = ADT.struct(); -  hb_msg->put_uint(HEARTBEAT_MESSAGE_request, 1); -  hb_msg->put_uint(16, 2); +  Stdio.Buffer hb_msg = Stdio.Buffer(); +  hb_msg->add_int(HEARTBEAT_MESSAGE_request, 1); +  hb_msg->add_int(16, 2);    int now = gethrtime(); -  hb_msg->put_fix_string(heartbeat_encode->crypt(sprintf("%8c%8c", now, 0))); +  hb_msg->add(heartbeat_encode->crypt(sprintf("%8c%8c", now, 0)));    // No padding. -  return heartbeat_packet(hb_msg->pop_data()); +  return heartbeat_packet((string(8bit))hb_msg);   }      // verify that a certificate chain is acceptable   //   int verify_certificate_chain(array(string) certs)   {    // do we need to verify the certificate chain?    if(!context->verify_certificates)    return 1;   
pike.git/lib/modules/SSL.pmod/Connection.pike:612:   }      void send_heartbeat()   {    if ((state != CONNECTION_ready) ||    (session->heartbeat_mode != HEARTBEAT_MODE_peer_allowed_to_send)) {    // We're not allowed to send heartbeats.    return;    }    -  ADT.struct hb_msg = ADT.struct(); -  hb_msg->put_uint(HEARTBEAT_MESSAGE_request, 1); -  hb_msg->put_uint(16, 2); +  Stdio.Buffer hb_msg = Stdio.Buffer(); +  hb_msg->add_int(HEARTBEAT_MESSAGE_request, 1); +  hb_msg->add_int(16, 2);    int now = gethrtime(); -  hb_msg->put_fix_string(heartbeat_encode->crypt(sprintf("%8c%8c", now, now))); +  hb_msg->add(heartbeat_encode->crypt(sprintf("%8c%8c", now, now)));    // We pad to an even 64 bytes. -  hb_msg->put_fix_string(random_string(64 - sizeof(hb_msg))); -  send_packet(heartbeat_packet(hb_msg->pop_data())); +  hb_msg->add(random_string(64 - sizeof(hb_msg))); +  send_packet(heartbeat_packet((string(8bit))hb_msg));   }      void handle_heartbeat(string(8bit) s)   {    if (sizeof(s) < 19) return; // Minimum size for valid heartbeats. -  ADT.struct hb_msg = ADT.struct(s); -  int hb_type = hb_msg->get_uint(1); -  int hb_len = hb_msg->get_uint(2); +  Stdio.Buffer hb_msg = Stdio.Buffer(s); +  int hb_type = hb_msg->read_int(1); +  int hb_len = hb_msg->read_int(2);       SSL3_DEBUG_MSG("SSL.Connection: Heartbeat %s (%d bytes)",    fmt_constant(hb_type, "HEARTBEAT_MESSAGE"), hb_len);       string(8bit) payload;    int pad_len = 16;       // RFC 6520 4:    // If the payload_length of a received HeartbeatMessage is too    // large, the received HeartbeatMessage MUST be discarded silently.    if ((hb_len < 0) || ((hb_len + 16) > sizeof(hb_msg))) {   #ifdef SSL3_SIMULATE_HEARTBLEED -  payload = hb_msg->get_rest(); +  payload = hb_msg->read();    if (sizeof(payload) < hb_len) {    payload = payload + random_string(hb_len - sizeof(payload));    } else {    payload = payload[..hb_len-1];    }   #else    return;   #endif    } else { -  payload = hb_msg->get_fix_string(hb_len); +  payload = hb_msg->read(hb_len);    pad_len = sizeof(hb_msg);    }       switch(hb_type) {    case HEARTBEAT_MESSAGE_request:    // RFC 6520 4:    // When a HeartbeatRequest message is received and sending a    // HeartbeatResponse is not prohibited as described elsewhere in    // this document, the receiver MUST send a corresponding    // HeartbeatResponse message carrying an exact copy of the payload    // of the received HeartbeatRequest. -  hb_msg = ADT.struct(); -  hb_msg->put_uint(HEARTBEAT_MESSAGE_response, 1); -  hb_msg->put_uint(hb_len, 2); -  hb_msg->put_fix_string(payload); -  hb_msg->put_fix_string(random_string(pad_len)); -  send_packet(heartbeat_packet(hb_msg->pop_data())); +  hb_msg = Stdio.Buffer(); +  hb_msg->add_int(HEARTBEAT_MESSAGE_response, 1); +  hb_msg->add_int(hb_len, 2); +  hb_msg->add(payload); +  hb_msg->add(random_string(pad_len)); +  send_packet(heartbeat_packet((string(8bit))hb_msg));    break;    case HEARTBEAT_MESSAGE_response:    // RFC 6520 4:    // If a received HeartbeatResponse message does not contain the    // expected payload, the message MUST be discarded silently.    if ((sizeof(payload) == 16) && heartbeat_decode) { -  hb_msg = ADT.struct(heartbeat_decode->crypt(payload)); -  int a = hb_msg->get_uint(8); -  int b = hb_msg->get_uint(8); +  hb_msg = Stdio.Buffer(heartbeat_decode->crypt(payload)); +  int a = hb_msg->read_int(8); +  int b = hb_msg->read_int(8);    if (a != b) {    if (!b) {    // Heartbleed probe response.    send_packet(alert(ALERT_fatal, ALERT_insufficient_security,    "Peer suffers from a bleeding heart.\n"));    }    break;    }   #ifdef SSL3_DEBUG    int delta = gethrtime() - a;