| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/secure_socket.h" | 5 #include "bin/secure_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 namespace dart { | 35 namespace dart { |
| 36 namespace bin { | 36 namespace bin { |
| 37 | 37 |
| 38 bool SSLFilter::library_initialized_ = false; | 38 bool SSLFilter::library_initialized_ = false; |
| 39 // To protect library initialization. | 39 // To protect library initialization. |
| 40 dart::Mutex* SSLFilter::mutex_ = new dart::Mutex(); | 40 dart::Mutex* SSLFilter::mutex_ = new dart::Mutex(); |
| 41 // The password is needed when creating secure server sockets. It can | 41 // The password is needed when creating secure server sockets. It can |
| 42 // be null if only secure client sockets are used. | 42 // be null if only secure client sockets are used. |
| 43 const char* SSLFilter::password_ = NULL; | 43 const char* SSLFilter::password_ = NULL; |
| 44 | 44 |
| 45 // Forward declaration. | |
| 46 static void ProcessFilter(Dart_Port dest_port_id, | |
| 47 Dart_Port reply_port_id, | |
| 48 Dart_CObject* message); | |
| 49 | |
| 50 NativeService SSLFilter::filter_service_("FilterService", ProcessFilter, 16); | |
| 51 | |
| 52 static const int kSSLFilterNativeFieldIndex = 0; | 45 static const int kSSLFilterNativeFieldIndex = 0; |
| 53 | 46 |
| 54 | 47 |
| 55 /* Handle an error reported from the NSS library. */ | 48 /* Handle an error reported from the NSS library. */ |
| 56 static void ThrowPRException(const char* exception_type, | 49 static void ThrowPRException(const char* exception_type, |
| 57 const char* message, | 50 const char* message, |
| 58 bool free_message = false) { | 51 bool free_message = false) { |
| 59 PRErrorCode error_code = PR_GetError(); | 52 PRErrorCode error_code = PR_GetError(); |
| 60 const char* error_message = PR_ErrorToString(error_code, PR_LANGUAGE_EN); | 53 const char* error_message = PR_ErrorToString(error_code, PR_LANGUAGE_EN); |
| 61 OSError os_error_struct(error_code, error_message, OSError::kNSS); | 54 OSError os_error_struct(error_code, error_message, OSError::kNSS); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 * area of the output buffers. The function returns the new start and end | 281 * area of the output buffers. The function returns the new start and end |
| 289 * positions in the buffers, but it only updates start for input buffers, and | 282 * positions in the buffers, but it only updates start for input buffers, and |
| 290 * end for output buffers. Therefore, the Dart thread can simultaneously | 283 * end for output buffers. Therefore, the Dart thread can simultaneously |
| 291 * write to the free space and end pointer of input buffers, and read from | 284 * write to the free space and end pointer of input buffers, and read from |
| 292 * the data space of output buffers, and modify the start pointer. | 285 * the data space of output buffers, and modify the start pointer. |
| 293 * | 286 * |
| 294 * When ProcessFilter returns, the Dart thread is responsible for combining | 287 * When ProcessFilter returns, the Dart thread is responsible for combining |
| 295 * the updated pointers from Dart and C++, to make the new valid state of | 288 * the updated pointers from Dart and C++, to make the new valid state of |
| 296 * the circular buffer. | 289 * the circular buffer. |
| 297 */ | 290 */ |
| 298 static void ProcessFilter(Dart_Port dest_port_id, | 291 CObject* SSLFilter::ProcessFilterRequest(const CObjectArray& request) { |
| 299 Dart_Port reply_port_id, | 292 CObjectIntptr filter_object(request[0]); |
| 300 Dart_CObject* message) { | |
| 301 CObjectArray args(message); | |
| 302 CObjectIntptr filter_object(args[0]); | |
| 303 SSLFilter* filter = reinterpret_cast<SSLFilter*>(filter_object.Value()); | 293 SSLFilter* filter = reinterpret_cast<SSLFilter*>(filter_object.Value()); |
| 304 bool in_handshake = CObjectBool(args[1]).Value(); | 294 bool in_handshake = CObjectBool(request[1]).Value(); |
| 305 int starts[SSLFilter::kNumBuffers]; | 295 int starts[SSLFilter::kNumBuffers]; |
| 306 int ends[SSLFilter::kNumBuffers]; | 296 int ends[SSLFilter::kNumBuffers]; |
| 307 for (int i = 0; i < SSLFilter::kNumBuffers; ++i) { | 297 for (int i = 0; i < SSLFilter::kNumBuffers; ++i) { |
| 308 starts[i] = CObjectInt32(args[2 * i + 2]).Value(); | 298 starts[i] = CObjectInt32(request[2 * i + 2]).Value(); |
| 309 ends[i] = CObjectInt32(args[2 * i + 3]).Value(); | 299 ends[i] = CObjectInt32(request[2 * i + 3]).Value(); |
| 310 } | 300 } |
| 311 | 301 |
| 312 if (filter->ProcessAllBuffers(starts, ends, in_handshake)) { | 302 if (filter->ProcessAllBuffers(starts, ends, in_handshake)) { |
| 303 CObjectArray* result = new CObjectArray( |
| 304 CObject::NewArray(SSLFilter::kNumBuffers * 2)); |
| 313 for (int i = 0; i < SSLFilter::kNumBuffers; ++i) { | 305 for (int i = 0; i < SSLFilter::kNumBuffers; ++i) { |
| 314 args[2 * i + 2]->AsApiCObject()->value.as_int32 = starts[i]; | 306 result->SetAt(2 * i, new CObjectInt32(CObject::NewInt32(starts[i]))); |
| 315 args[2 * i + 3]->AsApiCObject()->value.as_int32 = ends[i]; | 307 result->SetAt(2 * i + 1, new CObjectInt32(CObject::NewInt32(ends[i]))); |
| 316 } | 308 } |
| 317 Dart_PostCObject(reply_port_id, args.AsApiCObject()); | 309 return result; |
| 318 } else { | 310 } else { |
| 319 PRErrorCode error_code = PR_GetError(); | 311 PRErrorCode error_code = PR_GetError(); |
| 320 const char* error_message = PR_ErrorToString(error_code, PR_LANGUAGE_EN); | 312 const char* error_message = PR_ErrorToString(error_code, PR_LANGUAGE_EN); |
| 321 CObjectArray* result = new CObjectArray(CObject::NewArray(2)); | 313 CObjectArray* result = new CObjectArray(CObject::NewArray(2)); |
| 322 result->SetAt(0, new CObjectInt32(CObject::NewInt32(error_code))); | 314 result->SetAt(0, new CObjectInt32(CObject::NewInt32(error_code))); |
| 323 result->SetAt(1, new CObjectString(CObject::NewString(error_message))); | 315 result->SetAt(1, new CObjectString(CObject::NewString(error_message))); |
| 324 Dart_PostCObject(reply_port_id, result->AsApiCObject()); | 316 return result; |
| 325 } | 317 } |
| 326 } | 318 } |
| 327 | 319 |
| 328 | 320 |
| 329 bool SSLFilter::ProcessAllBuffers(int starts[kNumBuffers], | 321 bool SSLFilter::ProcessAllBuffers(int starts[kNumBuffers], |
| 330 int ends[kNumBuffers], | 322 int ends[kNumBuffers], |
| 331 bool in_handshake) { | 323 bool in_handshake) { |
| 332 for (int i = 0; i < kNumBuffers; ++i) { | 324 for (int i = 0; i < kNumBuffers; ++i) { |
| 333 if (in_handshake && (i == kReadPlaintext || i == kWritePlaintext)) continue; | 325 if (in_handshake && (i == kReadPlaintext || i == kWritePlaintext)) continue; |
| 334 int start = starts[i]; | 326 int start = starts[i]; |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 memmove(buffer + start + bytes_processed, buf2, bytes_to_send); | 938 memmove(buffer + start + bytes_processed, buf2, bytes_to_send); |
| 947 bytes_processed += bytes_to_send; | 939 bytes_processed += bytes_to_send; |
| 948 } | 940 } |
| 949 if (bytes_processed > 0) { | 941 if (bytes_processed > 0) { |
| 950 memio_PutWriteResult(secret, bytes_processed); | 942 memio_PutWriteResult(secret, bytes_processed); |
| 951 } | 943 } |
| 952 } | 944 } |
| 953 return bytes_processed; | 945 return bytes_processed; |
| 954 } | 946 } |
| 955 | 947 |
| 956 | |
| 957 Dart_Port SSLFilter::GetServicePort() { | |
| 958 return filter_service_.GetServicePort(); | |
| 959 } | |
| 960 | |
| 961 | |
| 962 void FUNCTION_NAME(SecureSocket_NewServicePort)(Dart_NativeArguments args) { | |
| 963 Dart_SetReturnValue(args, Dart_Null()); | |
| 964 Dart_Port service_port = SSLFilter::GetServicePort(); | |
| 965 if (service_port != ILLEGAL_PORT) { | |
| 966 // Return a send port for the service port. | |
| 967 Dart_Handle send_port = Dart_NewSendPort(service_port); | |
| 968 Dart_SetReturnValue(args, send_port); | |
| 969 } | |
| 970 } | |
| 971 | |
| 972 | |
| 973 } // namespace bin | 948 } // namespace bin |
| 974 } // namespace dart | 949 } // namespace dart |
| OLD | NEW |