Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
dart::bin::SSLFilter Class Reference

#include <secure_socket_filter.h>

Inheritance diagram for dart::bin::SSLFilter:
dart::bin::ReferenceCounted< SSLFilter >

Public Types

enum  BufferIndex {
  kReadPlaintext , kWritePlaintext , kReadEncrypted , kWriteEncrypted ,
  kNumBuffers , kFirstEncrypted = kReadEncrypted
}
 

Public Member Functions

 SSLFilter ()
 
 ~SSLFilter ()
 
char * hostname () const
 
bool is_server () const
 
bool is_client () const
 
Dart_Handle Init (Dart_Handle dart_this)
 
void Connect (const char *hostname, SSLCertContext *context, bool is_server, bool request_client_certificate, bool require_client_certificate, Dart_Handle protocols_handle)
 
void Destroy ()
 
void FreeResources ()
 
void MarkAsTrusted (Dart_NativeArguments args)
 
int Handshake (Dart_Port reply_port)
 
void GetSelectedProtocol (Dart_NativeArguments args)
 
void RegisterHandshakeCompleteCallback (Dart_Handle handshake_complete)
 
void RegisterBadCertificateCallback (Dart_Handle callback)
 
void RegisterKeyLogPort (Dart_Port key_log_port)
 
Dart_Port key_log_port ()
 
Dart_Handle bad_certificate_callback ()
 
int ProcessReadPlaintextBuffer (int start, int end)
 
int ProcessWritePlaintextBuffer (int start, int end)
 
int ProcessReadEncryptedBuffer (int start, int end)
 
int ProcessWriteEncryptedBuffer (int start, int end)
 
bool ProcessAllBuffers (int starts[kNumBuffers], int ends[kNumBuffers], bool in_handshake)
 
Dart_Handle PeerCertificate ()
 
const X509TrustStatecertificate_trust_state ()
 
Dart_Port reply_port () const
 
Dart_Port trust_evaluate_reply_port () const
 
- Public Member Functions inherited from dart::bin::ReferenceCounted< SSLFilter >
 ReferenceCounted ()
 
virtual ~ReferenceCounted ()
 
void Retain ()
 
void Release ()
 

Static Public Member Functions

static void Init ()
 
static void Cleanup ()
 
static void InitializeLibrary ()
 
static CObjectProcessFilterRequest (const CObjectArray &request)
 

Public Attributes

Dart_Handle callback_error
 

Static Public Attributes

static const intptr_t kApproximateSize
 
static constexpr int kSSLFilterNativeFieldIndex = 0
 
static int filter_ssl_index
 
static int ssl_cert_context_index
 

Detailed Description

Definition at line 41 of file secure_socket_filter.h.

Member Enumeration Documentation

◆ BufferIndex

Enumerator
kReadPlaintext 
kWritePlaintext 
kReadEncrypted 
kWriteEncrypted 
kNumBuffers 
kFirstEncrypted 

Definition at line 47 of file secure_socket_filter.h.

Constructor & Destructor Documentation

◆ SSLFilter()

dart::bin::SSLFilter::SSLFilter ( )
inline

Definition at line 59 of file secure_socket_filter.h.

60 : callback_error(nullptr),
61 ssl_(nullptr),
62 socket_side_(nullptr),
63 string_start_(nullptr),
64 string_length_(nullptr),
65 handshake_complete_(nullptr),
66 bad_certificate_callback_(nullptr),
67 in_handshake_(false),
68 hostname_(nullptr) {}

◆ ~SSLFilter()

dart::bin::SSLFilter::~SSLFilter ( )

Definition at line 689 of file secure_socket_filter.cc.

689 {
691}

Member Function Documentation

◆ bad_certificate_callback()

Dart_Handle dart::bin::SSLFilter::bad_certificate_callback ( )
inline

Definition at line 92 of file secure_socket_filter.h.

92 {
93 return Dart_HandleFromPersistent(bad_certificate_callback_);
94 }
DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object)

◆ certificate_trust_state()

const X509TrustState * dart::bin::SSLFilter::certificate_trust_state ( )
inline

