| 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 "Called SecureSocket.initialize more than once", | 634 "Called SecureSocket.initialize more than once", |
| 635 Dart_Null())); | 635 Dart_Null())); |
| 636 } | 636 } |
| 637 } | 637 } |
| 638 | 638 |
| 639 | 639 |
| 640 SECStatus BadCertificateCallback(void* filter, PRFileDesc* fd) { | 640 SECStatus BadCertificateCallback(void* filter, PRFileDesc* fd) { |
| 641 SSLFilter* ssl_filter = static_cast<SSLFilter*>(filter); | 641 SSLFilter* ssl_filter = static_cast<SSLFilter*>(filter); |
| 642 Dart_Handle callback = ssl_filter->bad_certificate_callback(); | 642 Dart_Handle callback = ssl_filter->bad_certificate_callback(); |
| 643 if (Dart_IsNull(callback)) return SECFailure; | 643 if (Dart_IsNull(callback)) return SECFailure; |
| 644 | |
| 645 Dart_EnterScope(); | |
| 646 Dart_Handle x509_object = ssl_filter->PeerCertificate(); | 644 Dart_Handle x509_object = ssl_filter->PeerCertificate(); |
| 647 Dart_Handle result = | 645 Dart_Handle result = Dart_InvokeClosure(callback, 1, &x509_object); |
| 648 ThrowIfError(Dart_InvokeClosure(callback, 1, &x509_object)); | 646 if (Dart_IsError(result)) { |
| 649 bool c_result = Dart_IsBoolean(result) && DartUtils::GetBooleanValue(result); | 647 ssl_filter->callback_error = result; |
| 650 Dart_ExitScope(); | 648 return SECFailure; |
| 649 } |
| 650 // Our wrapper is guaranteed to return a boolean. |
| 651 bool c_result = DartUtils::GetBooleanValue(result); |
| 651 return c_result ? SECSuccess : SECFailure; | 652 return c_result ? SECSuccess : SECFailure; |
| 652 } | 653 } |
| 653 | 654 |
| 654 | 655 |
| 655 Dart_Handle SSLFilter::PeerCertificate() { | 656 Dart_Handle SSLFilter::PeerCertificate() { |
| 656 CERTCertificate* certificate = SSL_PeerCertificate(filter_); | 657 CERTCertificate* certificate = SSL_PeerCertificate(filter_); |
| 657 if (certificate == NULL) return Dart_Null(); | 658 if (certificate == NULL) return Dart_Null(); |
| 658 Dart_Handle x509_object = X509FromCertificate(certificate); | 659 Dart_Handle x509_object = X509FromCertificate(certificate); |
| 659 CERT_DestroyCertificate(certificate); | 660 CERT_DestroyCertificate(certificate); |
| 660 return x509_object; | 661 return x509_object; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 | 818 |
| 818 void SSLFilter::Handshake() { | 819 void SSLFilter::Handshake() { |
| 819 SECStatus status = SSL_ForceHandshake(filter_); | 820 SECStatus status = SSL_ForceHandshake(filter_); |
| 820 if (status == SECSuccess) { | 821 if (status == SECSuccess) { |
| 821 if (in_handshake_) { | 822 if (in_handshake_) { |
| 822 ThrowIfError(Dart_InvokeClosure( | 823 ThrowIfError(Dart_InvokeClosure( |
| 823 Dart_HandleFromPersistent(handshake_complete_), 0, NULL)); | 824 Dart_HandleFromPersistent(handshake_complete_), 0, NULL)); |
| 824 in_handshake_ = false; | 825 in_handshake_ = false; |
| 825 } | 826 } |
| 826 } else { | 827 } else { |
| 828 if (callback_error != NULL) { |
| 829 Dart_PropagateError(callback_error); |
| 830 } |
| 827 PRErrorCode error = PR_GetError(); | 831 PRErrorCode error = PR_GetError(); |
| 828 if (error == PR_WOULD_BLOCK_ERROR) { | 832 if (error == PR_WOULD_BLOCK_ERROR) { |
| 829 if (!in_handshake_) { | 833 if (!in_handshake_) { |
| 830 in_handshake_ = true; | 834 in_handshake_ = true; |
| 831 } | 835 } |
| 832 } else { | 836 } else { |
| 833 if (is_server_) { | 837 if (is_server_) { |
| 834 ThrowPRException("HandshakeException", | 838 ThrowPRException("HandshakeException", |
| 835 "Handshake error in server"); | 839 "Handshake error in server"); |
| 836 } else { | 840 } else { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 // Return a send port for the service port. | 998 // Return a send port for the service port. |
| 995 Dart_Handle send_port = Dart_NewSendPort(service_port); | 999 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 996 Dart_SetReturnValue(args, send_port); | 1000 Dart_SetReturnValue(args, send_port); |
| 997 } | 1001 } |
| 998 Dart_ExitScope(); | 1002 Dart_ExitScope(); |
| 999 } | 1003 } |
| 1000 | 1004 |
| 1001 | 1005 |
| 1002 } // namespace bin | 1006 } // namespace bin |
| 1003 } // namespace dart | 1007 } // namespace dart |
| OLD | NEW |