From 807fca6803bdb19964710453819624bf7d0e4216 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 1 Feb 2011 14:40:15 -0800 Subject: [PATCH] TLS: Set ssl.receivedShutdown after each read Closes GH-613. --- src/node_crypto.cc | 28 ++++++++++++++++++++++++---- src/node_crypto.h | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5cfbef5..4abdc5d 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -336,6 +336,21 @@ void Connection::ClearError() { } +void Connection::SetShutdownFlags() { + HandleScope scope; + + int flags = SSL_get_shutdown(ssl_); + + if (flags & SSL_SENT_SHUTDOWN) { + handle_->Set(String::New("sentShutdown"), True()); + } + + if (flags & SSL_RECEIVED_SHUTDOWN) { + handle_->Set(String::New("receivedShutdown"), True()); + } +} + + void Connection::Initialize(Handle target) { HandleScope scope; @@ -496,8 +511,8 @@ Handle Connection::EncIn(const Arguments& args) { } int bytes_written = BIO_write(ss->bio_read_, (char*)buffer_data + off, len); - ss->HandleError("BIO_write", bytes_written); + ss->SetShutdownFlags(); return scope.Close(Integer::New(bytes_written)); } @@ -534,7 +549,6 @@ Handle Connection::ClearOut(const Arguments& args) { String::New("Length is extends beyond buffer"))); } - if (!SSL_is_init_finished(ss->ssl_)) { int rv; @@ -551,6 +565,7 @@ Handle Connection::ClearOut(const Arguments& args) { int bytes_read = SSL_read(ss->ssl_, (char*)buffer_data + off, len); ss->HandleError("SSL_read:ClearOut", bytes_read); + ss->SetShutdownFlags(); return scope.Close(Integer::New(bytes_read)); } @@ -610,6 +625,7 @@ Handle Connection::EncOut(const Arguments& args) { int bytes_read = BIO_read(ss->bio_write_, (char*)buffer_data + off, len); ss->HandleError("BIO_read:EncOut", bytes_read, true); + ss->SetShutdownFlags(); return scope.Close(Integer::New(bytes_read)); } @@ -662,6 +678,7 @@ Handle Connection::ClearIn(const Arguments& args) { int bytes_written = SSL_write(ss->ssl_, (char*)buffer_data + off, len); ss->HandleError("SSL_write:ClearIn", bytes_written); + ss->SetShutdownFlags(); return scope.Close(Integer::New(bytes_written)); } @@ -768,9 +785,12 @@ Handle Connection::Shutdown(const Arguments& args) { Connection *ss = Connection::Unwrap(args); if (ss->ssl_ == NULL) return False(); - int r = SSL_shutdown(ss->ssl_); + int rv = SSL_shutdown(ss->ssl_); + + ss->HandleError("SSL_shutdown", rv); + ss->SetShutdownFlags(); - return scope.Close(Integer::New(r)); + return scope.Close(Integer::New(rv)); } diff --git a/src/node_crypto.h b/src/node_crypto.h index c320864..a278d52 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -76,6 +76,7 @@ class Connection : ObjectWrap { int HandleError(const char* func, int rv, bool ignore_error=false); void ClearError(); + void SetShutdownFlags(); static Connection* Unwrap(const v8::Arguments& args) { Connection* ss = ObjectWrap::Unwrap(args.Holder()); -- 2.7.4