OLD | NEW |
(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 /* Handle an error reported from the NSS library. */ |
| 23 static void ReportError(const char* message, int error_code) { |
| 24 // TODO(): Throw SocketIOException here. The error_code can go in its |
| 25 // OSError's errorCode field. |
| 26 printf("Secure Socket error: %s Error code %d\n", message, error_code); |
| 27 } |
| 28 |
| 29 class TlsFilter { |
| 30 public: |
| 31 enum BufferIndex { kReadPlaintext, |
| 32 kWritePlaintext, |
| 33 kReadEncrypted, |
| 34 kWriteEncrypted, |
| 35 kNumBuffers}; |
| 36 |
| 37 TlsFilter(); |
| 38 void Init(Dart_Handle dart_this); |
| 39 void Connect(const char* host); |
| 40 void Destroy(); |
| 41 void DestroyPlatformIndependent(); |
| 42 void Handshake(); |
| 43 void RegisterHandshakeCallbacks(Dart_Handle start, Dart_Handle finish); |
| 44 static void InitializeLibrary(const char* pkcert_directory); |
| 45 |
| 46 intptr_t ProcessBuffer(int bufferIndex); |
| 47 |
| 48 private: |
| 49 // static const char* bufferNames_[kNumBuffers]; |
| 50 static bool library_initialized_; // Should be mutex protected. |
| 51 |
| 52 uint8_t* buffers_[kNumBuffers]; |
| 53 int64_t buffer_size_; |
| 54 Dart_Handle stringStart_; |
| 55 Dart_Handle stringLength_; |
| 56 Dart_Handle dart_buffer_objects_[kNumBuffers]; |
| 57 Dart_Handle handshake_start_; |
| 58 Dart_Handle handshake_finish_; |
| 59 bool in_handshake_; |
| 60 PRFileDesc* memio_; |
| 61 |
| 62 void InitializeBuffers(Dart_Handle dart_this); |
| 63 void InitializePlatformData(); |
| 64 // TODO(whesse): Implement thread-safety of NSS library initialization. |
| 65 static void LockInitMutex() {} |
| 66 static void UnlockInitMutex() {} |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(TlsFilter); |
| 69 }; |
| 70 |
| 71 #endif // BIN_TLS_SOCKET_H_ |
OLD | NEW |