| 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 |
| 11 InternetAddress HOST; | 11 InternetAddress HOST; |
| 12 | 12 |
| 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 14 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | 14 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); |
| 15 | 15 |
| 16 SecurityContext serverContext = new SecurityContext() | 16 SecurityContext serverContext = new SecurityContext() |
| 17 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) | 17 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) |
| 18 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), | 18 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), |
| 19 password: 'dartdart') | 19 password: 'dartdart') |
| 20 ..setTrustedCertificates(file: localFile('certificates/client_authority.pem')) | 20 ..setTrustedCertificatesBytes( |
| 21 readLocalFile('certificates/client_authority.pem')) |
| 21 ..setClientAuthorities(localFile('certificates/client_authority.pem')); | 22 ..setClientAuthorities(localFile('certificates/client_authority.pem')); |
| 22 | 23 |
| 23 SecurityContext clientCertContext = new SecurityContext() | 24 SecurityContext clientCertContext = new SecurityContext() |
| 24 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')) | 25 ..setTrustedCertificatesBytes( |
| 26 readLocalFile('certificates/trusted_certs.pem')) |
| 25 ..useCertificateChainBytes(readLocalFile('certificates/client1.pem')) | 27 ..useCertificateChainBytes(readLocalFile('certificates/client1.pem')) |
| 26 ..usePrivateKeyBytes(readLocalFile('certificates/client1_key.pem'), | 28 ..usePrivateKeyBytes(readLocalFile('certificates/client1_key.pem'), |
| 27 password: 'dartdart'); | 29 password: 'dartdart'); |
| 28 | 30 |
| 29 SecurityContext clientNoCertContext = new SecurityContext() | 31 SecurityContext clientNoCertContext = new SecurityContext() |
| 30 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); | 32 ..setTrustedCertificatesBytes( |
| 33 readLocalFile('certificates/trusted_certs.pem')); |
| 31 | 34 |
| 32 Future testClientCertificate({bool required, bool sendCert}) async { | 35 Future testClientCertificate({bool required, bool sendCert}) async { |
| 33 var server = await SecureServerSocket.bind(HOST, 0, serverContext, | 36 var server = await SecureServerSocket.bind(HOST, 0, serverContext, |
| 34 requestClientCertificate: true, requireClientCertificate: required); | 37 requestClientCertificate: true, requireClientCertificate: required); |
| 35 var clientContext = sendCert ? clientCertContext : clientNoCertContext; | 38 var clientContext = sendCert ? clientCertContext : clientNoCertContext; |
| 36 var clientEndFuture = | 39 var clientEndFuture = |
| 37 SecureSocket.connect(HOST, server.port, context: clientContext); | 40 SecureSocket.connect(HOST, server.port, context: clientContext); |
| 38 if (required && !sendCert) { | 41 if (required && !sendCert) { |
| 39 try { | 42 try { |
| 40 await server.first; | 43 await server.first; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 68 | 71 |
| 69 main() async { | 72 main() async { |
| 70 asyncStart(); | 73 asyncStart(); |
| 71 HOST = (await InternetAddress.lookup("localhost")).first; | 74 HOST = (await InternetAddress.lookup("localhost")).first; |
| 72 await testClientCertificate(required: false, sendCert: true); | 75 await testClientCertificate(required: false, sendCert: true); |
| 73 await testClientCertificate(required: true, sendCert: true); | 76 await testClientCertificate(required: true, sendCert: true); |
| 74 await testClientCertificate(required: false, sendCert: false); | 77 await testClientCertificate(required: false, sendCert: false); |
| 75 await testClientCertificate(required: true, sendCert: false); | 78 await testClientCertificate(required: true, sendCert: false); |
| 76 asyncEnd(); | 79 asyncEnd(); |
| 77 } | 80 } |
| OLD | NEW |