Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1305)

Unified Diff: runtime/bin/tls_socket.h

Issue 10916081: Add secure sockets to dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add Socket.read and pass port number to NSS. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/tls_socket.h
diff --git a/runtime/bin/tls_socket.h b/runtime/bin/tls_socket.h
new file mode 100644
index 0000000000000000000000000000000000000000..328e91c85f2210c5e19b3ac243d5291ef2c0e580
--- /dev/null
+++ b/runtime/bin/tls_socket.h
@@ -0,0 +1,96 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef BIN_TLS_SOCKET_H_
+#define BIN_TLS_SOCKET_H_
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#include <prinit.h>
+#include <prerror.h>
+#include <prnetdb.h>
+
+#include "bin/builtin.h"
+#include "bin/dartutils.h"
+#include "platform/globals.h"
+#include "platform/thread.h"
+
+static void ReportError(const char* message) {
+ Dart_Handle socket_io_exception =
+ DartUtils::NewDartSocketIOException(message, Dart_Null());
+ Dart_ThrowException(socket_io_exception);
+}
+
+
+/* Handle an error reported from the NSS library. */
+static void ReportPRError(const char* message) {
+ PRErrorCode error_code = PR_GetError();
+ int error_length = PR_GetErrorTextLength();
+ char* error_message = static_cast<char*>(malloc(error_length + 1));
+ ASSERT(error_message != NULL);
+ int copied_length = PR_GetErrorText(error_message);
+ ASSERT(copied_length == error_length);
+ error_message[error_length] = '\0';
+ OSError os_error_struct(error_code, error_message, OSError::kNSS);
+ Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct);
+ Dart_Handle socket_io_exception =
+ DartUtils::NewDartSocketIOException(message, os_error);
+ free(error_message);
+ Dart_ThrowException(socket_io_exception);
+}
+
+
+class TlsFilter {
+ public:
+ enum BufferIndex { kReadPlaintext,
+ kWritePlaintext,
+ kReadEncrypted,
+ kWriteEncrypted,
+ kNumBuffers};
+
+ TlsFilter()
+ : stringStart_(NULL),
+ stringLength_(NULL),
+ handshake_start_(NULL),
+ handshake_finish_(NULL),
+ in_handshake_(false),
+ memio_(NULL) { }
+
+ void Init(Dart_Handle dart_this);
+ void Connect(const char* host, int port);
+ void Destroy();
+ void DestroyPlatformIndependent();
+ void Handshake();
+ void RegisterHandshakeCallbacks(Dart_Handle start, Dart_Handle finish);
+ static void InitializeLibrary(const char* pkcert_directory);
+
+ intptr_t ProcessBuffer(int bufferIndex);
+
+ private:
+ static const int kMemioBufferSize = 20 * KB;
+ static bool library_initialized_; // Should be mutex protected.
+
+ uint8_t* buffers_[kNumBuffers];
+ int64_t buffer_size_;
+ Dart_Handle stringStart_;
+ Dart_Handle stringLength_;
+ Dart_Handle dart_buffer_objects_[kNumBuffers];
+ Dart_Handle handshake_start_;
+ Dart_Handle handshake_finish_;
+ bool in_handshake_;
+ PRFileDesc* memio_;
+
+ void InitializeBuffers(Dart_Handle dart_this);
+ void InitializePlatformData();
+ // TODO(whesse): Implement thread-safety of NSS library initialization.
+ static void LockInitMutex() {}
+ static void UnlockInitMutex() {}
+
+ DISALLOW_COPY_AND_ASSIGN(TlsFilter);
+};
+
+#endif // BIN_TLS_SOCKET_H_

Powered by Google App Engine
This is Rietveld 408576698