Definition at line 114 of file secure_socket_filter.h.

114 {
115 return certificate_trust_state_.get();
116 }

◆ Cleanup()

void dart::bin::SSLFilter::Cleanup ( )
static

Definition at line 43 of file secure_socket_filter.cc.

43 {
44 ASSERT(SSLFilter::mutex_ != nullptr);
45 delete SSLFilter::mutex_;
46 SSLFilter::mutex_ = nullptr;
47}
#define ASSERT(E)

◆ Connect()

void dart::bin::SSLFilter::Connect ( const char *  hostname,
SSLCertContext context,
bool  is_server,
bool  request_client_certificate,
bool  require_client_certificate,
Dart_Handle  protocols_handle 
)

Definition at line 484 of file secure_socket_filter.cc.

489 {
490 is_server_ = is_server;
491 if (in_handshake_) {
492 FATAL("Connect called twice on the same _SecureFilter.");
493 }
494
495 int status;
496 int error;
497 BIO* ssl_side;
498 status = BIO_new_bio_pair(&ssl_side, kInternalBIOSize, &socket_side_,
499 kInternalBIOSize);
500 SecureSocketUtils::CheckStatusSSL(status, "TlsException", "BIO_new_bio_pair",
501 ssl_);
502
503 ASSERT(context != nullptr);
504 ASSERT(context->context() != nullptr);
505 ssl_ = SSL_new(context->context());
506 SSL_set_bio(ssl_, ssl_side, ssl_side);
507 SSL_set_mode(ssl_, SSL_MODE_AUTO_RETRY); // TODO(whesse): Is this right?
508 SSL_set_ex_data(ssl_, filter_ssl_index, this);
509
510 if (context->allow_tls_renegotiation()) {
511 SSL_set_renegotiate_mode(ssl_, ssl_renegotiate_freely);
512 }
513 context->RegisterCallbacks(ssl_);
514 SSL_set_ex_data(ssl_, ssl_cert_context_index, context);
515
516 TrustEvaluateHandlerFunc trust_evaluate_handler =
517 context->GetTrustEvaluateHandler();
518 if (trust_evaluate_handler != nullptr) {
519 trust_evaluate_reply_port_ = Dart_NewNativePort(
520 "SSLCertContextTrustEvaluate", trust_evaluate_handler,
521 /*handle_concurrently=*/false);
522 }
523 if (is_server_) {
524 int certificate_mode =
525 request_client_certificate ? SSL_VERIFY_PEER : SSL_VERIFY_NONE;
526 if (require_client_certificate) {
527 certificate_mode |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
528 }
529 SSL_set_verify(ssl_, certificate_mode, nullptr);
530 } else {
531 SSLCertContext::SetAlpnProtocolList(protocols_handle, ssl_, nullptr, false);
532 status = SSL_set_tlsext_host_name(ssl_, hostname);
533 SecureSocketUtils::CheckStatusSSL(status, "TlsException",
534 "Set SNI host name", ssl_);
535 // Sets the hostname in the certificate-checking object, so it is checked
536 // against the certificate presented by the server.
537 X509_VERIFY_PARAM* certificate_checking_parameters = SSL_get0_param(ssl_);
538 hostname_ = Utils::StrDup(hostname);
539 X509_VERIFY_PARAM_set_flags(
540 certificate_checking_parameters,
541 X509_V_FLAG_PARTIAL_CHAIN | X509_V_FLAG_TRUSTED_FIRST);
542 X509_VERIFY_PARAM_set_hostflags(certificate_checking_parameters, 0);
543
544 // Use different check depending on whether the hostname is an IP address
545 // or a DNS name.
546 if (SocketBase::IsValidAddress(hostname_)) {
547 status = X509_VERIFY_PARAM_set1_ip_asc(certificate_checking_parameters,
548 hostname_);
549 } else {
550 status = X509_VERIFY_PARAM_set1_host(certificate_checking_parameters,
551 hostname_, strlen(hostname_));
552 }
554 status, "TlsException", "Set hostname for certificate checking", ssl_);
555 }
556 // Make the connection:
557 if (is_server_) {
558 status = SSL_accept(ssl_);
559 if (SSL_LOG_STATUS) {
560 Syslog::Print("SSL_accept status: %d\n", status);
561 }
562 if (status != 1) {
563 // TODO(whesse): expect a needs-data error here. Handle other errors.
564 error = SSL_get_error(ssl_, status);
565 if (SSL_LOG_STATUS) {
566 Syslog::Print("SSL_accept error: %d\n", error);
567 }
568 }
569 } else {
570 status = SSL_connect(ssl_);
571 if (SSL_LOG_STATUS) {
572 Syslog::Print("SSL_connect status: %d\n", status);
573 }
574 if (status != 1) {
575 // TODO(whesse): expect a needs-data error here. Handle other errors.
576 error = SSL_get_error(ssl_, status);
577 if (SSL_LOG_STATUS) {
578 Syslog::Print("SSL_connect error: %d\n", error);
579 }
580 }
581 }
582 // We don't expect certificate evaluation on first attempt,
583 // we expect requests for more bytes, therefore we could get away
584 // with passing illegal port.
586}
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
static void SetAlpnProtocolList(Dart_Handle protocols_handle, SSL *ssl, SSLCertContext *context, bool is_server)
int Handshake(Dart_Port reply_port)
static void CheckStatusSSL(int status, const char *type, const char *message, const SSL *ssl)
static bool IsValidAddress(const char *address)
Definition: socket_base.cc:306
#define ILLEGAL_PORT
Definition: dart_api.h:1535
#define FATAL(error)
const uint8_t uint32_t uint32_t GError ** error
const bool SSL_LOG_STATUS
void(* TrustEvaluateHandlerFunc)(Dart_Port dest_port_id, Dart_CObject *message)
DART_EXPORT Dart_Port Dart_NewNativePort(const char *name, Dart_NativeMessageHandler handler, bool handle_concurrently)

