| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 ..usePrivateKey(localFile('certificates/client1_key.pem'), | 25 ..usePrivateKey(localFile('certificates/client1_key.pem'), |
| 26 password: 'dartdart'); | 26 password: 'dartdart'); |
| 27 | 27 |
| 28 SecurityContext clientNoCertContext = new SecurityContext() | 28 SecurityContext clientNoCertContext = new SecurityContext() |
| 29 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); | 29 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); |
| 30 | 30 |
| 31 Future testClientCertificate({bool required, bool sendCert}) async { | 31 Future testClientCertificate({bool required, bool sendCert}) async { |
| 32 var server = await SecureServerSocket.bind(HOST, 0, serverContext, | 32 var server = await SecureServerSocket.bind(HOST, 0, serverContext, |
| 33 requestClientCertificate: true, requireClientCertificate: required); | 33 requestClientCertificate: true, requireClientCertificate: required); |
| 34 var clientContext = sendCert ? clientCertContext : clientNoCertContext; | 34 var clientContext = sendCert ? clientCertContext : clientNoCertContext; |
| 35 var clientEndFuture = SecureSocket.connect(HOST, server.port, | 35 var clientEndFuture = |
| 36 context: clientContext, sendClientCertificate: true); | 36 SecureSocket.connect(HOST, server.port, context: clientContext); |
| 37 if (required && !sendCert) { | 37 if (required && !sendCert) { |
| 38 try { | 38 try { |
| 39 await server.first; | 39 await server.first; |
| 40 } catch (e) { | 40 } catch (e) { |
| 41 try { | 41 try { |
| 42 await clientEndFuture; | 42 await clientEndFuture; |
| 43 } catch (e) { | 43 } catch (e) { |
| 44 return; | 44 return; |
| 45 } | 45 } |
| 46 } | 46 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 | 67 |
| 68 main() async { | 68 main() async { |
| 69 asyncStart(); | 69 asyncStart(); |
| 70 HOST = (await InternetAddress.lookup("localhost")).first; | 70 HOST = (await InternetAddress.lookup("localhost")).first; |
| 71 await testClientCertificate(required: false, sendCert: true); | 71 await testClientCertificate(required: false, sendCert: true); |
| 72 await testClientCertificate(required: true, sendCert: true); | 72 await testClientCertificate(required: true, sendCert: true); |
| 73 await testClientCertificate(required: false, sendCert: false); | 73 await testClientCertificate(required: false, sendCert: false); |
| 74 await testClientCertificate(required: true, sendCert: false); | 74 await testClientCertificate(required: true, sendCert: false); |
| 75 asyncEnd(); | 75 asyncEnd(); |
| 76 } | 76 } |
| OLD | NEW |