| 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 #ifndef BIN_SECURE_SOCKET_H_ | 5 #ifndef BIN_SECURE_SOCKET_H_ |
| 6 #define BIN_SECURE_SOCKET_H_ | 6 #define BIN_SECURE_SOCKET_H_ |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 | 12 |
| 13 #include <prinit.h> | 13 #include <prinit.h> |
| 14 #include <prerror.h> | 14 #include <prerror.h> |
| 15 #include <prnetdb.h> | 15 #include <prnetdb.h> |
| 16 #include <ssl.h> |
| 16 | 17 |
| 17 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
| 18 #include "bin/dartutils.h" | 19 #include "bin/dartutils.h" |
| 19 #include "platform/globals.h" | 20 #include "platform/globals.h" |
| 20 #include "platform/thread.h" | 21 #include "platform/thread.h" |
| 21 | 22 |
| 22 static void ThrowException(const char* message) { | 23 static void ThrowException(const char* message) { |
| 23 Dart_Handle socket_io_exception = | 24 Dart_Handle socket_io_exception = |
| 24 DartUtils::NewDartSocketIOException(message, Dart_Null()); | 25 DartUtils::NewDartSocketIOException(message, Dart_Null()); |
| 25 Dart_ThrowException(socket_io_exception); | 26 Dart_ThrowException(socket_io_exception); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 kWritePlaintext, | 59 kWritePlaintext, |
| 59 kReadEncrypted, | 60 kReadEncrypted, |
| 60 kWriteEncrypted, | 61 kWriteEncrypted, |
| 61 kNumBuffers | 62 kNumBuffers |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 SSLFilter() | 65 SSLFilter() |
| 65 : string_start_(NULL), | 66 : string_start_(NULL), |
| 66 string_length_(NULL), | 67 string_length_(NULL), |
| 67 handshake_complete_(NULL), | 68 handshake_complete_(NULL), |
| 69 bad_certificate_callback_(NULL), |
| 68 in_handshake_(false), | 70 in_handshake_(false), |
| 69 filter_(NULL) { } | 71 filter_(NULL) { } |
| 70 | 72 |
| 71 void Init(Dart_Handle dart_this); | 73 void Init(Dart_Handle dart_this); |
| 72 void Connect(const char* host, | 74 void Connect(const char* host, |
| 73 int port, | 75 int port, |
| 74 bool is_server, | 76 bool is_server, |
| 75 const char* certificate_name); | 77 const char* certificate_name); |
| 76 void Destroy(); | 78 void Destroy(); |
| 77 void Handshake(); | 79 void Handshake(); |
| 78 void RegisterHandshakeCompleteCallback(Dart_Handle handshake_complete); | 80 void RegisterHandshakeCompleteCallback(Dart_Handle handshake_complete); |
| 81 void RegisterBadCertificateCallback(Dart_Handle callback); |
| 79 static void InitializeLibrary(const char* certificate_database, | 82 static void InitializeLibrary(const char* certificate_database, |
| 80 const char* password, | 83 const char* password, |
| 81 bool use_builtin_root_certificates); | 84 bool use_builtin_root_certificates); |
| 82 | 85 |
| 83 intptr_t ProcessBuffer(int bufferIndex); | 86 intptr_t ProcessBuffer(int bufferIndex); |
| 84 | 87 |
| 88 SECStatus HandleBadCertificate(PRFileDesc* fd); |
| 89 |
| 85 private: | 90 private: |
| 86 static const int kMemioBufferSize = 20 * KB; | 91 static const int kMemioBufferSize = 20 * KB; |
| 87 static bool library_initialized_; | 92 static bool library_initialized_; |
| 88 static const char* password_; | 93 static const char* password_; |
| 89 static dart::Mutex mutex_; // To protect library initialization. | 94 static dart::Mutex mutex_; // To protect library initialization. |
| 90 | 95 |
| 91 uint8_t* buffers_[kNumBuffers]; | 96 uint8_t* buffers_[kNumBuffers]; |
| 92 int64_t buffer_size_; | 97 int64_t buffer_size_; |
| 93 Dart_Handle string_start_; | 98 Dart_Handle string_start_; |
| 94 Dart_Handle string_length_; | 99 Dart_Handle string_length_; |
| 95 Dart_Handle dart_buffer_objects_[kNumBuffers]; | 100 Dart_Handle dart_buffer_objects_[kNumBuffers]; |
| 96 Dart_Handle handshake_complete_; | 101 Dart_Handle handshake_complete_; |
| 102 Dart_Handle bad_certificate_callback_; |
| 97 bool in_handshake_; | 103 bool in_handshake_; |
| 98 bool is_server_; | 104 bool is_server_; |
| 99 PRFileDesc* filter_; | 105 PRFileDesc* filter_; |
| 100 | 106 |
| 101 void InitializeBuffers(Dart_Handle dart_this); | 107 void InitializeBuffers(Dart_Handle dart_this); |
| 102 void InitializePlatformData(); | 108 void InitializePlatformData(); |
| 103 | 109 |
| 104 DISALLOW_COPY_AND_ASSIGN(SSLFilter); | 110 DISALLOW_COPY_AND_ASSIGN(SSLFilter); |
| 105 }; | 111 }; |
| 106 | 112 |
| 107 #endif // BIN_SECURE_SOCKET_H_ | 113 #endif // BIN_SECURE_SOCKET_H_ |
| OLD | NEW |