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