◆ Destroy()

void dart::bin::SSLFilter::Destroy ( )

Definition at line 693 of file secure_socket_filter.cc.

693 {
694 for (int i = 0; i < kNumBuffers; ++i) {
695 if (dart_buffer_objects_[i] != nullptr) {
696 Dart_DeletePersistentHandle(dart_buffer_objects_[i]);
697 dart_buffer_objects_[i] = nullptr;
698 }
699 }
700 if (string_start_ != nullptr) {
701 Dart_DeletePersistentHandle(string_start_);
702 string_start_ = nullptr;
703 }
704 if (string_length_ != nullptr) {
705 Dart_DeletePersistentHandle(string_length_);
706 string_length_ = nullptr;
707 }
708 if (handshake_complete_ != nullptr) {
709 Dart_DeletePersistentHandle(handshake_complete_);
710 handshake_complete_ = nullptr;
711 }
712 if (bad_certificate_callback_ != nullptr) {
713 Dart_DeletePersistentHandle(bad_certificate_callback_);
714 bad_certificate_callback_ = nullptr;
715 }
716 if (trust_evaluate_reply_port_ != ILLEGAL_PORT) {
717 Dart_CloseNativePort(trust_evaluate_reply_port_);
718 trust_evaluate_reply_port_ = ILLEGAL_PORT;
719 }
721}
DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object)
DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id)

◆ FreeResources()

void dart::bin::SSLFilter::FreeResources ( )

Definition at line 668 of file secure_socket_filter.cc.

668 {
669 if (ssl_ != nullptr) {
670 SSL_free(ssl_);
671 ssl_ = nullptr;
672 }
673 if (socket_side_ != nullptr) {
674 BIO_free(socket_side_);
675 socket_side_ = nullptr;
676 }
677 if (hostname_ != nullptr) {
678 free(hostname_);
679 hostname_ = nullptr;
680 }
681 for (int i = 0; i < kNumBuffers; ++i) {
682 if (buffers_[i] != nullptr) {
683 delete[] buffers_[i];
684 buffers_[i] = nullptr;
685 }
686 }
687}

