return result;
}
+int
+Ssl::Bio::readAndBuffer(char *buf, int size, BIO *table, const char *description)
+{
+ prepReadBuf();
+
+ size = min((int)rbuf.potentialSpaceSize(), size);
+ if (size <= 0) {
+ debugs(83, DBG_IMPORTANT, "Not enough space to hold " <<
+ rbuf.contentSize() << "+ byte " << description);
+ return -1;
+ }
+
+ const int bytes = Ssl::Bio::read(buf, size, table);
+ debugs(83, 5, "read " << bytes << " out of " << size << " bytes"); // move to Ssl::Bio::read()
+
+ if (bytes > 0) {
+ rbuf.append(buf, bytes);
+ debugs(83, 5, "recorded " << bytes << " bytes of " << description);
+ }
+ return bytes;
+ }
+
+
/// Called whenever the SSL connection state changes, an alert appears, or an
/// error occurs. See SSL_set_info_callback().
void
Ssl::ClientBio::read(char *buf, int size, BIO *table)
{
if (helloState < atHelloReceived) {
- prepReadBuf();
-
- size = rbuf.spaceSize() > size ? size : rbuf.spaceSize();
-
- if (!size) {
- debugs(83, DBG_IMPORTANT, "Not enough space to hold client SSL hello message");
- return -1;
- }
-
- int bytes = Ssl::Bio::read(buf, size, table);
+ int bytes = readAndBuffer(buf, size, table, "TLS client Hello");
if (bytes <= 0)
return bytes;
- rbuf.append(buf, bytes);
- debugs(83, 7, "rbuf size: " << rbuf.contentSize());
}
if (helloState == atHelloNone) {
int
Ssl::ServerBio::read(char *buf, int size, BIO *table)
{
- int bytes = Ssl::Bio::read(buf, size, table);
-
- if (bytes > 0 && record_) {
- prepReadBuf();
-
- if (rbuf.spaceSize() < bytes) {
- debugs(83, DBG_IMPORTANT, "Not enough space to hold server hello message");
- return -1;
- }
-
- rbuf.append(buf, bytes);
- debugs(83, 5, "Record is enabled store " << bytes << " bytes");
- }
- debugs(83, 5, "Read " << bytes << " from " << size << " bytes");
- return bytes;
+ return record_ ?
+ readAndBuffer(buf, size, table, "TLS server Hello") : Ssl::Bio::read(buf, size, table);
}
// This function makes the required checks to examine if the client hello