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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 void FUNCTION_NAME(SecureSocket_Handshake)(Dart_NativeArguments args) { | 185 void FUNCTION_NAME(SecureSocket_Handshake)(Dart_NativeArguments args) { |
186 Dart_EnterScope(); | 186 Dart_EnterScope(); |
187 GetFilter(args)->Handshake(); | 187 GetFilter(args)->Handshake(); |
188 Dart_ExitScope(); | 188 Dart_ExitScope(); |
189 } | 189 } |
190 | 190 |
191 | 191 |
192 void FUNCTION_NAME(SecureSocket_Renegotiate)(Dart_NativeArguments args) { | |
193 Dart_EnterScope(); | |
194 bool use_session_cache = | |
195 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1)); | |
196 bool request_client_certificate = | |
197 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 2)); | |
198 bool require_client_certificate = | |
199 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3)); | |
200 request_client_certificate = | |
201 request_client_certificate || require_client_certificate; | |
Anders Johnsen
2013/07/11 11:20:32
Please add a comment here. It's hard to understand
Bill Hesse
2013/07/11 15:25:42
Done.
| |
202 GetFilter(args)->Renegotiate(use_session_cache, | |
203 request_client_certificate, | |
204 require_client_certificate); | |
205 Dart_ExitScope(); | |
206 } | |
207 | |
208 | |
192 void FUNCTION_NAME(SecureSocket_RegisterHandshakeCompleteCallback)( | 209 void FUNCTION_NAME(SecureSocket_RegisterHandshakeCompleteCallback)( |
193 Dart_NativeArguments args) { | 210 Dart_NativeArguments args) { |
194 Dart_EnterScope(); | 211 Dart_EnterScope(); |
195 Dart_Handle handshake_complete = | 212 Dart_Handle handshake_complete = |
196 ThrowIfError(Dart_GetNativeArgument(args, 1)); | 213 ThrowIfError(Dart_GetNativeArgument(args, 1)); |
197 if (!Dart_IsClosure(handshake_complete)) { | 214 if (!Dart_IsClosure(handshake_complete)) { |
198 Dart_ThrowException(DartUtils::NewDartArgumentError( | 215 Dart_ThrowException(DartUtils::NewDartArgumentError( |
199 "Illegal argument to RegisterHandshakeCompleteCallback")); | 216 "Illegal argument to RegisterHandshakeCompleteCallback")); |
200 } | 217 } |
201 GetFilter(args)->RegisterHandshakeCompleteCallback(handshake_complete); | 218 GetFilter(args)->RegisterHandshakeCompleteCallback(handshake_complete); |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 "Handshake error in server"); | 837 "Handshake error in server"); |
821 } else { | 838 } else { |
822 ThrowPRException("HandshakeException", | 839 ThrowPRException("HandshakeException", |
823 "Handshake error in client"); | 840 "Handshake error in client"); |
824 } | 841 } |
825 } | 842 } |
826 } | 843 } |
827 } | 844 } |
828 | 845 |
829 | 846 |
847 void SSLFilter::Renegotiate(bool use_session_cache, | |
848 bool request_client_certificate, | |
849 bool require_client_certificate) { | |
850 SECStatus status; | |
851 PRBool request_cert = request_client_certificate ? PR_TRUE : PR_FALSE; | |
Anders Johnsen
2013/07/11 11:20:32
It can not be cast directly?
Bill Hesse
2013/07/11 15:25:42
Yes, It doesn't even need a cast anymore - PRBool
Bill Hesse
2013/07/11 15:25:42
Yes, the implicit bool -> int cast produces 0 and
| |
852 status = SSL_OptionSet(filter_, SSL_REQUEST_CERTIFICATE, request_cert); | |
853 if (status != SECSuccess) { | |
854 ThrowPRException("TlsException", | |
855 "Failure in (Raw)SecureSocket.renegotiate request_client_certificate"); | |
856 } | |
857 PRBool require_cert = require_client_certificate ? PR_TRUE : PR_FALSE; | |
858 status = SSL_OptionSet(filter_, SSL_REQUIRE_CERTIFICATE, require_cert); | |
859 if (status != SECSuccess) { | |
860 ThrowPRException("TlsException", | |
861 "Failure in (Raw)SecureSocket.renegotiate require_client_certificate"); | |
862 } | |
863 PRBool flush_cache = use_session_cache ? PR_FALSE : PR_TRUE; | |
Anders Johnsen
2013/07/11 11:20:32
Please don't negate in this 'cast'. Hard to read.
Bill Hesse
2013/07/11 15:25:42
Done.
| |
864 status = SSL_ReHandshake(filter_, flush_cache); | |
865 if (status != SECSuccess) { | |
866 if (is_server_) { | |
867 ThrowPRException("HandshakeException", | |
868 "Failure in (Raw)SecureSocket.renegotiate in server"); | |
869 } else { | |
870 ThrowPRException("HandshakeException", | |
871 "Failure in (Raw)SecureSocket.renegotiate in client"); | |
872 } | |
873 } | |
874 } | |
875 | |
876 | |
830 void SSLFilter::Destroy() { | 877 void SSLFilter::Destroy() { |
831 for (int i = 0; i < kNumBuffers; ++i) { | 878 for (int i = 0; i < kNumBuffers; ++i) { |
832 Dart_DeletePersistentHandle(dart_buffer_objects_[i]); | 879 Dart_DeletePersistentHandle(dart_buffer_objects_[i]); |
833 delete[] buffers_[i]; | 880 delete[] buffers_[i]; |
834 } | 881 } |
835 Dart_DeletePersistentHandle(string_start_); | 882 Dart_DeletePersistentHandle(string_start_); |
836 Dart_DeletePersistentHandle(string_length_); | 883 Dart_DeletePersistentHandle(string_length_); |
837 Dart_DeletePersistentHandle(handshake_complete_); | 884 Dart_DeletePersistentHandle(handshake_complete_); |
838 Dart_DeletePersistentHandle(bad_certificate_callback_); | 885 Dart_DeletePersistentHandle(bad_certificate_callback_); |
839 free(client_certificate_name_); | 886 free(client_certificate_name_); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
942 // Return a send port for the service port. | 989 // Return a send port for the service port. |
943 Dart_Handle send_port = Dart_NewSendPort(service_port); | 990 Dart_Handle send_port = Dart_NewSendPort(service_port); |
944 Dart_SetReturnValue(args, send_port); | 991 Dart_SetReturnValue(args, send_port); |
945 } | 992 } |
946 Dart_ExitScope(); | 993 Dart_ExitScope(); |
947 } | 994 } |
948 | 995 |
949 | 996 |
950 } // namespace bin | 997 } // namespace bin |
951 } // namespace dart | 998 } // namespace dart |
OLD | NEW |