◆ GetSelectedProtocol()

void dart::bin::SSLFilter::GetSelectedProtocol ( Dart_NativeArguments  args)

Definition at line 657 of file secure_socket_filter.cc.

657 {
658 const uint8_t* protocol;
659 unsigned length;
660 SSL_get0_alpn_selected(ssl_, &protocol, &length);
661 if (length == 0) {
663 } else {
665 }
666}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
size_t length
DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t *utf8_array, intptr_t length)
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
DART_EXPORT Dart_Handle Dart_Null()

◆ Handshake()

int dart::bin::SSLFilter::Handshake ( Dart_Port  reply_port)

Definition at line 601 of file secure_socket_filter.cc.

601 {
602 // Set reply port to be used by CertificateVerificationCallback
603 // invoked by SSL_do_handshake: this is where results of
604 // certificate evaluation will be communicated to.
605 reply_port_ = reply_port;
606
607 // Try and push handshake along.
608 int status = SSL_do_handshake(ssl_);
609 int error = SSL_get_error(ssl_, status);
610 if (error == SSL_ERROR_WANT_CERTIFICATE_VERIFY) {
611 return SSL_ERROR_WANT_CERTIFICATE_VERIFY;
612 }
613 if (callback_error != nullptr) {
614 // The SSL_do_handshake will try performing a handshake and might call one
615 // or both of:
616 // SSLCertContext::KeyLogCallback
617 // SSLCertContext::CertificateCallback
618 //
619 // If either of those functions fail, and this.callback_error has not
620 // already been set, then they will set this.callback_error to an error
621 // handle i.e. only the first error will be captured and propagated.
623 }
624 if (SSL_want_write(ssl_) || SSL_want_read(ssl_)) {
625 in_handshake_ = true;
626 return error;
627 }
629 status, "HandshakeException",
630 is_server_ ? "Handshake error in server" : "Handshake error in client",
631 ssl_);
632 // Handshake succeeded.
633 if (in_handshake_) {
634 // TODO(24071): Check return value of SSL_get_verify_result, this
635 // should give us the hostname check.
636 int result = SSL_get_verify_result(ssl_);
637 if (SSL_LOG_STATUS) {
638 Syslog::Print("Handshake verification status: %d\n", result);
639 X509* peer_certificate = SSL_get_peer_certificate(ssl_);
640 if (peer_certificate == nullptr) {
641 Syslog::Print("No peer certificate received\n");
642 } else {
643 X509_NAME* s_name = X509_get_subject_name(peer_certificate);
644 printf("Peer certificate SN: ");
645 X509_NAME_print_ex_fp(stdout, s_name, 4, 0);
646 printf("\n");
647 }
648 }
650 Dart_HandleFromPersistent(handshake_complete_), 0, nullptr));
651 in_handshake_ = false;
652 }
653
654 return error;
655}
Dart_Port reply_port() const
GAsyncResult * result
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
static Dart_Handle ThrowIfError(Dart_Handle handle)
Definition: dartutils.h:31
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, int number_of_arguments, Dart_Handle *arguments)

◆ hostname()

char * dart::bin::SSLFilter::hostname ( ) const
inline

Definition at line 72 of file secure_socket_filter.h.

72{ return hostname_; }

◆ Init() [1/2]

void dart::bin::SSLFilter::Init ( )
static

Definition at line 38 of file secure_socket_filter.cc.

38 {
39 ASSERT(SSLFilter::mutex_ == nullptr);
40 SSLFilter::mutex_ = new Mutex();
41}

◆ Init() [2/2]

Dart_Handle dart::bin::SSLFilter::Init ( Dart_Handle  dart_this)

Definition at line 348 of file secure_socket_filter.cc.

