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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef BIN_TLS_SOCKET_H_
6 #define BIN_TLS_SOCKET_H_
7
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <sys/types.h>
12
13 #include <prinit.h>
14 #include <prerror.h>
15 #include <prnetdb.h>
16
17 #include "bin/builtin.h"
18 #include "bin/dartutils.h"
19 #include "platform/globals.h"
20 #include "platform/thread.h"
21
22 static void ReportError(const char* message) {
23 Dart_Handle socket_io_exception =
24 DartUtils::NewDartSocketIOException(message, Dart_Null());
25 Dart_ThrowException(socket_io_exception);
26 }
27
28
29 /* Handle an error reported from the NSS library. */
30 static void ReportPRError(const char* message) {
31 PRErrorCode error_code = PR_GetError();
32 int error_length = PR_GetErrorTextLength();
33 char* error_message = static_cast<char*>(malloc(error_length + 1));
34 ASSERT(error_message != NULL);
35 int copied_length = PR_GetErrorText(error_message);
36 ASSERT(copied_length == error_length);
37 error_message[error_length] = '\0';
38 OSError os_error_struct(error_code, error_message, OSError::kNSS);
39 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct);
40 Dart_Handle socket_io_exception =
41 DartUtils::NewDartSocketIOException(message, os_error);
42 free(error_message);
43 Dart_ThrowException(socket_io_exception);
44 }
45
46
47 class TlsFilter {
48 public:
49 enum BufferIndex { kReadPlaintext,
50 kWritePlaintext,
51 kReadEncrypted,
52 kWriteEncrypted,
53 kNumBuffers};
54
55 TlsFilter()
56 : stringStart_(NULL),
57 stringLength_(NULL),
58 handshake_start_(NULL),
59 handshake_finish_(NULL),
60 in_handshake_(false),
61 memio_(NULL) { }
62
63 void Init(Dart_Handle dart_this);
64 void Connect(const char* host, int port);
65 void Destroy();
66 void DestroyPlatformIndependent();
67 void Handshake();
68 void RegisterHandshakeCallbacks(Dart_Handle start, Dart_Handle finish);
69 static void InitializeLibrary(const char* pkcert_directory);
70
71 intptr_t ProcessBuffer(int bufferIndex);
72
73 private:
74 static const int kMemioBufferSize = 20 * KB;
75 static bool library_initialized_; // Should be mutex protected.
76
77 uint8_t* buffers_[kNumBuffers];
78 int64_t buffer_size_;
79 Dart_Handle stringStart_;
80 Dart_Handle stringLength_;
81 Dart_Handle dart_buffer_objects_[kNumBuffers];
82 Dart_Handle handshake_start_;
83 Dart_Handle handshake_finish_;
84 bool in_handshake_;
85 PRFileDesc* memio_;
86
87 void InitializeBuffers(Dart_Handle dart_this);
88 void InitializePlatformData();
89 // TODO(whesse): Implement thread-safety of NSS library initialization.
90 static void LockInitMutex() {}
91 static void UnlockInitMutex() {}
92
93 DISALLOW_COPY_AND_ASSIGN(TlsFilter);
94 };
95
96 #endif // BIN_TLS_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698