Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: runtime/bin/secure_socket_macos.cc

Issue 1852783003: Implements remaining SecurityContext calls for iOS (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #if !defined(DART_IO_DISABLED) && !defined(DART_IO_SECURE_SOCKET_DISABLED) 5 #if !defined(DART_IO_DISABLED) && !defined(DART_IO_SECURE_SOCKET_DISABLED)
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(TARGET_OS_MACOS) && !TARGET_OS_IOS 8 #if defined(TARGET_OS_MACOS) && !TARGET_OS_IOS
9 9
10 #include "bin/secure_socket.h" 10 #include "bin/secure_socket.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 static const int kSSLFilterNativeFieldIndex = 0; 59 static const int kSSLFilterNativeFieldIndex = 0;
60 static const int kSecurityContextNativeFieldIndex = 0; 60 static const int kSecurityContextNativeFieldIndex = 0;
61 static const int kX509NativeFieldIndex = 0; 61 static const int kX509NativeFieldIndex = 0;
62 62
63 static const bool SSL_LOG_STATUS = false; 63 static const bool SSL_LOG_STATUS = false;
64 static const bool SSL_LOG_DATA = false; 64 static const bool SSL_LOG_DATA = false;
65 static const bool SSL_LOG_CERTS = false; 65 static const bool SSL_LOG_CERTS = false;
66 static const int SSL_ERROR_MESSAGE_BUFFER_SIZE = 1000; 66 static const int SSL_ERROR_MESSAGE_BUFFER_SIZE = 1000;
67 static const intptr_t PEM_BUFSIZE = 1024; 67 static const intptr_t PEM_BUFSIZE = 1024;
68 68
69 // SSLCertContext wraps the certificates needed for a SecureTransport
70 // connection. Fields are protected by the mutex_ field, and may only be set
71 // once. This is to allow access by both the Dart thread and the IOService
72 // thread. Setters return false if the field was already set.
73 class SSLCertContext {
74 public:
75 SSLCertContext() :
76 mutex_(new Mutex()),
77 private_key_(NULL),
78 keychain_(NULL),
79 cert_chain_(NULL),
80 trusted_certs_(NULL),
81 cert_authorities_(NULL),
82 trust_builtin_(false) {}
83
84 ~SSLCertContext() {
85 if (private_key_ != NULL) {
86 CFRelease(private_key_);
87 }
88 if (keychain_ != NULL) {
89 SecKeychainDelete(keychain_);
90 CFRelease(keychain_);
91 }
92 if (cert_chain_ != NULL) {
93 CFRelease(cert_chain_);
94 }
95 if (trusted_certs_ != NULL) {
96 CFRelease(trusted_certs_);
97 }
98 if (cert_authorities_ != NULL) {
99 CFRelease(cert_authorities_);
100 }
101 delete mutex_;
102 }
103
104 SecKeyRef private_key() {
105 MutexLocker m(mutex_);
106 return private_key_;
107 }
108 bool set_private_key(SecKeyRef private_key) {
109 MutexLocker m(mutex_);
110 if (private_key_ != NULL) {
111 return false;
112 }
113 private_key_ = private_key;
114 return true;
115 }
116
117 SecKeychainRef keychain() {
118 MutexLocker m(mutex_);
119 return keychain_;
120 }
121 bool set_keychain(SecKeychainRef keychain) {
122 MutexLocker m(mutex_);
123 if (keychain_ != NULL) {
124 return false;
125 }
126 keychain_ = keychain;
127 return true;
128 }
129
130 CFArrayRef cert_chain() {
131 MutexLocker m(mutex_);
132 return cert_chain_;
133 }
134 bool set_cert_chain(CFArrayRef cert_chain) {
135 MutexLocker m(mutex_);
136 if (cert_chain_ != NULL) {
137 return false;
138 }
139 cert_chain_ = cert_chain;
140 return true;
141 }
142
143 CFArrayRef trusted_certs() {
144 MutexLocker m(mutex_);
145 return trusted_certs_;
146 }
147 bool set_trusted_certs(CFArrayRef trusted_certs) {
148 MutexLocker m(mutex_);
149 if (trusted_certs_ != NULL) {
150 return false;
151 }
152 trusted_certs_ = trusted_certs;
153 return true;
154 }
155
156 CFArrayRef cert_authorities() {
157 MutexLocker m(mutex_);
158 return cert_authorities_;
159 }
160 bool set_cert_authorities(CFArrayRef cert_authorities) {
161 MutexLocker m(mutex_);
162 if (cert_authorities_ != NULL) {
163 return false;
164 }
165 cert_authorities_ = cert_authorities;
166 return true;
167 }
168
169 bool trust_builtin() {
170 MutexLocker m(mutex_);
171 return trust_builtin_;
172 }
173 void set_trust_builtin(bool trust_builtin) {
174 MutexLocker m(mutex_);
175 trust_builtin_ = trust_builtin;
176 }
177
178 private:
179 // The context is accessed both by Dart code and the IOService. This mutex
180 // protects all fields.
181 Mutex* mutex_;
182
183 SecKeyRef private_key_;
184 SecKeychainRef keychain_;
185
186 // CFArrays of SecCertificateRef.
187 CFArrayRef cert_chain_;
188 CFArrayRef trusted_certs_;
189 CFArrayRef cert_authorities_;
190
191 bool trust_builtin_;
192
193 DISALLOW_COPY_AND_ASSIGN(SSLCertContext);
194 };
195
196
197 static char* CFStringRefToCString(CFStringRef cfstring) { 69 static char* CFStringRefToCString(CFStringRef cfstring) {
198 CFIndex len = CFStringGetLength(cfstring); 70 CFIndex len = CFStringGetLength(cfstring);
199 CFIndex max_len = 71 CFIndex max_len =
200 CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1; 72 CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1;
201 char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(max_len)); 73 char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(max_len));
202 ASSERT(result != NULL); 74 ASSERT(result != NULL);
203 bool success = 75 bool success =
204 CFStringGetCString(cfstring, result, max_len, kCFStringEncodingUTF8); 76 CFStringGetCString(cfstring, result, max_len, kCFStringEncodingUTF8);
205 return success ? result : NULL; 77 return success ? result : NULL;
206 } 78 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 kSSLFilterNativeFieldIndex, 122 kSSLFilterNativeFieldIndex,
251 reinterpret_cast<intptr_t*>(&filter))); 123 reinterpret_cast<intptr_t*>(&filter)));
252 return filter; 124 return filter;
253 } 125 }
254 126
255 127
256 static void DeleteFilter(void* isolate_data, 128 static void DeleteFilter(void* isolate_data,
257 Dart_WeakPersistentHandle handle, 129 Dart_WeakPersistentHandle handle,
258 void* context_pointer) { 130 void* context_pointer) {
259 SSLFilter* filter = reinterpret_cast<SSLFilter*>(context_pointer); 131 SSLFilter* filter = reinterpret_cast<SSLFilter*>(context_pointer);
260 delete filter; 132 filter->Release();
261 } 133 }
262 134
263 135
264 static Dart_Handle SetFilter(Dart_NativeArguments args, SSLFilter* filter) { 136 static Dart_Handle SetFilter(Dart_NativeArguments args, SSLFilter* filter) {
265 ASSERT(filter != NULL); 137 ASSERT(filter != NULL);
266 const int approximate_size_of_filter = 1500; 138 const int approximate_size_of_filter = 1500;
267 Dart_Handle dart_this = Dart_GetNativeArgument(args, 0); 139 Dart_Handle dart_this = Dart_GetNativeArgument(args, 0);
268 RETURN_IF_ERROR(dart_this); 140 RETURN_IF_ERROR(dart_this);
269 ASSERT(Dart_IsInstance(dart_this)); 141 ASSERT(Dart_IsInstance(dart_this));
270 Dart_Handle err = Dart_SetNativeInstanceField( 142 Dart_Handle err = Dart_SetNativeInstanceField(
(...skipping 18 matching lines...) Expand all
289 kSecurityContextNativeFieldIndex, 161 kSecurityContextNativeFieldIndex,
290 reinterpret_cast<intptr_t*>(&context))); 162 reinterpret_cast<intptr_t*>(&context)));
291 return context; 163 return context;
292 } 164 }
293 165
294 166
295 static void DeleteCertContext(void* isolate_data, 167 static void DeleteCertContext(void* isolate_data,
296 Dart_WeakPersistentHandle handle, 168 Dart_WeakPersistentHandle handle,
297 void* context_pointer) { 169 void* context_pointer) {
298 SSLCertContext* context = static_cast<SSLCertContext*>(context_pointer); 170 SSLCertContext* context = static_cast<SSLCertContext*>(context_pointer);
299 delete context; 171 context->Release();
300 } 172 }
301 173
302 174
303 static Dart_Handle SetSecurityContext(Dart_NativeArguments args, 175 static Dart_Handle SetSecurityContext(Dart_NativeArguments args,
304 SSLCertContext* context) { 176 SSLCertContext* context) {
305 const int approximate_size_of_context = 1500; 177 const int approximate_size_of_context = 1500;
306 Dart_Handle dart_this = Dart_GetNativeArgument(args, 0); 178 Dart_Handle dart_this = Dart_GetNativeArgument(args, 0);
307 RETURN_IF_ERROR(dart_this); 179 RETURN_IF_ERROR(dart_this);
308 ASSERT(Dart_IsInstance(dart_this)); 180 ASSERT(Dart_IsInstance(dart_this));
309 Dart_Handle err = Dart_SetNativeInstanceField( 181 Dart_Handle err = Dart_SetNativeInstanceField(
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 542
671 CFRelease(cfdata); 543 CFRelease(cfdata);
672 CFRelease(cfpassword); 544 CFRelease(cfpassword);
673 return status; 545 return status;
674 } 546 }
675 547
676 548
677 void FUNCTION_NAME(SecureSocket_Init)(Dart_NativeArguments args) { 549 void FUNCTION_NAME(SecureSocket_Init)(Dart_NativeArguments args) {
678 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); 550 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0));
679 SSLFilter* filter = new SSLFilter(); // Deleted in DeleteFilter finalizer. 551 SSLFilter* filter = new SSLFilter(); // Deleted in DeleteFilter finalizer.
552 filter->Retain();
680 Dart_Handle err = SetFilter(args, filter); 553 Dart_Handle err = SetFilter(args, filter);
681 if (Dart_IsError(err)) { 554 if (Dart_IsError(err)) {
682 delete filter; 555 filter->Release();
683 Dart_PropagateError(err); 556 Dart_PropagateError(err);
684 } 557 }
685 err = filter->Init(dart_this); 558 err = filter->Init(dart_this);
686 if (Dart_IsError(err)) { 559 if (Dart_IsError(err)) {
687 // The finalizer was set up by SetFilter. It will delete `filter` if there 560 // The finalizer was set up by SetFilter. It will delete `filter` if there
688 // is an error. 561 // is an error.
689 filter->Destroy(); 562 filter->Destroy();
690 Dart_PropagateError(err); 563 Dart_PropagateError(err);
691 } 564 }
692 } 565 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } 657 }
785 658
786 659
787 void FUNCTION_NAME(SecureSocket_PeerCertificate) 660 void FUNCTION_NAME(SecureSocket_PeerCertificate)
788 (Dart_NativeArguments args) { 661 (Dart_NativeArguments args) {
789 Dart_SetReturnValue(args, GetFilter(args)->PeerCertificate()); 662 Dart_SetReturnValue(args, GetFilter(args)->PeerCertificate());
790 } 663 }
791 664
792 665
793 void FUNCTION_NAME(SecureSocket_FilterPointer)(Dart_NativeArguments args) { 666 void FUNCTION_NAME(SecureSocket_FilterPointer)(Dart_NativeArguments args) {
794 intptr_t filter_pointer = reinterpret_cast<intptr_t>(GetFilter(args)); 667 SSLFilter* filter = GetFilter(args);
668 // This filter pointer is passed to the IO Service thread. The IO Service
669 // thread must Release() the pointer when it is done with it.
670 filter->Retain();
671 intptr_t filter_pointer = reinterpret_cast<intptr_t>(filter);
795 Dart_SetReturnValue(args, Dart_NewInteger(filter_pointer)); 672 Dart_SetReturnValue(args, Dart_NewInteger(filter_pointer));
796 } 673 }
797 674
798 675
799 void FUNCTION_NAME(SecurityContext_Allocate)(Dart_NativeArguments args) { 676 void FUNCTION_NAME(SecurityContext_Allocate)(Dart_NativeArguments args) {
800 SSLCertContext* cert_context = new SSLCertContext(); 677 SSLCertContext* cert_context = new SSLCertContext();
678 cert_context->Retain();
801 // cert_context deleted in DeleteCertContext finalizer. 679 // cert_context deleted in DeleteCertContext finalizer.
802 Dart_Handle err = SetSecurityContext(args, cert_context); 680 Dart_Handle err = SetSecurityContext(args, cert_context);
803 if (Dart_IsError(err)) { 681 if (Dart_IsError(err)) {
804 delete cert_context; 682 cert_context->Release();
805 Dart_PropagateError(err); 683 Dart_PropagateError(err);
806 } 684 }
807 } 685 }
808 686
809 687
810 void FUNCTION_NAME(SecurityContext_UsePrivateKeyBytes)( 688 void FUNCTION_NAME(SecurityContext_UsePrivateKeyBytes)(
811 Dart_NativeArguments args) { 689 Dart_NativeArguments args) {
812 SSLCertContext* context = GetSecurityContext(args); 690 SSLCertContext* context = GetSecurityContext(args);
813 const char* password = GetPasswordArgument(args, 2); 691 const char* password = GetPasswordArgument(args, 2);
814 692
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 866
989 867
990 void FUNCTION_NAME(X509_Subject)(Dart_NativeArguments args) { 868 void FUNCTION_NAME(X509_Subject)(Dart_NativeArguments args) {
991 SecCertificateRef certificate = GetX509Certificate(args); 869 SecCertificateRef certificate = GetX509Certificate(args);
992 char* subject_name = GetNameFromCert( 870 char* subject_name = GetNameFromCert(
993 certificate, 871 certificate,
994 kSecOIDX509V1SubjectName, 872 kSecOIDX509V1SubjectName,
995 reinterpret_cast<CFStringRef>(kSecOIDCommonName)); 873 reinterpret_cast<CFStringRef>(kSecOIDCommonName));
996 if (subject_name == NULL) { 874 if (subject_name == NULL) {
997 Dart_ThrowException(DartUtils::NewDartArgumentError( 875 Dart_ThrowException(DartUtils::NewDartArgumentError(
998 "X509.subject failed to find issuer's common name.")); 876 "X509.subject failed to find subject's common name."));
999 } else { 877 } else {
1000 Dart_SetReturnValue(args, Dart_NewStringFromCString(subject_name)); 878 Dart_SetReturnValue(args, Dart_NewStringFromCString(subject_name));
1001 } 879 }
1002 } 880 }
1003 881
1004 882
1005 void FUNCTION_NAME(X509_Issuer)(Dart_NativeArguments args) { 883 void FUNCTION_NAME(X509_Issuer)(Dart_NativeArguments args) {
1006 SecCertificateRef certificate = GetX509Certificate(args); 884 SecCertificateRef certificate = GetX509Certificate(args);
1007 char* issuer_name = GetNameFromCert( 885 char* issuer_name = GetNameFromCert(
1008 certificate, 886 certificate,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 // end for output buffers. Therefore, the Dart thread can simultaneously 957 // end for output buffers. Therefore, the Dart thread can simultaneously
1080 // write to the free space and end pointer of input buffers, and read from 958 // write to the free space and end pointer of input buffers, and read from
1081 // the data space of output buffers, and modify the start pointer. 959 // the data space of output buffers, and modify the start pointer.
1082 // 960 //
1083 // When ProcessFilter returns, the Dart thread is responsible for combining 961 // When ProcessFilter returns, the Dart thread is responsible for combining
1084 // the updated pointers from Dart and C++, to make the new valid state of 962 // the updated pointers from Dart and C++, to make the new valid state of
1085 // the circular buffer. 963 // the circular buffer.
1086 CObject* SSLFilter::ProcessFilterRequest(const CObjectArray& request) { 964 CObject* SSLFilter::ProcessFilterRequest(const CObjectArray& request) {
1087 CObjectIntptr filter_object(request[0]); 965 CObjectIntptr filter_object(request[0]);
1088 SSLFilter* filter = reinterpret_cast<SSLFilter*>(filter_object.Value()); 966 SSLFilter* filter = reinterpret_cast<SSLFilter*>(filter_object.Value());
967 RefCntReleaseScope<SSLFilter> rs(filter);
968
1089 bool in_handshake = CObjectBool(request[1]).Value(); 969 bool in_handshake = CObjectBool(request[1]).Value();
1090 intptr_t starts[SSLFilter::kNumBuffers]; 970 intptr_t starts[SSLFilter::kNumBuffers];
1091 intptr_t ends[SSLFilter::kNumBuffers]; 971 intptr_t ends[SSLFilter::kNumBuffers];
1092 for (intptr_t i = 0; i < SSLFilter::kNumBuffers; ++i) { 972 for (intptr_t i = 0; i < SSLFilter::kNumBuffers; ++i) {
1093 starts[i] = CObjectInt32(request[2 * i + 2]).Value(); 973 starts[i] = CObjectInt32(request[2 * i + 2]).Value();
1094 ends[i] = CObjectInt32(request[2 * i + 3]).Value(); 974 ends[i] = CObjectInt32(request[2 * i + 3]).Value();
1095 } 975 }
1096 976
1097 OSStatus status = filter->ProcessAllBuffers(starts, ends, in_handshake); 977 OSStatus status = filter->ProcessAllBuffers(starts, ends, in_handshake);
1098 if (status == noErr) { 978 if (status == noErr) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 if (auth != kNeverAuthenticate) { 1387 if (auth != kNeverAuthenticate) {
1508 status = SSLSetSessionOption( 1388 status = SSLSetSessionOption(
1509 ssl_context, kSSLSessionOptionBreakOnClientAuth, true); 1389 ssl_context, kSSLSessionOptionBreakOnClientAuth, true);
1510 CheckStatus(status, 1390 CheckStatus(status,
1511 "TlsException", 1391 "TlsException",
1512 "Failed to set client authentication mode"); 1392 "Failed to set client authentication mode");
1513 } 1393 }
1514 } 1394 }
1515 1395
1516 // Add the contexts to our wrapper. 1396 // Add the contexts to our wrapper.
1517 cert_context_ = context; 1397 cert_context_.set(context);
1518 ssl_context_ = ssl_context; 1398 ssl_context_ = ssl_context;
1519 is_server_ = is_server; 1399 is_server_ = is_server;
1520 1400
1521 // Kick-off the handshake. Expect the handshake to need more data. 1401 // Kick-off the handshake. Expect the handshake to need more data.
1522 // SSLHandshake calls our SSLReadCallback and SSLWriteCallback. 1402 // SSLHandshake calls our SSLReadCallback and SSLWriteCallback.
1523 status = SSLHandshake(ssl_context); 1403 status = SSLHandshake(ssl_context);
1524 ASSERT(status != noErr); 1404 ASSERT(status != noErr);
1525 if (status == errSSLWouldBlock) { 1405 if (status == errSSLWouldBlock) {
1526 status = noErr; 1406 status = noErr;
1527 in_handshake_ = true; 1407 in_handshake_ = true;
(...skipping 18 matching lines...) Expand all
1546 return noErr; 1426 return noErr;
1547 } 1427 }
1548 if (SSL_LOG_STATUS) { 1428 if (SSL_LOG_STATUS) {
1549 Log::Print("Handshake error from SSLCopyPeerTrust(): %ld.\n", 1429 Log::Print("Handshake error from SSLCopyPeerTrust(): %ld.\n",
1550 static_cast<intptr_t>(status)); 1430 static_cast<intptr_t>(status));
1551 } 1431 }
1552 return status; 1432 return status;
1553 } 1433 }
1554 1434
1555 CFArrayRef trusted_certs = NULL; 1435 CFArrayRef trusted_certs = NULL;
1556 if (cert_context_->trusted_certs() != NULL) { 1436 if (cert_context_.get()->trusted_certs() != NULL) {
1557 trusted_certs = CFArrayCreateCopy(NULL, cert_context_->trusted_certs()); 1437 trusted_certs =
1438 CFArrayCreateCopy(NULL, cert_context_.get()->trusted_certs());
1558 } else { 1439 } else {
1559 trusted_certs = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks); 1440 trusted_certs = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks);
1560 } 1441 }
1561 1442
1562 status = SecTrustSetAnchorCertificates(peer_trust, trusted_certs); 1443 status = SecTrustSetAnchorCertificates(peer_trust, trusted_certs);
1563 if (status != noErr) { 1444 if (status != noErr) {
1564 if (SSL_LOG_STATUS) { 1445 if (SSL_LOG_STATUS) {
1565 Log::Print("Handshake error from SecTrustSetAnchorCertificates: %ld\n", 1446 Log::Print("Handshake error from SecTrustSetAnchorCertificates: %ld\n",
1566 static_cast<intptr_t>(status)); 1447 static_cast<intptr_t>(status));
1567 } 1448 }
1568 CFRelease(trusted_certs); 1449 CFRelease(trusted_certs);
1569 CFRelease(peer_trust); 1450 CFRelease(peer_trust);
1570 return status; 1451 return status;
1571 } 1452 }
1572 1453
1573 if (SSL_LOG_STATUS) { 1454 if (SSL_LOG_STATUS) {
1574 Log::Print("Handshake %s built in root certs\n", 1455 Log::Print("Handshake %s built in root certs\n",
1575 cert_context_->trust_builtin() ? "trusting" : "not trusting"); 1456 cert_context_.get()->trust_builtin() ? "trusting" : "not trusting");
1576 } 1457 }
1577 1458
1578 status = SecTrustSetAnchorCertificatesOnly( 1459 status = SecTrustSetAnchorCertificatesOnly(
1579 peer_trust, !cert_context_->trust_builtin()); 1460 peer_trust, !cert_context_.get()->trust_builtin());
1580 if (status != noErr) { 1461 if (status != noErr) {
1581 CFRelease(trusted_certs); 1462 CFRelease(trusted_certs);
1582 CFRelease(peer_trust); 1463 CFRelease(peer_trust);
1583 return status; 1464 return status;
1584 } 1465 }
1585 1466
1586 SecTrustResultType trust_result; 1467 SecTrustResultType trust_result;
1587 status = SecTrustEvaluate(peer_trust, &trust_result); 1468 status = SecTrustEvaluate(peer_trust, &trust_result);
1588 if (status != noErr) { 1469 if (status != noErr) {
1589 CFRelease(trusted_certs); 1470 CFRelease(trusted_certs);
(...skipping 22 matching lines...) Expand all
1612 if (SSL_LOG_STATUS) { 1493 if (SSL_LOG_STATUS) {
1613 Log::Print("Trust eval failed: trust_restul = %d\n", trust_result); 1494 Log::Print("Trust eval failed: trust_restul = %d\n", trust_result);
1614 } 1495 }
1615 bad_cert_ = true; 1496 bad_cert_ = true;
1616 return errSSLBadCert; 1497 return errSSLBadCert;
1617 } 1498 }
1618 } 1499 }
1619 1500
1620 1501
1621 OSStatus SSLFilter::Handshake() { 1502 OSStatus SSLFilter::Handshake() {
1622 ASSERT(cert_context_ != NULL); 1503 ASSERT(cert_context_.get() != NULL);
1623 ASSERT(ssl_context_ != NULL); 1504 ASSERT(ssl_context_ != NULL);
1624 // Try and push handshake along. 1505 // Try and push handshake along.
1625 if (SSL_LOG_STATUS) { 1506 if (SSL_LOG_STATUS) {
1626 Log::Print("Doing SSLHandshake\n"); 1507 Log::Print("Doing SSLHandshake\n");
1627 } 1508 }
1628 OSStatus status = SSLHandshake(ssl_context_); 1509 OSStatus status = SSLHandshake(ssl_context_);
1629 if (SSL_LOG_STATUS) { 1510 if (SSL_LOG_STATUS) {
1630 Log::Print("SSLHandshake returned %ld\n", static_cast<intptr_t>(status)); 1511 Log::Print("SSLHandshake returned %ld\n", static_cast<intptr_t>(status));
1631 } 1512 }
1632 1513
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 // The SSL_REQUIRE_CERTIFICATE option only takes effect if the 1606 // The SSL_REQUIRE_CERTIFICATE option only takes effect if the
1726 // SSL_REQUEST_CERTIFICATE option is also set, so set it. 1607 // SSL_REQUEST_CERTIFICATE option is also set, so set it.
1727 request_client_certificate = 1608 request_client_certificate =
1728 request_client_certificate || require_client_certificate; 1609 request_client_certificate || require_client_certificate;
1729 // TODO(24070, 24069): Implement setting the client certificate parameters, 1610 // TODO(24070, 24069): Implement setting the client certificate parameters,
1730 // and triggering rehandshake. 1611 // and triggering rehandshake.
1731 } 1612 }
1732 1613
1733 1614
1734 SSLFilter::~SSLFilter() { 1615 SSLFilter::~SSLFilter() {
1735 // cert_context_ deleted by finalizer. Don't delete here.
1736 cert_context_ = NULL;
1737 if (ssl_context_ != NULL) { 1616 if (ssl_context_ != NULL) {
1738 CFRelease(ssl_context_); 1617 CFRelease(ssl_context_);
1739 ssl_context_ = NULL; 1618 ssl_context_ = NULL;
1740 } 1619 }
1741 if (peer_certs_ != NULL) { 1620 if (peer_certs_ != NULL) {
1742 CFRelease(peer_certs_); 1621 CFRelease(peer_certs_);
1743 peer_certs_ = NULL; 1622 peer_certs_ = NULL;
1744 } 1623 }
1745 if (hostname_ != NULL) { 1624 if (hostname_ != NULL) {
1746 free(hostname_); 1625 free(hostname_);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 return status; 1839 return status;
1961 } 1840 }
1962 1841
1963 } // namespace bin 1842 } // namespace bin
1964 } // namespace dart 1843 } // namespace dart
1965 1844
1966 #endif // defined(TARGET_OS_MACOS) && !TARGET_OS_IOS 1845 #endif // defined(TARGET_OS_MACOS) && !TARGET_OS_IOS
1967 1846
1968 #endif // !defined(DART_IO_DISABLED) && 1847 #endif // !defined(DART_IO_DISABLED) &&
1969 // !defined(DART_IO_SECURE_SOCKET_DISABLED) 1848 // !defined(DART_IO_SECURE_SOCKET_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698