348 {
349 if (!library_initialized_) {
351 }
352 ASSERT(string_start_ == nullptr);
353 string_start_ = Dart_NewPersistentHandle(DartUtils::NewString("start"));
354 ASSERT(string_start_ != nullptr);
355 ASSERT(string_length_ == nullptr);
356 string_length_ = Dart_NewPersistentHandle(DartUtils::NewString("length"));
357 ASSERT(string_length_ != nullptr);
358 ASSERT(bad_certificate_callback_ == nullptr);
359 bad_certificate_callback_ = Dart_NewPersistentHandle(Dart_Null());
360 ASSERT(bad_certificate_callback_ != nullptr);
361 // Caller handles cleanup on an error.
362 return InitializeBuffers(dart_this);
363}
static Dart_Handle NewString(const char *str)
Definition: dartutils.h:214
DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object)

◆ InitializeLibrary()

void dart::bin::SSLFilter::InitializeLibrary ( )
static

Definition at line 470 of file secure_socket_filter.cc.

470 {
471 MutexLocker locker(mutex_);
472 if (!library_initialized_) {
473 SSL_library_init();
475 SSL_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
478 SSL_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
480 library_initialized_ = true;
481 }
482}

◆ is_client()

bool dart::bin::SSLFilter::is_client ( ) const
inline

Definition at line 74 of file secure_socket_filter.h.

74{ return !is_server_; }

◆ is_server()

bool dart::bin::SSLFilter::is_server ( ) const
inline

Definition at line 73 of file secure_socket_filter.h.

73{ return is_server_; }

◆ key_log_port()

Dart_Port dart::bin::SSLFilter::key_log_port ( )
inline

Definition at line 91 of file secure_socket_filter.h.

91{ return key_log_port_; }

◆ MarkAsTrusted()

void dart::bin::SSLFilter::MarkAsTrusted ( Dart_NativeArguments  args)

Definition at line 588 of file secure_socket_filter.cc.

588 {
589 intptr_t certificate_pointer = DartUtils::GetNativeIntptrArgument(args, 1);
590 ASSERT(certificate_pointer != 0);
591 certificate_trust_state_.reset(
592 new X509TrustState(reinterpret_cast<X509*>(certificate_pointer),
594 if (SSL_LOG_STATUS) {
595 Syslog::Print("Mark %p as %strusted certificate\n",
596 certificate_trust_state_->x509(),
597 certificate_trust_state_->is_trusted() ? "" : "not ");
598 }
599}
static intptr_t GetNativeIntptrArgument(Dart_NativeArguments args, intptr_t index)
Definition: dartutils.cc:166
static bool GetNativeBooleanArgument(Dart_NativeArguments args, intptr_t index)
Definition: dartutils.cc:146

◆ PeerCertificate()

Dart_Handle dart::bin::SSLFilter::PeerCertificate ( )

Definition at line 458 of file secure_socket_filter.cc.

458 {
459 X509* ca = SSL_get_peer_certificate(ssl_);
460 if (ca == nullptr) {
461 return Dart_Null();
462 }
464}
static Dart_Handle WrappedX509Certificate(X509 *certificate)

◆ ProcessAllBuffers()

bool dart::bin::SSLFilter::ProcessAllBuffers ( int  starts[kNumBuffers],
int  ends[kNumBuffers],
bool  in_handshake 
)

Definition at line 276 of file secure_socket_filter.cc.

278 {
279 for (int i = 0; i < kNumBuffers; ++i) {
280 if (in_handshake && (i == kReadPlaintext || i == kWritePlaintext)) continue;
281 int start = starts[i];
282 int end = ends[i];
283 int size = IsBufferEncrypted(i) ? encrypted_buffer_size_ : buffer_size_;
284 if (start < 0 || end < 0 || start >= size || end >= size) {
285 FATAL("Out-of-bounds internal buffer access in dart:io SecureSocket");
286 }
287 switch (i) {
288 case kReadPlaintext:
289 case kWriteEncrypted:
290 // Write data to the circular buffer's free space. If the buffer
291 // is full, neither if statement is executed and nothing happens.
292 if (start <= end) {
293 // If the free space may be split into two segments,
294 // then the first is [end, size), unless start == 0.
295 // Then, since the last free byte is at position start - 2,
296 // the interval is [end, size - 1).
297 int buffer_end = (start == 0) ? size - 1 : size;
298 int bytes = (i == kReadPlaintext)
299 ? ProcessReadPlaintextBuffer(end, buffer_end)
300 : ProcessWriteEncryptedBuffer(end, buffer_end);
301 if (bytes < 0) return false;
302 end += bytes;
303 ASSERT(end <= size);
304 if (end == size) end = 0;
305 }
306 if (start > end + 1) {
307 int bytes = (i == kReadPlaintext)
308 ? ProcessReadPlaintextBuffer(end, start - 1)
309 : ProcessWriteEncryptedBuffer(end, start - 1);
310 if (bytes < 0) return false;
311 end += bytes;
312 ASSERT(end < start);
313 }
314 ends[i] = end;
315 break;
316 case kReadEncrypted:
317 case kWritePlaintext:
318 // Read/Write data from circular buffer. If the buffer is empty,
319 // neither if statement's condition is true.
320 if (end < start) {
321 // Data may be split into two segments. In this case,
322 // the first is [start, size).
323 int bytes = (i == kReadEncrypted)
326 if (bytes < 0) return false;
327 start += bytes;
328 ASSERT(start <= size);
329 if (start == size) start = 0;
330 }
331 if (start < end) {
332 int bytes = (i == kReadEncrypted)
333 ? ProcessReadEncryptedBuffer(start, end)
334 : ProcessWritePlaintextBuffer(start, end);
335 if (bytes < 0) return false;
336 start += bytes;
337 ASSERT(start <= end);
338 }
339 starts[i] = start;
340 break;
341 default:
342 UNREACHABLE();
343 }
344 }
345 return true;
346}
#define UNREACHABLE()
Definition: assert.h:248
int ProcessReadEncryptedBuffer(int start, int end)
int ProcessWritePlaintextBuffer(int start, int end)
int ProcessReadPlaintextBuffer(int start, int end)
int ProcessWriteEncryptedBuffer(int start, int end)
glong glong end
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ ProcessFilterRequest()

CObject * dart::bin::SSLFilter::ProcessFilterRequest ( const CObjectArray request)
static

Pushes data through the SSL filter, reading and writing from circular buffers shared with Dart.

The Dart _SecureFilterImpl class contains 4 ExternalByteArrays used to pass encrypted and plaintext data to and from the C++ SSLFilter object.

ProcessFilter is called with a CObject array containing the pointer to the SSLFilter, encoded as an int, and the start and end positions of the valid data in the four circular buffers. The function only reads from the valid data area of the input buffers, and only writes to the free area of the output buffers. The function returns the new start and end positions in the buffers, but it only updates start for input buffers, and end for output buffers. Therefore, the Dart thread can simultaneously write to the free space and end pointer of input buffers, and read from the data space of output buffers, and modify the start pointer.

When ProcessFilter returns, the Dart thread is responsible for combining the updated pointers from Dart and C++, to make the new valid state of the circular buffer.

Definition at line 243 of file secure_socket_filter.cc.

243 {
244 CObjectIntptr filter_object(request[0]);
245 SSLFilter* filter = reinterpret_cast<SSLFilter*>(filter_object.Value());
246 RefCntReleaseScope<SSLFilter> rs(filter);
247
248 bool in_handshake = CObjectBool(request[1]).Value();
249 int starts[SSLFilter::kNumBuffers];
250 int ends[SSLFilter::kNumBuffers];
251 for (int i = 0; i < SSLFilter::kNumBuffers; ++i) {
252 starts[i] = CObjectInt32(request[2 * i + 2]).Value();
253 ends[i] = CObjectInt32(request[2 * i + 3]).Value();
254 }
255
256 if (filter->ProcessAllBuffers(starts, ends, in_handshake)) {
257 CObjectArray* result =
258 new CObjectArray(CObject::NewArray(SSLFilter::kNumBuffers * 2));
259 for (int i = 0; i < SSLFilter::kNumBuffers; ++i) {
260 result->SetAt(2 * i, new CObjectInt32(CObject::NewInt32(starts[i])));
261 result->SetAt(2 * i + 1, new CObjectInt32(CObject::NewInt32(ends[i])));
262 }
263 return result;
264 } else {
265 int32_t error_code = static_cast<int32_t>(ERR_peek_error());
267 SecureSocketUtils::FetchErrorString(filter->ssl_, &error_string);
268 CObjectArray* result = new CObjectArray(CObject::NewArray(2));
269 result->SetAt(0, new CObjectInt32(CObject::NewInt32(error_code)));
270 result->SetAt(1,
271 new CObjectString(CObject::NewString(error_string.buffer())));
272 return result;
273 }
274}
static Dart_CObject * NewString(const char *str)
Definition: dartutils.cc:927
static Dart_CObject * NewArray(intptr_t length)
Definition: dartutils.cc:936
static Dart_CObject * NewInt32(int32_t value)
Definition: dartutils.cc:902
static constexpr int SSL_ERROR_MESSAGE_BUFFER_SIZE
static uint32_t FetchErrorString(const SSL *ssl, TextBuffer *text_buffer)

◆ ProcessReadEncryptedBuffer()

int dart::bin::SSLFilter::ProcessReadEncryptedBuffer ( int  start,
int  end 
)

Definition at line 779 of file secure_socket_filter.cc.

779 {
780 int length = end - start;
781 if (SSL_LOG_DATA) {
782 Syslog::Print("Entering ProcessReadEncryptedBuffer with %d bytes\n",
783 length);
784 }
785 int bytes_processed = 0;
786 if (length > 0) {
787 bytes_processed =
788 BIO_write(socket_side_, buffers_[kReadEncrypted] + start, length);
789 if (bytes_processed <= 0) {
790 bool retry = BIO_should_retry(socket_side_) != 0;
791 if (!retry) {
792 if (SSL_LOG_DATA) {
793 Syslog::Print("BIO_write failed in ReadEncryptedBuffer\n");
794 }
795 }
796 bytes_processed = 0;
797 }
798 }
799 if (SSL_LOG_DATA) {
800 Syslog::Print("Leaving ProcessReadEncryptedBuffer read %d bytes\n",
801 bytes_processed);
802 }
803 return bytes_processed;
804}
const bool SSL_LOG_DATA

◆ ProcessReadPlaintextBuffer()

int dart::bin::SSLFilter::ProcessReadPlaintextBuffer ( int  start,
int  end 
)

Definition at line 724 of file secure_socket_filter.cc.

724 {
725 int length = end - start;
726 int bytes_processed = 0;
727 if (SSL_LOG_DATA) {
728 Syslog::Print("Entering ProcessReadPlaintextBuffer with %d bytes\n",
729 length);
730 }
731 if (length > 0) {
732 bytes_processed = SSL_read(
733 ssl_, reinterpret_cast<char*>((buffers_[kReadPlaintext] + start)),
734 length);
735 if (bytes_processed < 0) {
736 int error = SSL_get_error(ssl_, bytes_processed);
737 if (SSL_LOG_DATA) {
738 Syslog::Print("SSL_read returned error %d\n", error);
739 }
740 switch (error) {
741 case SSL_ERROR_SYSCALL:
742 case SSL_ERROR_SSL:
743 return -1;
744 default:
745 break;
746 }
747 bytes_processed = 0;
748 }
749 }
750 if (SSL_LOG_DATA) {
751 Syslog::Print("Leaving ProcessReadPlaintextBuffer read %d bytes\n",
752 bytes_processed);
753 }
754 return bytes_processed;
755}

◆ ProcessWriteEncryptedBuffer()

int dart::bin::SSLFilter::ProcessWriteEncryptedBuffer ( int  start,
int  end 
)

Definition at line 806 of file secure_socket_filter.cc.

806 {
807 int length = end - start;
808 int bytes_processed = 0;
809 if (SSL_LOG_DATA) {
810 Syslog::Print("Entering ProcessWriteEncryptedBuffer with %d bytes\n",
811 length);
812 }
813 if (length > 0) {
814 bytes_processed =
815 BIO_read(socket_side_, buffers_[kWriteEncrypted] + start, length);
816 if (bytes_processed < 0) {
817 if (SSL_LOG_DATA) {
818 Syslog::Print("WriteEncrypted BIO_read returned error %d\n",
819 bytes_processed);
820 }
821 return 0;
822 } else {
823 if (SSL_LOG_DATA) {
824 Syslog::Print("WriteEncrypted BIO_read wrote %d bytes\n",
825 bytes_processed);
826 }
827 }
828 }
829 return bytes_processed;
830}

◆ ProcessWritePlaintextBuffer()

int dart::bin::SSLFilter::ProcessWritePlaintextBuffer ( int  start,
int  end 
)

Definition at line 757 of file secure_socket_filter.cc.

757 {
758 int length = end - start;
759 if (SSL_LOG_DATA) {
760 Syslog::Print("Entering ProcessWritePlaintextBuffer with %d bytes\n",
761 length);
762 }
763 int bytes_processed =
764 SSL_write(ssl_, buffers_[kWritePlaintext] + start, length);
765 if (bytes_processed < 0) {
766 if (SSL_LOG_DATA) {
767 Syslog::Print("SSL_write returned error %d\n", bytes_processed);
768 }
769 return 0;
770 }
771 if (SSL_LOG_DATA) {
772 Syslog::Print("Leaving ProcessWritePlaintextBuffer wrote %d bytes\n",
773 bytes_processed);
774 }
775 return bytes_processed;
776}

◆ RegisterBadCertificateCallback()

void dart::bin::SSLFilter::RegisterBadCertificateCallback ( Dart_Handle  callback)

Definition at line 451 of file secure_socket_filter.cc.

451 {
452 ASSERT(bad_certificate_callback_ != nullptr);
453 Dart_DeletePersistentHandle(bad_certificate_callback_);
454 bad_certificate_callback_ = Dart_NewPersistentHandle(callback);
455 ASSERT(bad_certificate_callback_ != nullptr);
456}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ RegisterHandshakeCompleteCallback()

void dart::bin::SSLFilter::RegisterHandshakeCompleteCallback ( Dart_Handle  handshake_complete)

Definition at line 444 of file secure_socket_filter.cc.

444 {
445 ASSERT(nullptr == handshake_complete_);
446 handshake_complete_ = Dart_NewPersistentHandle(complete);
447
448 ASSERT(handshake_complete_ != nullptr);
449}

◆ RegisterKeyLogPort()

void dart::bin::SSLFilter::RegisterKeyLogPort ( Dart_Port  key_log_port)

Definition at line 466 of file secure_socket_filter.cc.

466 {
467 key_log_port_ = key_log_port;
468}

◆ reply_port()

Dart_Port dart::bin::SSLFilter::reply_port ( ) const
inline

Definition at line 117 of file secure_socket_filter.h.

117{ return reply_port_; }

◆ trust_evaluate_reply_port()

Dart_Port dart::bin::SSLFilter::trust_evaluate_reply_port ( ) const
inline

Definition at line 118 of file secure_socket_filter.h.

118 {
119 return trust_evaluate_reply_port_;
120 }

Member Data Documentation

◆ callback_error

Dart_Handle dart::bin::SSLFilter::callback_error

Definition at line 104 of file secure_socket_filter.h.

◆ filter_ssl_index

int dart::bin::SSLFilter::filter_ssl_index
static

Definition at line 109 of file secure_socket_filter.h.

◆ kApproximateSize

const intptr_t dart::bin::SSLFilter::kApproximateSize
static
Initial value:
=
sizeof(SSLFilter) + (2 * SSLFilter::kInternalBIOSize)

Definition at line 56 of file secure_socket_filter.h.

◆ kSSLFilterNativeFieldIndex

constexpr int dart::bin::SSLFilter::kSSLFilterNativeFieldIndex = 0
staticconstexpr

Definition at line 57 of file secure_socket_filter.h.

◆ ssl_cert_context_index

int dart::bin::SSLFilter::ssl_cert_context_index
static

Definition at line 112 of file secure_socket_filter.h.


The documentation for this class was generated from the following files: